build against ginpb
This commit is contained in:
parent
9e7887ae88
commit
3869dc8c24
29
gin.go
29
gin.go
|
@ -19,6 +19,30 @@ import (
|
||||||
func handlePort(port int) {
|
func handlePort(port int) {
|
||||||
r := ginpb.Default()
|
r := ginpb.Default()
|
||||||
|
|
||||||
|
// Ping test
|
||||||
|
r.GET("/ping", func(c *ginpb.Context) {
|
||||||
|
// c.String(http.StatusOK, "pong")
|
||||||
|
})
|
||||||
|
|
||||||
|
// Get user value
|
||||||
|
r.GET("/user/:name", func(c *ginpb.Context) {
|
||||||
|
// c.JSON(http.StatusOK, gin.H{"user": "test", "status": "no value"})
|
||||||
|
/*
|
||||||
|
user := c.Params.ByName("name")
|
||||||
|
value, ok := db[user]
|
||||||
|
if ok {
|
||||||
|
c.JSON(http.StatusOK, ginpb.H{"user": user, "value": value})
|
||||||
|
} else {
|
||||||
|
c.JSON(http.StatusOK, ginpb.H{"user": user, "status": "no value"})
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func handlePortGin(port int) {
|
||||||
|
r := gin.Default()
|
||||||
|
|
||||||
// Ping test
|
// Ping test
|
||||||
r.GET("/ping", func(c *gin.Context) {
|
r.GET("/ping", func(c *gin.Context) {
|
||||||
c.String(http.StatusOK, "pong")
|
c.String(http.StatusOK, "pong")
|
||||||
|
@ -27,12 +51,7 @@ func handlePort(port int) {
|
||||||
// Get user value
|
// Get user value
|
||||||
r.GET("/user/:name", func(c *gin.Context) {
|
r.GET("/user/:name", func(c *gin.Context) {
|
||||||
user := c.Params.ByName("name")
|
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"})
|
c.JSON(http.StatusOK, gin.H{"user": user, "status": "no value"})
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue