OSDN Git Service

init gin
authorHAOYUatHZ <haoyu@protonmail.com>
Tue, 27 Aug 2019 06:50:42 +0000 (14:50 +0800)
committerHAOYUatHZ <haoyu@protonmail.com>
Tue, 27 Aug 2019 06:50:42 +0000 (14:50 +0800)
toolbar/precog/api/server.go

index abfa34d..bdad6cc 100644 (file)
@@ -1,9 +1,13 @@
 package api
 
 import (
+       "fmt"
+
+       "github.com/gin-gonic/gin"
        "github.com/jinzhu/gorm"
 
        "github.com/vapor/toolbar/precog/config"
+       "github.com/vapor/toolbar/precog/database/orm"
 )
 
 type server struct {
@@ -19,9 +23,14 @@ func NewApiServer(cfg *config.Config, db *gorm.DB) *server {
 }
 
 func (s *server) Run() {
-       // setup gin
+       router := gin.Default()
+
+       router.POST("/list-nodes", listNodes)
 
-       // disable log
+       router.Run(fmt.Sprintf(":%d", s.cfg.API.ListeningPort))
+}
 
-       // set up router, bind handler
+// TODO: cannot use listNodes (type func(*gin.Context) ([]*orm.Node, error)) as type gin.HandlerFunc in argument to router.RouterGroup.POST
+func listNodes(_ *gin.Context) ([]*orm.Node, error) {
+       return nil, nil
 }