1
0
mirror of https://github.com/labstack/echo.git synced 2024-11-24 08:22:21 +02:00

fixed build for recipes

Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana 2016-10-20 11:51:15 -07:00
parent b6547dde66
commit edd558a5ca
19 changed files with 43 additions and 30 deletions

View File

@ -30,7 +30,7 @@ Example:
e.GET("/", hello)
// Start server
panic(e.Start(":1323"))
e.Logger.Fatal(e.Start(":1323"))
}
Learn more at https://echo.labstack.com

12
glide.lock generated
View File

@ -1,12 +1,20 @@
hash: c976a13eaa717493a6b9e0e2750dc55e510371cf532a69aa9a14ad945d21b96e
updated: 2016-10-20T11:28:32.867490559-07:00
hash: 68fa89887f232f6f139552d50300f5fe9f958da390045b9b99d4f7d0201f42f7
updated: 2016-10-20T11:50:22.171643207-07:00
imports:
- name: github.com/daaku/go.zipexe
version: a5fe2436ffcb3236e175e5149162b41cd28bd27d
- name: github.com/dgrijalva/jwt-go
version: 24c63f56522a87ec5339cc3567883f1039378fdb
- name: github.com/GeertJohan/go.rice
version: 9fdfd46f9806a9228aae341d65ab75c5235c383c
subpackages:
- embedded
- name: github.com/golang/protobuf
version: 98fa357170587e470c5f27d3c3ea0947b71eb455
subpackages:
- proto
- name: github.com/kardianos/osext
version: c2c54e542fb797ad986b31721e1baedf214ca413
- name: github.com/labstack/gommon
version: f3b1a1b3bd4726161e1200863d278df7da5e66ff
subpackages:

View File

@ -1,5 +1,6 @@
package: github.com/labstack/echo
import:
- package: github.com/GeertJohan/go.rice
- package: github.com/dgrijalva/jwt-go
- package: github.com/labstack/gommon
subpackages:

View File

@ -33,5 +33,5 @@ func main() {
}))
e.GET("/api/users", getUsers)
panic(e.Start(":1323"))
e.Logger.Fatal(e.Start(":1323"))
}

View File

@ -71,5 +71,5 @@ func main() {
e.DELETE("/users/:id", deleteUser)
// Start server
panic(e.Start(":1323"))
e.Logger.Fatal(e.Start(":1323"))
}

View File

@ -3,6 +3,7 @@ package main
import (
"net/http"
rice "github.com/GeertJohan/go.rice"
"github.com/labstack/echo"
)
@ -11,9 +12,10 @@ func main() {
// the file server for rice. "app" is the folder where the files come from.
assetHandler := http.FileServer(rice.MustFindBox("app").HTTPBox())
// serves the index.html from rice
e.GET("/", standard.WrapHandler(assetHandler))
e.GET("/", echo.WrapHandler(assetHandler))
// servers other static files
e.GET("/static/*", standard.WrapHandler(http.StripPrefix("/static/", assetHandler)))
panic(e.Start(":3000"))
e.GET("/static/*", echo.WrapHandler(http.StripPrefix("/static/", assetHandler)))
e.Logger.Fatal(e.Start(":3000"))
}

View File

@ -61,5 +61,5 @@ func main() {
e.POST("/upload", upload)
panic(e.Start(":1323"))
e.Logger.Fatal(e.Start(":1323"))
}

View File

@ -55,5 +55,5 @@ func main() {
e.POST("/upload", upload)
panic(e.Start(":1323"))
e.Logger.Fatal(e.Start(":1323"))
}

View File

@ -20,5 +20,5 @@ func createMux() *echo.Echo {
}
func main() {
panic(e.Start(":8080"))
e.Logger.Fatal(e.Start(":8080"))
}

View File

@ -50,5 +50,5 @@ func getUsers(c echo.Context) error {
}
func getUser(c echo.Context) error {
return c.JSON(http.StatusOK, users[c.P(0)])
return c.JSON(http.StatusOK, users[c.Param("id")])
}

View File

@ -18,7 +18,7 @@ func init() {
t := &Template{
templates: template.Must(template.ParseFiles("templates/welcome.html")),
}
e.SetRenderer(t)
e.Renderer = t
e.GET("/welcome", welcome)
}

View File

@ -21,5 +21,5 @@ func main() {
})
// Start server
panic(e.Start(":1323"))
e.Logger.Fatal(e.Start(":1323"))
}

View File

@ -9,14 +9,14 @@ import (
)
func request(c echo.Context) error {
req := c.Request().(*standard.Request).Request
req := c.Request()
format := "<pre><strong>Request Information</strong>\n\n<code>Protocol: %s\nHost: %s\nRemote Address: %s\nMethod: %s\nPath: %s\n</code></pre>"
return c.HTML(http.StatusOK, fmt.Sprintf(format, req.Proto, req.Host, req.RemoteAddr, req.Method, req.URL.Path))
}
func stream(c echo.Context) error {
res := c.Response().(*standard.Response).ResponseWriter
gone := res.(http.CloseNotifier).CloseNotify()
res := c.Response()
gone := res.CloseNotify()
res.Header().Set(echo.HeaderContentType, echo.MIMETextHTMLCharsetUTF8)
res.WriteHeader(http.StatusOK)
ticker := time.NewTicker(1 * time.Second)
@ -25,7 +25,7 @@ func stream(c echo.Context) error {
fmt.Fprint(res, "<pre><strong>Clock Stream</strong>\n\n<code>")
for {
fmt.Fprintf(res, "%v\n", time.Now())
res.(http.Flusher).Flush()
res.Flush()
select {
case <-ticker.C:
case <-gone:
@ -38,5 +38,5 @@ func main() {
e := echo.New()
e.GET("/request", request)
e.GET("/stream", stream)
panic(e.StartTLS(":1323", "cert.pem", "key.pem"))
e.Logger.Fatal(e.StartTLS(":1323", "cert.pem", "key.pem"))
}

View File

@ -30,5 +30,5 @@ func main() {
})
// Start server
panic(e.Start(":1323"))
e.Logger.Fatal(e.Start(":1323"))
}

View File

@ -4,6 +4,7 @@ import (
"net/http"
"time"
jwt "github.com/dgrijalva/jwt-go"
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
)
@ -81,5 +82,5 @@ func main() {
r.Use(middleware.JWTWithConfig(config))
r.GET("", restricted)
panic(e.Start(":1323"))
e.Logger.Fatal(e.Start(":1323"))
}

View File

@ -4,6 +4,7 @@ import (
"net/http"
"time"
jwt "github.com/dgrijalva/jwt-go"
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
)
@ -64,5 +65,5 @@ func main() {
r.Use(middleware.JWT([]byte("secret")))
r.GET("", restricted)
panic(e.Start(":1323"))
e.Logger.Fatal(e.Start(":1323"))
}

View File

@ -34,7 +34,7 @@ func (s *Stats) Process(next echo.HandlerFunc) echo.HandlerFunc {
s.mutex.Lock()
defer s.mutex.Unlock()
s.RequestCount++
status := strconv.Itoa(c.Response().Status())
status := strconv.Itoa(c.Response().Status)
s.Statuses[status]++
return nil
}
@ -59,7 +59,7 @@ func main() {
e := echo.New()
// Debug mode
e.SetDebug(true)
e.Debug = true
//-------------------
// Custom middleware
@ -78,5 +78,5 @@ func main() {
})
// Start server
panic(e.Start(":1323"))
e.Logger.Fatal(e.Start(":1323"))
}

View File

@ -36,10 +36,10 @@ func main() {
if err := json.NewEncoder(c.Response()).Encode(l); err != nil {
return err
}
c.Response().(http.Flusher).Flush()
c.Response().Flush()
time.Sleep(1 * time.Second)
}
return nil
})
panic(e.Start(":1323"))
e.Logger.Fatal((e.Start(":1323")))
}

View File

@ -64,15 +64,15 @@ func main() {
e.Any("/*", func(c echo.Context) (err error) {
req := c.Request()
res := c.Response()
host := hosts[req.Host()]
host := hosts[req.Host]
if host == nil {
err = echo.ErrNotFound
} else {
host.Echo.ServeHTTP(req, res)
host.Echo.ServeHTTP(res, req)
}
return
})
panic(e.Start(":1323"))
e.Logger.Fatal(e.Start(":1323"))
}