refactor: Fix linter errors
This commit is contained in:
@@ -19,7 +19,11 @@ func (c *PlainAuthController) Handler() gin.HandlerFunc {
|
||||
var payload dto.LoginRequest
|
||||
|
||||
if err := ginCtx.ShouldBindJSON(&payload); err != nil {
|
||||
sendErr := httpApp.NewResponseErrBuilder().WithStatusCode(http.StatusBadRequest).WithMessage(err.Error()).Send(ginCtx)
|
||||
sendErr := httpApp.
|
||||
NewResponseErrBuilder().
|
||||
WithStatusCode(http.StatusBadRequest).
|
||||
WithMessage(err.Error()).
|
||||
Send(ginCtx)
|
||||
if sendErr != nil {
|
||||
ginCtx.Writer.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
@@ -30,7 +34,11 @@ func (c *PlainAuthController) Handler() gin.HandlerFunc {
|
||||
|
||||
jwtString, err := c.authModule.Proceed(ginCtx.Request.Context(), payload.Login, payload.Password)
|
||||
if err != nil {
|
||||
sendErr := httpApp.NewResponseErrBuilder().WithStatusCode(http.StatusBadRequest).WithMessage(err.Error()).Send(ginCtx)
|
||||
sendErr := httpApp.
|
||||
NewResponseErrBuilder().
|
||||
WithStatusCode(http.StatusBadRequest).
|
||||
WithMessage(err.Error()).
|
||||
Send(ginCtx)
|
||||
if sendErr != nil {
|
||||
ginCtx.Writer.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
|
||||
30
router/controller/service/common.go
Normal file
30
router/controller/service/common.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"git.ostiwe.com/ostiwe-com/status/modules/log"
|
||||
http2 "git.ostiwe.com/ostiwe-com/status/pkg/http"
|
||||
"git.ostiwe.com/ostiwe-com/status/repository"
|
||||
"git.ostiwe.com/ostiwe-com/status/transform"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func processGetServicesHandler(c *gin.Context, publicOnly bool, serviceRepository repository.Service) {
|
||||
items, err := serviceRepository.All(c.Request.Context(), -1, 0, publicOnly)
|
||||
if err != nil {
|
||||
log.Global.Get(log.SERVER).Error(err)
|
||||
|
||||
writeErr := http2.NewResponseErrBuilder().
|
||||
WithMessage("Fetch service error").
|
||||
WithStatusCode(http.StatusInternalServerError).
|
||||
Send(c)
|
||||
if writeErr != nil {
|
||||
log.Global.Get(log.SERVER).Error(writeErr)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, transform.PublicServices(items...))
|
||||
}
|
||||
@@ -4,12 +4,9 @@ import (
|
||||
"net/http"
|
||||
|
||||
"git.ostiwe.com/ostiwe-com/status/modules/jwt"
|
||||
"git.ostiwe.com/ostiwe-com/status/modules/log"
|
||||
http2 "git.ostiwe.com/ostiwe-com/status/pkg/http"
|
||||
"git.ostiwe.com/ostiwe-com/status/repository"
|
||||
"git.ostiwe.com/ostiwe-com/status/router/controller"
|
||||
"git.ostiwe.com/ostiwe-com/status/router/midlleware"
|
||||
"git.ostiwe.com/ostiwe-com/status/transform"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
@@ -25,22 +22,7 @@ func (g *GetServices) New() controller.Controller {
|
||||
|
||||
func (g *GetServices) Handler() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
items, err := g.serviceRepository.All(c.Request.Context(), -1, 0, true)
|
||||
if err != nil {
|
||||
log.Global.Get(log.SERVER).Error(err)
|
||||
|
||||
writeErr := http2.NewResponseErrBuilder().
|
||||
WithMessage("Fetch service error").
|
||||
WithStatusCode(http.StatusInternalServerError).
|
||||
Send(c)
|
||||
if writeErr != nil {
|
||||
log.Global.Get(log.SERVER).Error(writeErr)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, transform.PublicServices(items...))
|
||||
processGetServicesHandler(c, false, g.serviceRepository)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,11 +3,8 @@ package service
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"git.ostiwe.com/ostiwe-com/status/modules/log"
|
||||
http2 "git.ostiwe.com/ostiwe-com/status/pkg/http"
|
||||
"git.ostiwe.com/ostiwe-com/status/repository"
|
||||
"git.ostiwe.com/ostiwe-com/status/router/controller"
|
||||
"git.ostiwe.com/ostiwe-com/status/transform"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
@@ -23,22 +20,7 @@ func (p *PublicGetServicesController) New() controller.Controller {
|
||||
|
||||
func (p *PublicGetServicesController) Handler() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
items, err := p.serviceRepository.All(c.Request.Context(), -1, 0, true)
|
||||
if err != nil {
|
||||
log.Global.Get(log.SERVER).Error(err)
|
||||
|
||||
writeErr := http2.NewResponseErrBuilder().
|
||||
WithMessage("Fetch service error").
|
||||
WithStatusCode(http.StatusInternalServerError).
|
||||
Send(c)
|
||||
if writeErr != nil {
|
||||
log.Global.Get(log.SERVER).Error(writeErr)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, transform.PublicServices(items...))
|
||||
processGetServicesHandler(c, true, p.serviceRepository)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,10 @@ func InitRoutes() *gin.Engine {
|
||||
}
|
||||
|
||||
log.Global.Get(log.SERVER).Info(fmt.Sprintf("Initialized %d routers", len(ctrlList)))
|
||||
log.Global.Get(log.SERVER).Info(fmt.Sprintf("Setting up routers is done for %dms, start server", time.Since(startTime).Milliseconds()))
|
||||
log.Global.Get(log.SERVER).Info(fmt.Sprintf(
|
||||
"Setting up routers is done for %dms, start server",
|
||||
time.Since(startTime).Milliseconds(),
|
||||
))
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user