Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions go-app/.gcloudignore
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions go-app/.gitignore
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions go-app/app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
runtime: go111
20 changes: 20 additions & 0 deletions go-app/main.go
Original file line number Diff line number Diff line change
@@ -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")
}
48 changes: 48 additions & 0 deletions go-app/routes/routes.go
Original file line number Diff line number Diff line change
@@ -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
}
91 changes: 91 additions & 0 deletions go-app/vendor/vendor.json
Original file line number Diff line number Diff line change
@@ -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"
}