This commit is contained in:
parent
167d067aed
commit
90765beb35
@ -1,6 +1,4 @@
|
||||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
git.pbiernat.dev/egommerce/go-api-pkg v0.0.134 h1:ToujzrSBAD0Yt62T4+Ak+5pRCw6sMYnry3FDTo3eRnM=
|
||||
git.pbiernat.dev/egommerce/go-api-pkg v0.0.134/go.mod h1:w2N79aoumjrrcrGPJLkCwxAHtrLd7G4Uj8VOxvPooa0=
|
||||
git.pbiernat.dev/egommerce/go-api-pkg v0.0.136 h1:SzJRAkqJKdng/3d0V7o/R0yGh7QaZynPBn/P++on9RA=
|
||||
git.pbiernat.dev/egommerce/go-api-pkg v0.0.136/go.mod h1:w2N79aoumjrrcrGPJLkCwxAHtrLd7G4Uj8VOxvPooa0=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
|
@ -1,10 +0,0 @@
|
||||
package definition
|
||||
|
||||
type AuthLoginRequest struct {
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
}
|
||||
|
||||
type AuthLoginResponse struct {
|
||||
JWTToken string `json:"jwt_token"`
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
package definition
|
||||
|
||||
type HealthResponse struct {
|
||||
Status string `json:"status,omitempty"`
|
||||
}
|
9
src/internal/app/server/config_handler.go
Normal file
9
src/internal/app/server/config_handler.go
Normal file
@ -0,0 +1,9 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func (s *Server) ConfigHandler(c *fiber.Ctx) error {
|
||||
return c.JSON(s.conf)
|
||||
}
|
@ -1,16 +1,15 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
def "git.pbiernat.dev/egommerce/identity-service/internal/app/definition"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
type HealthResponse struct {
|
||||
Status string `json:"status,omitempty"`
|
||||
}
|
||||
|
||||
func (s *Server) HealthHandler(c *fiber.Ctx) error {
|
||||
return c.JSON(&def.HealthResponse{
|
||||
return c.JSON(&HealthResponse{
|
||||
Status: "OK",
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Server) ConfigHandler(c *fiber.Ctx) error {
|
||||
return c.JSON(s.conf)
|
||||
}
|
||||
|
@ -1,13 +1,21 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
def "git.pbiernat.dev/egommerce/identity-service/internal/app/definition"
|
||||
"git.pbiernat.dev/egommerce/identity-service/internal/app/service"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
type AuthLoginRequest struct {
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
}
|
||||
|
||||
type AuthLoginResponse struct {
|
||||
JWTToken string `json:"jwt_token"`
|
||||
}
|
||||
|
||||
func (s *Server) LoginHandler(c *fiber.Ctx) error {
|
||||
data := new(def.AuthLoginRequest)
|
||||
data := new(AuthLoginRequest)
|
||||
if err := c.BodyParser(data); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -20,5 +28,5 @@ func (s *Server) LoginHandler(c *fiber.Ctx) error {
|
||||
cookie := service.AuthService.Cookie("auth_token", token)
|
||||
c.Cookie(cookie)
|
||||
|
||||
return c.JSON(&def.AuthLoginResponse{JWTToken: token})
|
||||
return c.JSON(&AuthLoginResponse{JWTToken: token})
|
||||
}
|
||||
|
@ -17,6 +17,11 @@ var (
|
||||
})
|
||||
)
|
||||
|
||||
func SetupMiddlewares(s *Server) {
|
||||
s.App.Use(defaultCORS)
|
||||
s.App.Use(LoggingMiddleware(s.log))
|
||||
}
|
||||
|
||||
func SetupRoutes(s *Server) {
|
||||
s.App.Options("*", defaultCORS)
|
||||
|
||||
@ -26,11 +31,7 @@ func SetupRoutes(s *Server) {
|
||||
api := s.App.Group("/api")
|
||||
v1 := api.Group("/v1")
|
||||
v1.Post("/login", s.LoginHandler)
|
||||
}
|
||||
|
||||
func SetupMiddlewares(s *Server) {
|
||||
s.App.Use(defaultCORS)
|
||||
s.App.Use(LoggingMiddleware(s.log))
|
||||
v1.All("/traefik", s.TraefikHandler)
|
||||
}
|
||||
|
||||
// Middlewares
|
||||
@ -41,6 +42,16 @@ func LoggingMiddleware(log *fluentd.Logger) func(c *fiber.Ctx) error {
|
||||
return c.Next()
|
||||
}
|
||||
|
||||
if strings.Contains(path, "/traefik") {
|
||||
log.Log("Request: %s, Headers: %v, remote: %s, via: %s",
|
||||
c.Request().URI().String(),
|
||||
c.GetRespHeaders(),
|
||||
c.Context().RemoteIP().String(),
|
||||
string(c.Context().UserAgent()))
|
||||
|
||||
return c.Next()
|
||||
}
|
||||
|
||||
log.Log("Request: %s, remote: %s, via: %s",
|
||||
c.Request().URI().String(),
|
||||
c.Context().RemoteIP().String(),
|
||||
|
18
src/internal/app/server/traefik_handler.go
Normal file
18
src/internal/app/server/traefik_handler.go
Normal file
@ -0,0 +1,18 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"git.pbiernat.dev/egommerce/identity-service/internal/app/service"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
type TraefikAuthResponse struct {
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
func (s *Server) TraefikHandler(c *fiber.Ctx) error {
|
||||
cookie := service.AuthService.Cookie("traefik", "tmp-dummy-traefik-token")
|
||||
c.Cookie(cookie)
|
||||
s.log.Log("Traefik action set cookie. done.")
|
||||
|
||||
return c.JSON(&TraefikAuthResponse{Status: "OK"})
|
||||
}
|
Loading…
Reference in New Issue
Block a user