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
35 changes: 35 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: CI for nf-example

on:
push:
branches: [ main, master, feature/* ]
pull_request:

jobs:
build-and-test:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.24"

- name: Cache Go modules
uses: actions/cache@v4
with:
path: |
~/go/pkg/mod
~/.cache/go-build
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-

- name: Run unit tests
run: go test ./...

- name: Build nf binary
run: go build -o bin/nf ./cmd/main.go
61 changes: 61 additions & 0 deletions internal/sbi/api_student.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package sbi

import (
"net/http"

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

// Rutas para el nuevo servicio /student
func (s *Server) getStudentRoute() []Route {
return []Route{
{
Name: "GetStudent",
Method: http.MethodGet,
Pattern: "/:id",
APIFunc: s.HTTPGetStudent,
},
{
Name: "CreateStudent",
Method: http.MethodPost,
Pattern: "/",
APIFunc: s.HTTPCreateStudent,
},
}
}

// Estructura para el cuerpo del POST
type Student struct {
ID string `json:"id" binding:"required"`
Name string `json:"name" binding:"required"`
}

// GET /student/:id
func (s *Server) HTTPGetStudent(c *gin.Context) {
id := c.Param("id")
if id == "" {
c.JSON(http.StatusBadRequest, gin.H{"error": "id is required"})
return
}

c.JSON(http.StatusOK, gin.H{
"id": id,
"name": "Student " + id,
"msg": "Student info from nf-example",
})
}

// POST /student/
func (s *Server) HTTPCreateStudent(c *gin.Context) {
var student Student

if err := c.ShouldBindJSON(&student); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}

c.JSON(http.StatusCreated, gin.H{
"msg": "Student created successfully",
"student": student,
})
}
4 changes: 4 additions & 0 deletions internal/sbi/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ func newRouter(s *Server) *gin.Engine {

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

studentGroup := router.Group("/student")
applyRoutes(studentGroup, s.getStudentRoute())


return router
}
Expand Down