From 6b5e80901f70082f87e5a581ccfa4f319cf735dc Mon Sep 17 00:00:00 2001 From: Javier Provecho Fernandez Date: Wed, 2 Jul 2014 22:08:37 +0200 Subject: [PATCH 1/4] Added Google App Engine Example --- examples/app-engine/app.yaml | 8 ++++++++ examples/app-engine/hello.go | 22 ++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 examples/app-engine/app.yaml create mode 100644 examples/app-engine/hello.go diff --git a/examples/app-engine/app.yaml b/examples/app-engine/app.yaml new file mode 100644 index 00000000..5f20cf3f --- /dev/null +++ b/examples/app-engine/app.yaml @@ -0,0 +1,8 @@ +application: hello +version: 1 +runtime: go +api_version: go1 + +handlers: +- url: /.* + script: _go_app \ No newline at end of file diff --git a/examples/app-engine/hello.go b/examples/app-engine/hello.go new file mode 100644 index 00000000..a6de8378 --- /dev/null +++ b/examples/app-engine/hello.go @@ -0,0 +1,22 @@ +package hello + +import ( + "net/http" + "github.com/gin-gonic/gin" +) + +func init() { + // Starts a new Gin instance with no middle-ware + r := gin.New() + + // Define your handlers + r.GET("/", func(c *gin.Context){ + c.String(200, "Hello World!") + }) + r.GET("/ping/", func(c *gin.Context){ + c.String(200, "pong") + }) + + // Handle all requests using net/http + http.Handle("/", r) +} \ No newline at end of file From f380265f5d3bd2f6693098f65a093aea21ca3f5f Mon Sep 17 00:00:00 2001 From: Javier Provecho Fernandez Date: Wed, 2 Jul 2014 22:38:02 +0200 Subject: [PATCH 2/4] Added README.md --- examples/app-engine/README.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 examples/app-engine/README.md diff --git a/examples/app-engine/README.md b/examples/app-engine/README.md new file mode 100644 index 00000000..99200668 --- /dev/null +++ b/examples/app-engine/README.md @@ -0,0 +1,7 @@ +# Guide to run Gin under App Engine Development Server + +1. Download, install and setup Go in your computer. (That includes setting your $GOPATH.) +2. Download SDK for your platform from here: https://developers.google.com/appengine/downloads?hl=es#Google_App_Engine_SDK_for_Go +3. Download Gin source code using: $ go get github.com/gin-gonic/gin +4. Navigate to examples folder: $ cd $GOPATH/src/github.com/gin-gonic/gin/examples/ +5. Run it: $ goapp serve app-engine/ \ No newline at end of file From ca91a4a6dad2025b2711cc45ac2bdfad9e810dcd Mon Sep 17 00:00:00 2001 From: Javier Provecho Fernandez Date: Wed, 2 Jul 2014 22:39:42 +0200 Subject: [PATCH 3/4] Fix Modified ping path and added a comment explaining why init() is called like that. --- examples/app-engine/hello.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/app-engine/hello.go b/examples/app-engine/hello.go index a6de8378..f5daf824 100644 --- a/examples/app-engine/hello.go +++ b/examples/app-engine/hello.go @@ -5,6 +5,7 @@ import ( "github.com/gin-gonic/gin" ) +// This function's name is a must. App Engine uses it to drive the requests properly. func init() { // Starts a new Gin instance with no middle-ware r := gin.New() @@ -13,7 +14,7 @@ func init() { r.GET("/", func(c *gin.Context){ c.String(200, "Hello World!") }) - r.GET("/ping/", func(c *gin.Context){ + r.GET("/ping", func(c *gin.Context){ c.String(200, "pong") }) From 05d587d65ecb3bd0a655b5b9aaaadf01f3d05e88 Mon Sep 17 00:00:00 2001 From: Javier Provecho Fernandez Date: Wed, 2 Jul 2014 22:48:06 +0200 Subject: [PATCH 4/4] Clarification --- examples/app-engine/README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/app-engine/README.md b/examples/app-engine/README.md index 99200668..48505de8 100644 --- a/examples/app-engine/README.md +++ b/examples/app-engine/README.md @@ -1,7 +1,7 @@ -# Guide to run Gin under App Engine Development Server +# Guide to run Gin under App Engine LOCAL Development Server -1. Download, install and setup Go in your computer. (That includes setting your $GOPATH.) -2. Download SDK for your platform from here: https://developers.google.com/appengine/downloads?hl=es#Google_App_Engine_SDK_for_Go -3. Download Gin source code using: $ go get github.com/gin-gonic/gin -4. Navigate to examples folder: $ cd $GOPATH/src/github.com/gin-gonic/gin/examples/ -5. Run it: $ goapp serve app-engine/ \ No newline at end of file +1. Download, install and setup Go in your computer. (That includes setting your `$GOPATH`.) +2. Download SDK for your platform from here: `https://developers.google.com/appengine/downloads?hl=es#Google_App_Engine_SDK_for_Go` +3. Download Gin source code using: `$ go get github.com/gin-gonic/gin` +4. Navigate to examples folder: `$ cd $GOPATH/src/github.com/gin-gonic/gin/examples/` +5. Run it: `$ goapp serve app-engine/` \ No newline at end of file