Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
Add github.com/google/jsonapi and use it to return json api conforming API in /auth/login
天舟e6b10d067839
diff --git a/backend/api/auth.go b/backend/api/auth.goindex 748bb4ac60..679daff106 100644--- a/backend/api/auth.go+++ b/backend/api/auth.go@@ -3,6 +3,7 @@ package apiimport ("net/http"+ "github.com/google/jsonapi""github.com/labstack/echo/v4")@@ -11,8 +12,8 @@ var ()type Login struct {- Email string `json:"email"`- Password string `json:"password"`+ Email string `jsonapi:"attr,email"`+ Password string `jsonapi:"attr,password"`}type AuthService struct {@@ -20,6 +21,17 @@ type AuthService struct {func (s *AuthService) RegisterRoutes(g *echo.Group) {g.POST("/auth/login", func(c echo.Context) error {- return c.String(http.StatusOK, "")+ 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})}diff --git a/backend/go.mod b/backend/go.modindex 3cd5b37b43..1f1c5c471d 100644--- a/backend/go.mod+++ b/backend/go.mod@@ -4,6 +4,7 @@ go 1.16require (github.com/golang-migrate/migrate/v4 v4.14.1 // indirect+ github.com/google/jsonapi v1.0.0 // indirectgithub.com/labstack/echo/v4 v4.2.2 // indirectgithub.com/mattn/go-sqlite3 v1.14.7 // indirect)diff --git a/backend/go.sum b/backend/go.sumindex 0f0801949d..5a203d73e9 100644--- a/backend/go.sum+++ b/backend/go.sum@@ -128,6 +128,8 @@ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ=github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=+github.com/google/jsonapi v1.0.0 h1:qIGgO5Smu3yJmSs+QlvhQnrscdZfFhiV6S8ryJAglqU=+github.com/google/jsonapi v1.0.0/go.mod h1:YYHiRPJT8ARXGER8In9VuLv4qvLfDmA9ULQqptbLE4s=github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=