Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions internal/newapi/handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package newapi

import (
"net/http"
"github.com/gin-gonic/gin"
)

func GetMessage(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"message": "Hola desde el nuevo GET!",
})
}

type CreateRequest struct {
Name string `json:"name"`
}

func CreateItem(c *gin.Context) {
var req CreateRequest
if err := c.BindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid input"})
return
}

c.JSON(http.StatusCreated, gin.H{
"status": "created",
"name": req.Name,
})
}
22 changes: 22 additions & 0 deletions internal/sbi/api_secondapi.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package sbi

import (
"github.com/gabbyrz024/nf-example/internal/secondapi"
)

func (s *Server) getSecondAPIRoute() []Route {
return []Route{
{
Name: "secondapi-status",
Method: "GET",
Pattern: "/status",
APIFunc: secondapi.GetStatus,
},
{
Name: "secondapi-message",
Method: "POST",
Pattern: "/message",
APIFunc: secondapi.PostMessage,
},
}
}
5 changes: 5 additions & 0 deletions internal/sbi/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (

"github.com/free5gc/util/httpwrapper"
logger_util "github.com/free5gc/util/logger"

"github.com/gabbyrz024/nf-example/internal/secondapi"
)

type Route struct {
Expand Down Expand Up @@ -45,6 +47,9 @@ func newRouter(s *Server) *gin.Engine {
spyFamilyGroup := router.Group("/spyfamily")
applyRoutes(spyFamilyGroup, s.getSpyFamilyRoute())

secondAPIGroup := router.Group("/secondapi")
applyRoutes(secondAPIGroup, s.getSecondAPIRoute())

return router
}

Expand Down
31 changes: 31 additions & 0 deletions internal/secondapi/handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package secondapi

import (
"net/http"

"github.com/gin-gonic/gin"
)

func GetStatus(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"status": "second api running",
})
}

type MessageRequest struct {
Message string `json:"message"`
}

func PostMessage(c *gin.Context) {
var req MessageRequest
if err := c.BindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{
"error": err.Error(),
})
return
}

c.JSON(http.StatusOK, gin.H{
"received": req.Message,
})
}
31 changes: 31 additions & 0 deletions secondapi/handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package secondapi

import (
"net/http"

"github.com/gin-gonic/gin"
)

func GetStatus(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"status": "second api running",
})
}

type MessageRequest struct {
Message string `json:"message"`
}

func PostMessage(c *gin.Context) {
var req MessageRequest
if err := c.BindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{
"error": err.Error(),
})
return
}

c.JSON(http.StatusOK, gin.H{
"received": req.Message,
})
}