update package name

This commit is contained in:
ivamp 2024-06-16 14:16:59 +08:00
parent 8a3c5050ac
commit 7e63a420b8
10 changed files with 34 additions and 34 deletions

View File

@ -1,4 +1,4 @@
package facades package facade
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"

View File

@ -3,8 +3,8 @@ package gin
import ( import (
"fmt" "fmt"
"framework_v2/internal/app/auth" "framework_v2/internal/app/auth"
"framework_v2/internal/app/facades" "framework_v2/internal/app/facade"
"framework_v2/internal/app/helpers" "framework_v2/internal/app/helper"
http2 "framework_v2/internal/middleware/http" http2 "framework_v2/internal/middleware/http"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"net/http" "net/http"
@ -12,31 +12,31 @@ import (
) )
func GET(relativePath string, handlers ...interface{}) { 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...) doHandler(c, handlers...)
}) })
} }
func POST(relativePath string, handlers ...interface{}) { 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...) doHandler(c, handlers...)
}) })
} }
func PUT(relativePath string, handlers ...interface{}) { 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...) doHandler(c, handlers...)
}) })
} }
func PATCH(relativePath string, handlers ...interface{}) { 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...) doHandler(c, handlers...)
}) })
} }
func DELETE(relativePath string, handlers ...interface{}) { 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...) doHandler(c, handlers...)
}) })
} }
@ -48,7 +48,7 @@ func doHandler(c *gin.Context, handlers ...interface{}) {
if c.Writer.Written() { if c.Writer.Written() {
return return
} else { } else {
helpers.ResponseError(c, http.StatusBadRequest, http2.ErrEmptyResponse) helper.ResponseError(c, http.StatusBadRequest, http2.ErrEmptyResponse)
} }
return return
@ -74,12 +74,12 @@ func wrapHandler(c *gin.Context, f interface{}) {
case reflect.TypeOf((*auth.User)(nil)): case reflect.TypeOf((*auth.User)(nil)):
userInfo := http2.DIJWTAuth(c) userInfo := http2.DIJWTAuth(c)
if userInfo == nil { if userInfo == nil {
helpers.ResponseError(c, http.StatusUnauthorized, http2.ErrNotValidToken) helper.ResponseError(c, http.StatusUnauthorized, http2.ErrNotValidToken)
return return
} }
argValue = reflect.ValueOf(userInfo) argValue = reflect.ValueOf(userInfo)
default: 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 return
} }

View File

@ -1,7 +1,7 @@
package gin package gin
import ( import (
"framework_v2/internal/app/facades" "framework_v2/internal/app/facade"
"framework_v2/internal/http/controllers/user" "framework_v2/internal/http/controllers/user"
"framework_v2/internal/middleware/http" "framework_v2/internal/middleware/http"
ginzap "github.com/gin-contrib/zap" ginzap "github.com/gin-contrib/zap"
@ -12,9 +12,9 @@ import (
func InitGin() { func InitGin() {
gin.SetMode(gin.ReleaseMode) 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() InitApiRoutes()
} }

View File

@ -1,4 +1,4 @@
package helpers package helper
func Offset(page int, pageSize int) int { func Offset(page int, pageSize int) int {
offset := (page - 1) * pageSize offset := (page - 1) * pageSize

View File

@ -1,4 +1,4 @@
package helpers package helper
import ( import (
"framework_v2/internal/app/response" "framework_v2/internal/app/response"

View File

@ -1,7 +1,7 @@
package logger package logger
import ( import (
"framework_v2/internal/app/facades" "framework_v2/internal/app/facade"
"go.uber.org/zap" "go.uber.org/zap"
) )
@ -19,5 +19,5 @@ func InitLogger() {
panic(err) panic(err)
} }
facades.Logger = Logger facade.Logger = Logger
} }

View File

@ -3,7 +3,7 @@ package redis
import "C" import "C"
import ( import (
"framework_v2/internal/app/config" "framework_v2/internal/app/config"
"framework_v2/internal/app/facades" "framework_v2/internal/app/facade"
"github.com/redis/go-redis/v9" "github.com/redis/go-redis/v9"
"golang.org/x/net/context" "golang.org/x/net/context"
) )
@ -25,5 +25,5 @@ func InitRedis() {
panic(err) panic(err)
} }
facades.Redis = Redis facade.Redis = Redis
} }

View File

@ -2,7 +2,7 @@ package s3
import ( import (
"framework_v2/internal/app/config" "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"
"github.com/minio/minio-go/v7/pkg/credentials" "github.com/minio/minio-go/v7/pkg/credentials"
"log" "log"
@ -10,7 +10,7 @@ import (
func InitS3Driver() { func InitS3Driver() {
var err error 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, ""), Creds: credentials.NewStaticV4(config.Config.S3.AccessKeyID, config.Config.S3.SecretAccessKey, ""),
Secure: config.Config.S3.UseSSL, Secure: config.Config.S3.UseSSL,
}) })
@ -19,5 +19,5 @@ func InitS3Driver() {
panic(err) panic(err)
} }
log.Printf("%#v\n", facades.S3) log.Printf("%#v\n", facade.S3)
} }

