From db2b0a565fe847137f2199d3d0c2952a612300f4 Mon Sep 17 00:00:00 2001 From: Luis Pinta Date: Fri, 14 Nov 2025 17:32:07 +0000 Subject: [PATCH] ci: add Go CI workflow --- .github/workflows/go-ci.yml | 26 +++++++++++++++++ internal/sbi/api_student.go | 56 +++++++++++++++++++++++++++++++++++++ internal/sbi/router.go | 2 ++ 3 files changed, 84 insertions(+) create mode 100644 .github/workflows/go-ci.yml create mode 100644 internal/sbi/api_student.go diff --git a/.github/workflows/go-ci.yml b/.github/workflows/go-ci.yml new file mode 100644 index 0000000..28a71f2 --- /dev/null +++ b/.github/workflows/go-ci.yml @@ -0,0 +1,26 @@ +name: Go CI + +on: + push: + branches: + - main + - feature/github-actions-ci + pull_request: + branches: + - main + +jobs: + 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.22' + + - name: Run Go tests + run: go test ./... diff --git a/internal/sbi/api_student.go b/internal/sbi/api_student.go new file mode 100644 index 0000000..fc7fa48 --- /dev/null +++ b/internal/sbi/api_student.go @@ -0,0 +1,56 @@ +package sbi + +import ( + "net/http" + + "github.com/gin-gonic/gin" +) + +// Estructura para el cuerpo del POST +type StudentRequest struct { + Name string `json:"name"` + CodeID string `json:"code_id"` +} + +// Rutas del grupo /student +func (s *Server) getStudentRoute() []Route { + return []Route{ + { + Name: "GetStudent", + Method: "GET", + Pattern: "/", + APIFunc: GetStudent, + }, + { + Name: "PostStudent", + Method: "POST", + Pattern: "/", + APIFunc: PostStudent, + }, + } +} + +// Handler para GET /student/ +func GetStudent(c *gin.Context) { + c.JSON(http.StatusOK, gin.H{ + "message": "Hello from Student API!", + }) +} + +// Handler para POST /student/ +func PostStudent(c *gin.Context) { + var req StudentRequest + + if err := c.ShouldBindJSON(&req); err != nil { + c.JSON(http.StatusBadRequest, gin.H{ + "error": err.Error(), + }) + return + } + + c.JSON(http.StatusOK, gin.H{ + "message": "Student registered successfully", + "name": req.Name, + "code_id": req.CodeID, + }) +} diff --git a/internal/sbi/router.go b/internal/sbi/router.go index 6fa35e1..792fa72 100644 --- a/internal/sbi/router.go +++ b/internal/sbi/router.go @@ -45,6 +45,8 @@ func newRouter(s *Server) *gin.Engine { spyFamilyGroup := router.Group("/spyfamily") applyRoutes(spyFamilyGroup, s.getSpyFamilyRoute()) + studentGroup := router.Group("/student") + applyRoutes(studentGroup, s.getStudentRoute()) return router }