chore: scaffold project workbench

This commit is contained in:
2026-07-18 15:50:04 +08:00
parent c58af44b73
commit 619a8b4b3b
9 changed files with 258 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
package httpx
import (
"net/http"
"github.com/gin-gonic/gin"
"senlinai-agent/backend/internal/config"
)
func NewRouter(cfg config.Config) *gin.Engine {
if cfg.Env == "test" {
gin.SetMode(gin.TestMode)
}
router := gin.New()
router.Use(gin.Recovery())
router.GET("/healthz", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"status": "ok"})
})
return router
}

View File

@@ -0,0 +1,21 @@
package httpx
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/require"
"senlinai-agent/backend/internal/config"
)
func TestHealthz(t *testing.T) {
router := NewRouter(config.Config{Env: "test"})
req := httptest.NewRequest(http.MethodGet, "/healthz", nil)
rec := httptest.NewRecorder()
router.ServeHTTP(rec, req)
require.Equal(t, http.StatusOK, rec.Code)
require.JSONEq(t, `{"status":"ok"}`, rec.Body.String())
}