diff --git a/go-app/.gcloudignore b/go-app/.gcloudignore new file mode 100644 index 00000000..199e6d9f --- /dev/null +++ b/go-app/.gcloudignore @@ -0,0 +1,25 @@ +# This file specifies files that are *not* uploaded to Google Cloud Platform +# using gcloud. It follows the same syntax as .gitignore, with the addition of +# "#!include" directives (which insert the entries of the given .gitignore-style +# file at that point). +# +# For more information, run: +# $ gcloud topic gcloudignore +# +.gcloudignore +# If you would like to upload your .git directory, .gitignore file or files +# from your .gitignore file, remove the corresponding line +# below: +.git +.gitignore + +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib +# Test binary, build with `go test -c` +*.test +# Output of the go coverage tool, specifically when used with LiteIDE +*.out \ No newline at end of file diff --git a/go-app/.gitignore b/go-app/.gitignore new file mode 100644 index 00000000..8a3cddc0 --- /dev/null +++ b/go-app/.gitignore @@ -0,0 +1,23 @@ + +# Created by https://www.gitignore.io/api/go +# Edit at https://www.gitignore.io/?templates=go + +### Go ### +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +### Go Patch ### +vendor/*/ +/Godeps/ + +# End of https://www.gitignore.io/api/go diff --git a/go-app/app.yaml b/go-app/app.yaml new file mode 100644 index 00000000..7a545c9f --- /dev/null +++ b/go-app/app.yaml @@ -0,0 +1 @@ +runtime: go111 \ No newline at end of file diff --git a/go-app/main.go b/go-app/main.go new file mode 100644 index 00000000..8ee07fa4 --- /dev/null +++ b/go-app/main.go @@ -0,0 +1,20 @@ +package main + +import ( + routes "CodeLanka/TrainPal-Mobile-App/go-app/routes" + "github.com/gin-gonic/gin" +) + +func setupRouter() *gin.Engine { + + r := gin.Default() + routes.BindRoutes(r) + return r +} + +func main() { + r := setupRouter() + + // Listen and Server in 0.0.0.0:8080 + r.Run(":8080") +} diff --git a/go-app/routes/routes.go b/go-app/routes/routes.go new file mode 100644 index 00000000..3c2ee277 --- /dev/null +++ b/go-app/routes/routes.go @@ -0,0 +1,48 @@ +package routes + +import ( + "github.com/gin-gonic/gin" + "net/http" +) + +var db = make(map[string]string) + +func BindRoutes(r *gin.Engine) gin.IRoutes { + // Ping test + r.GET("/ping", func(c *gin.Context) { + c.String(http.StatusOK, "pong") + }) + + // Get user value + r.GET("/user/:name", func(c *gin.Context) { + user := c.Params.ByName("name") + value, ok := db[user] + if ok { + c.JSON(http.StatusOK, gin.H{"user": user, "value": value}) + } else { + c.JSON(http.StatusOK, gin.H{"user": user, "status": "no value"}) + } + }) + + // TODO Replace with JWT + authorized := r.Group("/", gin.BasicAuth(gin.Accounts{ + "mobile": "a_nil_trap", // user:mobile password:a_nil_trap + "web": "a_nil_trap", // user:web password:a_nil_trap + })) + + authorized.POST("register", func(c *gin.Context) { + user := c.MustGet(gin.AuthUserKey).(string) + + // Parse JSON + var json struct { + Value string `json:"value" binding:"required"` + } + + if c.Bind(&json) == nil { + db[user] = json.Value + c.JSON(http.StatusOK, gin.H{"status": "ok"}) + } + }) + + return r +} diff --git a/go-app/vendor/vendor.json b/go-app/vendor/vendor.json new file mode 100644 index 00000000..9c63ceb8 --- /dev/null +++ b/go-app/vendor/vendor.json @@ -0,0 +1,91 @@ +{ + "comment": "", + "ignore": "test", + "package": [ + { + "checksumSHA1": "QeKwBtN2df+j+4stw3bQJ6yO4EY=", + "path": "github.com/gin-contrib/sse", + "revision": "5545eab6dad3bbbd6c5ae9186383c2a9d23c0dae", + "revisionTime": "2019-03-01T06:25:29Z" + }, + { + "checksumSHA1": "hTnhsCu6LPUweVZbsnDl2RDpAFg=", + "path": "github.com/gin-gonic/gin", + "revision": "04eecb1283dbd84c3babae7b3923ac71b18a56f9", + "revisionTime": "2019-05-10T06:03:25Z" + }, + { + "checksumSHA1": "w+RnWTXWA44K2IM9EmsbJPzQzRM=", + "path": "github.com/gin-gonic/gin/binding", + "revision": "04eecb1283dbd84c3babae7b3923ac71b18a56f9", + "revisionTime": "2019-05-10T06:03:25Z" + }, + { + "checksumSHA1": "rST0S8cuVbM57VmJhWXhKNUkKTc=", + "path": "github.com/gin-gonic/gin/internal/json", + "revision": "04eecb1283dbd84c3babae7b3923ac71b18a56f9", + "revisionTime": "2019-05-10T06:03:25Z" + }, + { + "checksumSHA1": "G2Aj1V/HtK2sJGFZc9tNGNsd4MY=", + "path": "github.com/gin-gonic/gin/render", + "revision": "04eecb1283dbd84c3babae7b3923ac71b18a56f9", + "revisionTime": "2019-05-10T06:03:25Z" + }, + { + "checksumSHA1": "Y2MOwzNZfl4NRNDbLCZa6sgx7O0=", + "path": "github.com/golang/protobuf/proto", + "revision": "e91709a02e0e8ff8b86b7aa913fdc9ae9498e825", + "revisionTime": "2019-04-09T05:09:43Z" + }, + { + "checksumSHA1": "TB2vxux9xQbvsTHOVt4aRTuvSn4=", + "path": "github.com/json-iterator/go", + "revision": "0ff49de124c6f76f8494e194af75bde0f1a49a29", + "revisionTime": "2019-03-06T14:29:09Z" + }, + { + "checksumSHA1": "FCTkVf8YbFJ4rAHSiFJm/tCiLbY=", + "path": "github.com/mattn/go-isatty", + "revision": "c1975dc15c1d481e8da23f6ed313bb071136b98f", + "revisionTime": "2019-04-24T07:51:23Z" + }, + { + "checksumSHA1": "ZTcgWKWHsrX0RXYVXn5Xeb8Q0go=", + "path": "github.com/modern-go/concurrent", + "revision": "bacd9c7ef1dd9b15be4a9909b8ac7a4e313eec94", + "revisionTime": "2018-03-06T01:26:44Z" + }, + { + "checksumSHA1": "qvH48wzTIV3QKSDqI0dLFtVjaDI=", + "path": "github.com/modern-go/reflect2", + "revision": "94122c33edd36123c84d5368cfb2b69df93a0ec8", + "revisionTime": "2018-07-18T01:23:57Z" + }, + { + "checksumSHA1": "RBRh7hUVcoELofg7TinPuBUG/po=", + "path": "github.com/ugorji/go/codec", + "revision": "08f7b401aef15f3d544472dd46bf6788cdfe55bf", + "revisionTime": "2019-05-07T20:14:01Z" + }, + { + "checksumSHA1": "xTTolmUyMtTkwMASe17ec7cr9Qg=", + "path": "golang.org/x/sys/unix", + "revision": "a5b02f93d862f065920dd6a40dddc66b60d0dec4", + "revisionTime": "2019-05-09T06:39:11Z" + }, + { + "checksumSHA1": "P/k5ZGf0lEBgpKgkwy++F7K1PSg=", + "path": "gopkg.in/go-playground/validator.v8", + "revision": "5f1438d3fca68893a817e4a66806cea46a9e4ebf", + "revisionTime": "2017-07-30T05:02:35Z" + }, + { + "checksumSHA1": "QqDq2x8XOU7IoOR98Cx1eiV5QY8=", + "path": "gopkg.in/yaml.v2", + "revision": "51d6538a90f86fe93ac480b35f37b2be17fef232", + "revisionTime": "2018-11-15T11:05:04Z" + } + ], + "rootPath": "github.com/CodeLanka/TrainPal-Mobile-App/go-app" +}