refactor: general-node and map-node to use flotte types for service registration
This commit is contained in:
@@ -1,24 +1,12 @@
|
||||
package generalnode
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func Start() {
|
||||
router := gin.Default()
|
||||
|
||||
// Get Status
|
||||
router.GET("/status", func(c *gin.Context) {
|
||||
c.JSON(200, gin.H{
|
||||
"message": "pong",
|
||||
})
|
||||
})
|
||||
|
||||
// Add Service
|
||||
router.POST("/service", func(c *gin.Context) {
|
||||
c.JSON(200, gin.H{
|
||||
"serviceName": "service1",
|
||||
"status": "registered",
|
||||
})
|
||||
})
|
||||
router = registerRoutes(router)
|
||||
|
||||
router.Run("localhost:8000") // listen and serve on 0.0.0.0:8000
|
||||
}
|
||||
|
38
internal/general-node/routes.go
Normal file
38
internal/general-node/routes.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package generalnode
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/alexohneander/flotte/pkg/types/request"
|
||||
respone "github.com/alexohneander/flotte/pkg/types/response"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func registerRoutes(router *gin.Engine) *gin.Engine {
|
||||
// Get Status
|
||||
router.GET("/ping", func(c *gin.Context) {
|
||||
c.JSON(200, gin.H{
|
||||
"message": "pong",
|
||||
})
|
||||
})
|
||||
|
||||
// Add Service
|
||||
router.POST("/service", func(c *gin.Context) {
|
||||
defer c.Request.Body.Close()
|
||||
var req request.ServiceRegister
|
||||
err := json.NewDecoder(c.Request.Body).Decode(&req)
|
||||
|
||||
if err != nil {
|
||||
c.JSON(400, gin.H{
|
||||
"message": err.Error(),
|
||||
})
|
||||
}
|
||||
|
||||
c.JSON(200, respone.ServiceRegister{
|
||||
ServiceName: req.Name,
|
||||
Status: "registered",
|
||||
})
|
||||
})
|
||||
|
||||
return router
|
||||
}
|
Reference in New Issue
Block a user