update package name
This commit is contained in:
parent
8a3c5050ac
commit
7e63a420b8
@ -1,4 +1,4 @@
|
||||
package facades
|
||||
package facade
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
@ -3,8 +3,8 @@ package gin
|
||||
import (
|
||||
"fmt"
|
||||
"framework_v2/internal/app/auth"
|
||||
"framework_v2/internal/app/facades"
|
||||
"framework_v2/internal/app/helpers"
|
||||
"framework_v2/internal/app/facade"
|
||||
"framework_v2/internal/app/helper"
|
||||
http2 "framework_v2/internal/middleware/http"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
@ -12,31 +12,31 @@ import (
|
||||
)
|
||||
|
||||
func GET(relativePath string, handlers ...interface{}) {
|
||||
facades.Router.GET(relativePath, func(c *gin.Context) {
|
||||
facade.Router.GET(relativePath, func(c *gin.Context) {
|
||||
doHandler(c, handlers...)
|
||||
})
|
||||
}
|
||||
|
||||
func POST(relativePath string, handlers ...interface{}) {
|
||||
facades.Router.POST(relativePath, func(c *gin.Context) {
|
||||
facade.Router.POST(relativePath, func(c *gin.Context) {
|
||||
doHandler(c, handlers...)
|
||||
})
|
||||
}
|
||||
|
||||
func PUT(relativePath string, handlers ...interface{}) {
|
||||
facades.Router.PUT(relativePath, func(c *gin.Context) {
|
||||
facade.Router.PUT(relativePath, func(c *gin.Context) {
|
||||
doHandler(c, handlers...)
|
||||
})
|
||||
}
|
||||
|
||||
func PATCH(relativePath string, handlers ...interface{}) {
|
||||
facades.Router.PATCH(relativePath, func(c *gin.Context) {
|
||||
facade.Router.PATCH(relativePath, func(c *gin.Context) {
|
||||
doHandler(c, handlers...)
|
||||
})
|
||||
}
|
||||
|
||||
func DELETE(relativePath string, handlers ...interface{}) {
|
||||
facades.Router.DELETE(relativePath, func(c *gin.Context) {
|
||||
facade.Router.DELETE(relativePath, func(c *gin.Context) {
|
||||
doHandler(c, handlers...)
|
||||
})
|
||||
}
|
||||
@ -48,7 +48,7 @@ func doHandler(c *gin.Context, handlers ...interface{}) {
|
||||
if c.Writer.Written() {
|
||||
return
|
||||
} else {
|
||||
helpers.ResponseError(c, http.StatusBadRequest, http2.ErrEmptyResponse)
|
||||
helper.ResponseError(c, http.StatusBadRequest, http2.ErrEmptyResponse)
|
||||
}
|
||||
|
||||
return
|
||||
@ -74,12 +74,12 @@ func wrapHandler(c *gin.Context, f interface{}) {
|
||||
case reflect.TypeOf((*auth.User)(nil)):
|
||||
userInfo := http2.DIJWTAuth(c)
|
||||
if userInfo == nil {
|
||||
helpers.ResponseError(c, http.StatusUnauthorized, http2.ErrNotValidToken)
|
||||
helper.ResponseError(c, http.StatusUnauthorized, http2.ErrNotValidToken)
|
||||
return
|
||||
}
|
||||
argValue = reflect.ValueOf(userInfo)
|
||||
default:
|
||||
helpers.ResponseError(c, http.StatusBadRequest, fmt.Errorf("invalid argument type: %s", argType.String()))
|
||||
helper.ResponseError(c, http.StatusBadRequest, fmt.Errorf("invalid argument type: %s", argType.String()))
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
package gin
|
||||
|
||||
import (
|
||||
"framework_v2/internal/app/facades"
|
||||
"framework_v2/internal/app/facade"
|
||||
"framework_v2/internal/http/controllers/user"
|
||||
"framework_v2/internal/middleware/http"
|
||||
ginzap "github.com/gin-contrib/zap"
|
||||
@ -12,9 +12,9 @@ import (
|
||||
func InitGin() {
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
|
||||
facades.Router = gin.New()
|
||||
facade.Router = gin.New()
|
||||
|
||||
facades.Router.Use(ginzap.Ginzap(facades.Logger, time.RFC3339, true))
|
||||
facade.Router.Use(ginzap.Ginzap(facade.Logger, time.RFC3339, true))
|
||||
|
||||
InitApiRoutes()
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package helpers
|
||||
package helper
|
||||
|
||||
func Offset(page int, pageSize int) int {
|
||||
offset := (page - 1) * pageSize
|
@ -1,4 +1,4 @@
|
||||
package helpers
|
||||
package helper
|
||||
|
||||
import (
|
||||
"framework_v2/internal/app/response"
|
@ -1,7 +1,7 @@
|
||||
package logger
|
||||
|
||||
import (
|
||||
"framework_v2/internal/app/facades"
|
||||
"framework_v2/internal/app/facade"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@ -19,5 +19,5 @@ func InitLogger() {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
facades.Logger = Logger
|
||||
facade.Logger = Logger
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package redis
|
||||
import "C"
|
||||
import (
|
||||
"framework_v2/internal/app/config"
|
||||
"framework_v2/internal/app/facades"
|
||||
"framework_v2/internal/app/facade"
|
||||
"github.com/redis/go-redis/v9"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
@ -25,5 +25,5 @@ func InitRedis() {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
facades.Redis = Redis
|
||||
facade.Redis = Redis
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ package s3
|
||||
|
||||
import (
|
||||
"framework_v2/internal/app/config"
|
||||
"framework_v2/internal/app/facades"
|
||||
"framework_v2/internal/app/facade"
|
||||
"github.com/minio/minio-go/v7"
|
||||
"github.com/minio/minio-go/v7/pkg/credentials"
|
||||
"log"
|
||||
@ -10,7 +10,7 @@ import (
|
||||
|
||||
func InitS3Driver() {
|
||||
var err error
|
||||
facades.S3, err = minio.New(config.Config.S3.Endpoint, &minio.Options{
|
||||
facade.S3, err = minio.New(config.Config.S3.Endpoint, &minio.Options{
|
||||
Creds: credentials.NewStaticV4(config.Config.S3.AccessKeyID, config.Config.S3.SecretAccessKey, ""),
|
||||
Secure: config.Config.S3.UseSSL,
|
||||
})
|
||||
@ -19,5 +19,5 @@ func InitS3Driver() {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
log.Printf("%#v\n", facades.S3)
|
||||
log.Printf("%#v\n", facade.S3)
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ package cmd
|
||||
|
||||
import (
|
||||
"framework_v2/internal/app/config"
|
||||
"framework_v2/internal/app/facades"
|
||||
"framework_v2/internal/app/facade"
|
||||
"framework_v2/internal/app/gin"
|
||||
"framework_v2/internal/app/jobs"
|
||||
"framework_v2/internal/app/jwks"
|
||||
@ -35,7 +35,7 @@ func StartHttp() {
|
||||
}
|
||||
|
||||
logger.Logger.Info("Http Server listening at " + config.Config.ListenAddr.HTTP)
|
||||
err := facades.Router.Run(config.Config.ListenAddr.HTTP)
|
||||
err := facade.Router.Run(config.Config.ListenAddr.HTTP)
|
||||
if err != nil {
|
||||
panic("failed to listen: " + err.Error())
|
||||
}
|
||||
|
@ -4,8 +4,8 @@ import (
|
||||
"errors"
|
||||
"framework_v2/internal/app/auth"
|
||||
"framework_v2/internal/app/config"
|
||||
"framework_v2/internal/app/facades"
|
||||
"framework_v2/internal/app/helpers"
|
||||
"framework_v2/internal/app/facade"
|
||||
"framework_v2/internal/app/helper"
|
||||
"framework_v2/internal/app/jwks"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
@ -34,36 +34,36 @@ func DIJWTAuth(c *gin.Context) *auth.User {
|
||||
authorization := c.Request.Header.Get("Authorization")
|
||||
|
||||
if authorization == "" {
|
||||
helpers.ResponseError(c, http.StatusUnauthorized, ErrJWTFormatError)
|
||||
helper.ResponseError(c, http.StatusUnauthorized, ErrJWTFormatError)
|
||||
return nil
|
||||
}
|
||||
|
||||
authSplit := strings.Split(authorization, " ")
|
||||
if len(authSplit) != 2 {
|
||||
helpers.ResponseError(c, http.StatusUnauthorized, ErrJWTFormatError)
|
||||
helper.ResponseError(c, http.StatusUnauthorized, ErrJWTFormatError)
|
||||
return nil
|
||||
}
|
||||
|
||||
if authSplit[0] != "Bearer" {
|
||||
helpers.ResponseError(c, http.StatusUnauthorized, ErrNotBearerType)
|
||||
helper.ResponseError(c, http.StatusUnauthorized, ErrNotBearerType)
|
||||
return nil
|
||||
}
|
||||
|
||||
token, err := jwks.ParseJWT(authSplit[1])
|
||||
if err != nil {
|
||||
helpers.ResponseError(c, http.StatusUnauthorized, ErrJWTFormatError)
|
||||
helper.ResponseError(c, http.StatusUnauthorized, ErrJWTFormatError)
|
||||
return nil
|
||||
}
|
||||
sub, err = token.Claims.GetSubject()
|
||||
if err != nil {
|
||||
helpers.ResponseError(c, http.StatusUnauthorized, ErrNotValidToken)
|
||||
helper.ResponseError(c, http.StatusUnauthorized, ErrNotValidToken)
|
||||
return nil
|
||||
}
|
||||
|
||||
err = mapstructure.Decode(token.Claims, &jwtIdToken.Token)
|
||||
if err != nil {
|
||||
facades.Logger.Error("Failed to map token claims to JwtIDToken struct.\nError: " + err.Error())
|
||||
helpers.ResponseError(c, http.StatusUnauthorized, ErrNotValidToken)
|
||||
facade.Logger.Error("Failed to map token claims to JwtIDToken struct.\nError: " + err.Error())
|
||||
helper.ResponseError(c, http.StatusUnauthorized, ErrNotValidToken)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user