Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
Make the router registration under the server package
天舟7d4546fa2a8a
diff --git a/backend/api/auth.go b/backend/api/auth.goindex 679daff106..92c6a22f76 100644--- a/backend/api/auth.go+++ b/backend/api/auth.go@@ -1,14 +1,7 @@package api-import (- "net/http"-- "github.com/google/jsonapi"- "github.com/labstack/echo/v4"-)-var (- _ Service = (*AuthService)(nil)+ _ AuthService = (*AuthService)(nil))type Login struct {@@ -16,22 +9,6 @@ type Login struct {Password string `jsonapi:"attr,password"`}-type AuthService struct {-}--func (s *AuthService) RegisterRoutes(g *echo.Group) {- g.POST("/auth/login", func(c echo.Context) error {- login := &Login{}- if err := jsonapi.UnmarshalPayload(c.Request().Body, login); err != nil {- return echo.NewHTTPError(http.StatusBadRequest, "Malformatted login request")- }-- c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)- c.Response().WriteHeader(http.StatusOK)- if err := jsonapi.MarshalPayload(c.Response().Writer, login); err != nil {- return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal login response")- }-- return nil- })+type AuthService interface {+ // FindUserWithEmailAndPassword(email string, password string) (*Principal, error)}diff --git a/backend/api/environment.go b/backend/api/environment.goindex 70baba4ab3..29bc8f37d2 100644--- a/backend/api/environment.go+++ b/backend/api/environment.go@@ -1,13 +1,7 @@package api-import (- "fmt"-- "github.com/labstack/echo/v4"-)-var (- _ Service = (*EnvironmentService)(nil)+ _ EnvironmentService = (*EnvironmentService)(nil))type Environment struct {@@ -16,9 +10,5 @@ type Environment struct {Order uint `json:"order"`}-type EnvironmentService struct {-}--func (s *EnvironmentService) RegisterRoutes(g *echo.Group) {- fmt.Println("registerEnvironmentRoutes")+type EnvironmentService interface {}diff --git a/backend/server/auth.go b/backend/server/auth.gonew file mode 100644index 0000000000..0f3c42a7b5--- /dev/null+++ b/backend/server/auth.go@@ -0,0 +1,26 @@+package server++import (+ "net/http"++ "github.com/bytebase/bytebase/api"+ "github.com/google/jsonapi"+ "github.com/labstack/echo/v4"+)++func (s *Server) registerAuthRoutes(g *echo.Group) {+ g.POST("/auth/login", func(c echo.Context) error {+ login := &api.Login{}+ if err := jsonapi.UnmarshalPayload(c.Request().Body, login); err != nil {+ return echo.NewHTTPError(http.StatusBadRequest, "Malformatted login request")+ }++ c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)+ c.Response().WriteHeader(http.StatusOK)+ if err := jsonapi.MarshalPayload(c.Response().Writer, login); err != nil {+ return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal login response")+ }++ return nil+ })+}diff --git a/backend/api/debug.go b/backend/server/debug.gosimilarity index 62%rename from backend/api/debug.gorename to backend/server/debug.goindex 2d068c33de..2f96149810 100644--- a/backend/api/debug.go+++ b/backend/server/debug.go@@ -1,4 +1,4 @@-package api+package serverimport ("fmt"@@ -8,14 +8,7 @@ import ("github.com/labstack/echo/v4")-var (- _ Service = (*DebugService)(nil)-)--type DebugService struct {-}--func (s *DebugService) RegisterRoutes(g *echo.Group) {+func (s *Server) registerDebugRoutes(g *echo.Group) {g.GET("/ping", func(c echo.Context) error {return c.String(http.StatusOK, fmt.Sprintf("[%v] Pong from backend", time.Now().Format("2006-01-02 15:04:05")))})diff --git a/backend/server/environment.go b/backend/server/environment.gonew file mode 100644index 0000000000..11c171b362--- /dev/null+++ b/backend/server/environment.go@@ -0,0 +1,11 @@+package server++import (+ "fmt"++ "github.com/labstack/echo/v4"+)++func (s *Server) registerEnvironmentRoutes(g *echo.Group) {+ fmt.Println("registerEnvironmentRoutes")+}diff --git a/backend/server/server.go b/backend/server/server.goindex 14f1215090..1d57b8fa6b 100644--- a/backend/server/server.go+++ b/backend/server/server.go@@ -13,7 +13,6 @@ import ()type Server struct {- DebugService api.DebugServiceAuthService api.AuthServiceEnvironmentService api.EnvironmentService@@ -64,11 +63,11 @@ func NewServer() *Server {g := e.Group("/api")- s.DebugService.RegisterRoutes(g)+ s.registerDebugRoutes(g)- s.AuthService.RegisterRoutes(g)+ s.registerAuthRoutes(g)- s.EnvironmentService.RegisterRoutes(g)+ s.registerEnvironmentRoutes(g)return s}