From 671246003250084f2a19fd3f223feb421a6c7f2b Mon Sep 17 00:00:00 2001 From: lvescobar Date: Mon, 11 May 2026 13:24:34 -0500 Subject: [PATCH 1/2] feat: add GET and POST /subscriber endpoints --- internal/context/context.go | 7 +++++ internal/sbi/api_subscriber.go | 39 ++++++++++++++++++++++++++++ internal/sbi/processor/subscriber.go | 31 ++++++++++++++++++++++ internal/sbi/router.go | 3 +++ 4 files changed, 80 insertions(+) create mode 100644 internal/sbi/api_subscriber.go create mode 100644 internal/sbi/processor/subscriber.go diff --git a/internal/context/context.go b/internal/context/context.go index 2bfe8b2..98716eb 100644 --- a/internal/context/context.go +++ b/internal/context/context.go @@ -10,6 +10,11 @@ import ( "github.com/free5gc/openapi/models" ) +type Subscriber struct { + IMSI string `json:"imsi"` + Name string `json:"name"` +} + type NFContext struct { NfId string Name string @@ -18,6 +23,7 @@ type NFContext struct { SBIPort int SpyFamilyData map[string]string + Subscribers []Subscriber } var nfContext = NFContext{} @@ -40,6 +46,7 @@ func InitNfContext() { nfContext.BindingIPv4 = "0.0.0.0" } } + nfContext.Subscribers = []Subscriber{} nfContext.SpyFamilyData = map[string]string{ "Loid": "Forger", "Anya": "Forger", diff --git a/internal/sbi/api_subscriber.go b/internal/sbi/api_subscriber.go new file mode 100644 index 0000000..1f57de2 --- /dev/null +++ b/internal/sbi/api_subscriber.go @@ -0,0 +1,39 @@ +package sbi + +import ( + "net/http" + + "github.com/Alonza0314/nf-example/internal/logger" + "github.com/gin-gonic/gin" +) + +func (s *Server) getSubscriberRoute() []Route { + return []Route{ + { + Name: "Get All Subscribers", + Method: http.MethodGet, + Pattern: "/", + APIFunc: s.HTTPGetAllSubscribers, + // Use: curl -X GET http://127.0.0.163:8000/subscriber/ -w "\n" + }, + { + Name: "Add Subscriber", + Method: http.MethodPost, + Pattern: "/", + APIFunc: s.HTTPAddSubscriber, + // Use: curl -X POST http://127.0.0.163:8000/subscriber/ \ + // -H "Content-Type: application/json" \ + // -d '{"imsi":"208930000000001","name":"UE-Test"}' -w "\n" + }, + } +} + +func (s *Server) HTTPGetAllSubscribers(c *gin.Context) { + logger.SBILog.Infof("HTTPGetAllSubscribers") + s.Processor().GetAllSubscribers(c) +} + +func (s *Server) HTTPAddSubscriber(c *gin.Context) { + logger.SBILog.Infof("HTTPAddSubscriber") + s.Processor().AddSubscriber(c) +} diff --git a/internal/sbi/processor/subscriber.go b/internal/sbi/processor/subscriber.go new file mode 100644 index 0000000..cb1d96e --- /dev/null +++ b/internal/sbi/processor/subscriber.go @@ -0,0 +1,31 @@ +package processor + +import ( + "net/http" + + context "github.com/Alonza0314/nf-example/internal/context" + "github.com/gin-gonic/gin" +) + +func (p *Processor) GetAllSubscribers(c *gin.Context) { + subscribers := p.Context().Subscribers + if len(subscribers) == 0 { + c.JSON(http.StatusOK, []context.Subscriber{}) + return + } + c.JSON(http.StatusOK, subscribers) +} + +func (p *Processor) AddSubscriber(c *gin.Context) { + var sub context.Subscriber + if err := c.ShouldBindJSON(&sub); err != nil { + c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) + return + } + if sub.IMSI == "" || sub.Name == "" { + c.JSON(http.StatusBadRequest, gin.H{"error": "imsi and name are required"}) + return + } + p.Context().Subscribers = append(p.Context().Subscribers, sub) + c.JSON(http.StatusCreated, sub) +} diff --git a/internal/sbi/router.go b/internal/sbi/router.go index b62139f..d34b93d 100644 --- a/internal/sbi/router.go +++ b/internal/sbi/router.go @@ -45,6 +45,9 @@ func newRouter(s *Server) *gin.Engine { spyFamilyGroup := router.Group("/spyfamily") applyRoutes(spyFamilyGroup, s.getSpyFamilyRoute()) + subscriberGroup := router.Group("/subscriber") + applyRoutes(subscriberGroup, s.getSubscriberRoute()) + return router } From 76d9d8686490dce17878edf7b01c3e9d0af82d83 Mon Sep 17 00:00:00 2001 From: lvescobar Date: Mon, 11 May 2026 13:32:30 -0500 Subject: [PATCH 2/2] ci: add GitHub Actions CI pipeline --- .github/workflows/ci.yml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..303a902 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,26 @@ +name: CI Pipeline + +on: + push: + branches: [ main, "feature/**" ] + pull_request: + branches: [ main ] + +jobs: + build-and-test: + runs-on: ubuntu-22.04 + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.21' + + - name: Build + run: go build ./... + + - name: Run tests + run: go test -v ./...