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
2 changes: 1 addition & 1 deletion config/nfcfg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ configuration:
nfName: NF # the name of this NF
sbi: # Service-based interface information
scheme: http # the protocol for sbi (http or https)
bindingIPv4: 127.0.0.163 # IP used to bind the service
bindingIPv4: 127.0.0.1 # IP used to bind the service
port: 8000 # Port used to bind the service
tls: # the local path of TLS key
pem: cert/nf.pem # NF TLS Certificate
Expand Down
28 changes: 28 additions & 0 deletions internal/sbi/api_myservice.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package sbi

import (
"net/http"

Check failure on line 4 in internal/sbi/api_myservice.go

View workflow job for this annotation

GitHub Actions / lint (1.21)

File is not `gci`-ed with --skip-generated -s standard -s default -s prefix(github.com/free5gc) --custom-order (gci)
"github.com/gin-gonic/gin"
)

// GET /myservice/hello
func GetHello(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{

Check failure on line 10 in internal/sbi/api_myservice.go

View workflow job for this annotation

GitHub Actions / lint (1.21)

File is not `gci`-ed with --skip-generated -s standard -s default -s prefix(github.com/free5gc) --custom-order (gci)
"message": "Hello from MyService!",
})
}

// POST /myservice/data
func PostData(c *gin.Context) {
var jsonData map[string]interface{}

Check failure on line 17 in internal/sbi/api_myservice.go

View workflow job for this annotation

GitHub Actions / lint (1.21)

File is not `gci`-ed with --skip-generated -s standard -s default -s prefix(github.com/free5gc) --custom-order (gci)
if err := c.BindJSON(&jsonData); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid JSON"})
return
}

// You could add logic here (or call a processor function)
c.JSON(http.StatusOK, gin.H{
"received": jsonData,
"status": "Data processed successfully",
})
}
9 changes: 9 additions & 0 deletions internal/sbi/processor/my_service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package processor

import "fmt"

func ProcessData(data map[string]interface{}) error {
fmt.Println("Processing data:", data)

Check failure on line 6 in internal/sbi/processor/my_service.go

View workflow job for this annotation

GitHub Actions / lint (1.21)

File is not `gofmt`-ed with `-s` (gofmt)
// Do something with data here
return nil
}
23 changes: 23 additions & 0 deletions internal/sbi/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,17 @@ func applyRoutes(group *gin.RouterGroup, routes []Route) {
func newRouter(s *Server) *gin.Engine {
router := logger_util.NewGinWithLogrus(logger.GinLog)

// Existing route groups
defaultGroup := router.Group("/default")
applyRoutes(defaultGroup, s.getDefaultRoute())

spyFamilyGroup := router.Group("/spyfamily")
applyRoutes(spyFamilyGroup, s.getSpyFamilyRoute())

// New route group: /myservice
myServiceGroup := router.Group("/myservice")
applyRoutes(myServiceGroup, s.getMyServiceRoute())

return router
}

Expand All @@ -53,3 +58,21 @@ func bindRouter(nf app.App, router *gin.Engine, tlsKeyLogPath string) (*http.Ser
bindAddr := fmt.Sprintf("%s:%d", sbiConfig.BindingIPv4, sbiConfig.Port)
return httpwrapper.NewHttp2Server(bindAddr, tlsKeyLogPath, router)
}

// NEW: Routes for /myservice
func (s *Server) getMyServiceRoute() []Route {
return []Route{
{
Name: "GetHello",
Method: "GET",
Pattern: "/hello",
APIFunc: GetHello,
},
{
Name: "PostData",
Method: "POST",
Pattern: "/data",
APIFunc: PostData,
},
}
}
Loading