From 67fa0e9230ba427196f76c0c4a0dfd8ab953ea36 Mon Sep 17 00:00:00 2001 From: Oscar1 Date: Tue, 18 Nov 2025 22:15:45 +0000 Subject: [PATCH] feat: add custom API service with GET and POST endpoints --- internal/sbi/custom/custom.go | 23 +++++++++++++++++++++++ internal/sbi/router.go | 19 +++++++++++-------- 2 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 internal/sbi/custom/custom.go diff --git a/internal/sbi/custom/custom.go b/internal/sbi/custom/custom.go new file mode 100644 index 0000000..f107215 --- /dev/null +++ b/internal/sbi/custom/custom.go @@ -0,0 +1,23 @@ +package custom + +import ( + "github.com/gin-gonic/gin" + "net/http" +) + +func AddCustomService(r *gin.Engine) { + r.GET("/custom/hello", func(c *gin.Context) { + c.JSON(http.StatusOK, gin.H{ + "message": "Hello from Evelin’s custom API!", + }) + }) + + r.POST("/custom/echo", func(c *gin.Context) { + var data map[string]interface{} + c.BindJSON(&data) + c.JSON(http.StatusOK, gin.H{ + "received": data, + }) + }) +} + diff --git a/internal/sbi/router.go b/internal/sbi/router.go index b62139f..486b9b4 100644 --- a/internal/sbi/router.go +++ b/internal/sbi/router.go @@ -1,9 +1,9 @@ package sbi - +import "nf-example/internal/sbi/custom" import ( "fmt" "net/http" - + "github.com/omatabajoy/nf-example/internal/sbi/custom" "github.com/Alonza0314/nf-example/internal/logger" "github.com/Alonza0314/nf-example/pkg/app" "github.com/gin-gonic/gin" @@ -37,15 +37,18 @@ func applyRoutes(group *gin.RouterGroup, routes []Route) { } func newRouter(s *Server) *gin.Engine { - router := logger_util.NewGinWithLogrus(logger.GinLog) + router := logger_util.NewGinWithLogrus(logger.GinLog) + + defaultGroup := router.Group("/default") + applyRoutes(defaultGroup, s.getDefaultRoute()) - defaultGroup := router.Group("/default") - applyRoutes(defaultGroup, s.getDefaultRoute()) + spyFamilyGroup := router.Group("/spyfamily") + applyRoutes(spyFamilyGroup, s.getSpyFamilyRoute()) - spyFamilyGroup := router.Group("/spyfamily") - applyRoutes(spyFamilyGroup, s.getSpyFamilyRoute()) + // Agregar tu custom API + custom.AddCustomService(router) - return router + return router } func bindRouter(nf app.App, router *gin.Engine, tlsKeyLogPath string) (*http.Server, error) {