View File

@ -2,7 +2,7 @@ package cmd
import ( import (
"framework_v2/internal/app/config" "framework_v2/internal/app/config"
"framework_v2/internal/app/facades" "framework_v2/internal/app/facade"
"framework_v2/internal/app/gin" "framework_v2/internal/app/gin"
"framework_v2/internal/app/jobs" "framework_v2/internal/app/jobs"
"framework_v2/internal/app/jwks" "framework_v2/internal/app/jwks"
@ -35,7 +35,7 @@ func StartHttp() {
} }
logger.Logger.Info("Http Server listening at " + config.Config.ListenAddr.HTTP) 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 { if err != nil {
panic("failed to listen: " + err.Error()) panic("failed to listen: " + err.Error())
} }

View File

@ -4,8 +4,8 @@ import (
"errors" "errors"
"framework_v2/internal/app/auth" "framework_v2/internal/app/auth"
"framework_v2/internal/app/config" "framework_v2/internal/app/config"
"framework_v2/internal/app/facades" "framework_v2/internal/app/facade"
"framework_v2/internal/app/helpers" "framework_v2/internal/app/helper"
"framework_v2/internal/app/jwks" "framework_v2/internal/app/jwks"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/mitchellh/mapstructure" "github.com/mitchellh/mapstructure"
@ -34,36 +34,36 @@ func DIJWTAuth(c *gin.Context) *auth.User {
authorization := c.Request.Header.Get("Authorization") authorization := c.Request.Header.Get("Authorization")
if authorization == "" { if authorization == "" {
helpers.ResponseError(c, http.StatusUnauthorized, ErrJWTFormatError) helper.ResponseError(c, http.StatusUnauthorized, ErrJWTFormatError)
return nil return nil
} }
authSplit := strings.Split(authorization, " ") authSplit := strings.Split(authorization, " ")
if len(authSplit) != 2 { if len(authSplit) != 2 {
helpers.ResponseError(c, http.StatusUnauthorized, ErrJWTFormatError) helper.ResponseError(c, http.StatusUnauthorized, ErrJWTFormatError)
return nil return nil
} }
if authSplit[0] != "Bearer" { if authSplit[0] != "Bearer" {
helpers.ResponseError(c, http.StatusUnauthorized, ErrNotBearerType) helper.ResponseError(c, http.StatusUnauthorized, ErrNotBearerType)
return nil return nil
} }
token, err := jwks.ParseJWT(authSplit[1]) token, err := jwks.ParseJWT(authSplit[1])
if err != nil { if err != nil {
helpers.ResponseError(c, http.StatusUnauthorized, ErrJWTFormatError) helper.ResponseError(c, http.StatusUnauthorized, ErrJWTFormatError)
return nil return nil
} }
sub, err = token.Claims.GetSubject() sub, err = token.Claims.GetSubject()
if err != nil { if err != nil {
helpers.ResponseError(c, http.StatusUnauthorized, ErrNotValidToken) helper.ResponseError(c, http.StatusUnauthorized, ErrNotValidToken)
return nil return nil
} }
err = mapstructure.Decode(token.Claims, &jwtIdToken.Token) err = mapstructure.Decode(token.Claims, &jwtIdToken.Token)
if err != nil { if err != nil {
facades.Logger.Error("Failed to map token claims to JwtIDToken struct.\nError: " + err.Error()) facade.Logger.Error("Failed to map token claims to JwtIDToken struct.\nError: " + err.Error())
helpers.ResponseError(c, http.StatusUnauthorized, ErrNotValidToken) helper.ResponseError(c, http.StatusUnauthorized, ErrNotValidToken)
return nil return nil
} }
} }