2018-04-10 10:32:34 +00:00
|
|
|
package routes
|
|
|
|
|
|
|
|
import (
|
2018-04-12 09:41:21 +00:00
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"git.trj.tw/golang/go-gallery/models"
|
2018-04-10 10:32:34 +00:00
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
|
|
|
// NewServ - get new service
|
|
|
|
func NewServ() *gin.Engine {
|
|
|
|
r := gin.Default()
|
|
|
|
return r
|
|
|
|
}
|
|
|
|
|
2018-04-11 09:27:48 +00:00
|
|
|
// SetDefaultRoutes -
|
2018-04-10 10:32:34 +00:00
|
|
|
func SetDefaultRoutes(r *gin.Engine) {
|
|
|
|
r.GET("/", func(c *gin.Context) {
|
2018-04-12 09:41:21 +00:00
|
|
|
accs, err := models.GetAllAccount()
|
|
|
|
if err != nil {
|
|
|
|
c.JSON(500, gin.H{
|
|
|
|
"message": "db error",
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
fmt.Println(accs)
|
|
|
|
c.JSON(200, accs)
|
2018-04-10 10:32:34 +00:00
|
|
|
})
|
2018-04-13 09:16:21 +00:00
|
|
|
|
|
|
|
api := r.Group("/api")
|
|
|
|
{
|
|
|
|
api.GET("/", func(c *gin.Context) {
|
|
|
|
c.JSON(200, gin.H{
|
|
|
|
"status": 200,
|
|
|
|
"message": "Success",
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
2018-04-10 10:32:34 +00:00
|
|
|
}
|