summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/labstack/echo/cookbook/google-app-engine
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/labstack/echo/cookbook/google-app-engine')
-rw-r--r--vendor/github.com/labstack/echo/cookbook/google-app-engine/app-engine.go17
-rw-r--r--vendor/github.com/labstack/echo/cookbook/google-app-engine/app-managed.go25
-rw-r--r--vendor/github.com/labstack/echo/cookbook/google-app-engine/app-standalone.go24
-rw-r--r--vendor/github.com/labstack/echo/cookbook/google-app-engine/app.go4
-rw-r--r--vendor/github.com/labstack/echo/cookbook/google-app-engine/users.go54
-rw-r--r--vendor/github.com/labstack/echo/cookbook/google-app-engine/welcome.go31
6 files changed, 155 insertions, 0 deletions
diff --git a/vendor/github.com/labstack/echo/cookbook/google-app-engine/app-engine.go b/vendor/github.com/labstack/echo/cookbook/google-app-engine/app-engine.go
new file mode 100644
index 00000000..0c1db087
--- /dev/null
+++ b/vendor/github.com/labstack/echo/cookbook/google-app-engine/app-engine.go
@@ -0,0 +1,17 @@
+// +build appengine
+
+package main
+
+import (
+ "net/http"
+
+ "github.com/labstack/echo"
+)
+
+func createMux() *echo.Echo {
+ e := echo.New()
+ // note: we don't need to provide the middleware or static handlers, that's taken care of by the platform
+ // app engine has it's own "main" wrapper - we just need to hook echo into the default handler
+ http.Handle("/", e)
+ return e
+}
diff --git a/vendor/github.com/labstack/echo/cookbook/google-app-engine/app-managed.go b/vendor/github.com/labstack/echo/cookbook/google-app-engine/app-managed.go
new file mode 100644
index 00000000..7b8eacf8
--- /dev/null
+++ b/vendor/github.com/labstack/echo/cookbook/google-app-engine/app-managed.go
@@ -0,0 +1,25 @@
+// +build appenginevm
+
+package main
+
+import (
+ "net/http"
+
+ "github.com/labstack/echo"
+ "google.golang.org/appengine"
+)
+
+func createMux() *echo.Echo {
+ e := echo.New()
+ // note: we don't need to provide the middleware or static handlers
+ // for the appengine vm version - that's taken care of by the platform
+ return e
+}
+
+func main() {
+ // the appengine package provides a convenient method to handle the health-check requests
+ // and also run the app on the correct port. We just need to add Echo to the default handler
+ e := echo.New(":8080")
+ http.Handle("/", e)
+ appengine.Main()
+}
diff --git a/vendor/github.com/labstack/echo/cookbook/google-app-engine/app-standalone.go b/vendor/github.com/labstack/echo/cookbook/google-app-engine/app-standalone.go
new file mode 100644
index 00000000..c3b44dc0
--- /dev/null
+++ b/vendor/github.com/labstack/echo/cookbook/google-app-engine/app-standalone.go
@@ -0,0 +1,24 @@
+// +build !appengine,!appenginevm
+
+package main
+
+import (
+ "github.com/labstack/echo"
+ "github.com/labstack/echo/middleware"
+)
+
+func createMux() *echo.Echo {
+ e := echo.New()
+
+ e.Use(middleware.Recover())
+ e.Use(middleware.Logger())
+ e.Use(middleware.Gzip())
+
+ e.Static("/", "public")
+
+ return e
+}
+
+func main() {
+ e.Logger.Fatal(e.Start(":8080"))
+}
diff --git a/vendor/github.com/labstack/echo/cookbook/google-app-engine/app.go b/vendor/github.com/labstack/echo/cookbook/google-app-engine/app.go
new file mode 100644
index 00000000..8d4d97a2
--- /dev/null
+++ b/vendor/github.com/labstack/echo/cookbook/google-app-engine/app.go
@@ -0,0 +1,4 @@
+package main
+
+// reference our echo instance and create it early
+var e = createMux()
diff --git a/vendor/github.com/labstack/echo/cookbook/google-app-engine/users.go b/vendor/github.com/labstack/echo/cookbook/google-app-engine/users.go
new file mode 100644
index 00000000..19533e51
--- /dev/null
+++ b/vendor/github.com/labstack/echo/cookbook/google-app-engine/users.go
@@ -0,0 +1,54 @@
+package main
+
+import (
+ "net/http"
+
+ "github.com/labstack/echo"
+ "github.com/labstack/echo/middleware"
+)
+
+type (
+ user struct {
+ ID string `json:"id"`
+ Name string `json:"name"`
+ }
+)
+
+var (
+ users map[string]user
+)
+
+func init() {
+ users = map[string]user{
+ "1": user{
+ ID: "1",
+ Name: "Wreck-It Ralph",
+ },
+ }
+
+ // hook into the echo instance to create an endpoint group
+ // and add specific middleware to it plus handlers
+ g := e.Group("/users")
+ g.Use(middleware.CORS())
+
+ g.POST("", createUser)
+ g.GET("", getUsers)
+ g.GET("/:id", getUser)
+}
+
+func createUser(c echo.Context) error {
+ u := new(user)
+ if err := c.Bind(u); err != nil {
+ return err
+ }
+ users[u.ID] = *u
+ return c.JSON(http.StatusCreated, u)
+}
+
+func getUsers(c echo.Context) error {
+ return c.JSON(http.StatusOK, users)
+}
+
+func getUser(c echo.Context) error {
+ return c.JSON(http.StatusOK, users[c.Param("id")])
+}
diff --git a/vendor/github.com/labstack/echo/cookbook/google-app-engine/welcome.go b/vendor/github.com/labstack/echo/cookbook/google-app-engine/welcome.go
new file mode 100644
index 00000000..2639b209
--- /dev/null
+++ b/vendor/github.com/labstack/echo/cookbook/google-app-engine/welcome.go
@@ -0,0 +1,31 @@
+package main
+
+import (
+ "html/template"
+ "io"
+ "net/http"
+
+ "github.com/labstack/echo"
+)
+
+type (
+ Template struct {
+ templates *template.Template
+ }
+)
+
+func init() {
+ t := &Template{
+ templates: template.Must(template.ParseFiles("templates/welcome.html")),
+ }
+ e.Renderer = t
+ e.GET("/welcome", welcome)
+}
+
+func (t *Template) Render(w io.Writer, name string, data interface{}, c echo.Context) error {
+ return t.templates.ExecuteTemplate(w, name, data)
+}
+
+func welcome(c echo.Context) error {
+ return c.Render(http.StatusOK, "welcome", "Joe")
+}