提交 c4783e62 authored 作者: mooncake9527's avatar mooncake9527

change dir

上级 b9c4159d
package application
import (
"context"
"time"
"gitlab.wanzhuangkj.com/tush/xpkg/database"
"gitlab.wanzhuangkj.com/tush/xpkg/config"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/app"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/tracer"
)
func Close(servers []app.IServer) []app.Close {
var closes []app.Close
for _, s := range servers {
closes = append(closes, s.Stop)
}
closes = append(closes, func() error {
return database.CloseDB()
})
cacheType := ""
config.Read(func(c *config.Config) {
cacheType = c.App.CacheType
})
if cacheType == "redis" {
closes = append(closes, func() error {
return database.CloseRedis()
})
}
enableTrace := false
config.Read(func(c *config.Config) {
enableTrace = c.App.Middleware.Trace.Enable
})
if enableTrace {
closes = append(closes, func() error {
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) //nolint
defer cancel()
return tracer.Close(ctx)
})
}
closes = append(closes, func() error {
return logger.Sync()
})
return closes
}
package application
import (
"net/http"
"strconv"
"gitlab.wanzhuangkj.com/tush/xpkg/config"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/app"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/server"
)
func CreateServices(handler http.Handler) []app.IServer {
port := 8080
config.Read(func(c *config.Config) {
port = c.HTTP.Port
})
var servers []app.IServer
httpAddr := ":" + strconv.Itoa(port)
httpServer := server.NewHTTPServer(httpAddr, handler)
servers = append(servers, httpServer)
return servers
}
package xpkg package application
import ( import (
"context" "context"
"fmt" "fmt"
"os" "os"
"runtime"
"strconv" "strconv"
"github.com/gin-gonic/gin"
"github.com/jinzhu/copier" "github.com/jinzhu/copier"
"gitlab.wanzhuangkj.com/tush/xpkg/config" "gitlab.wanzhuangkj.com/tush/xpkg/config"
"gitlab.wanzhuangkj.com/tush/xpkg/database" "gitlab.wanzhuangkj.com/tush/xpkg/database"
"gitlab.wanzhuangkj.com/tush/xpkg/eventbus"
"gitlab.wanzhuangkj.com/tush/xpkg/global" "gitlab.wanzhuangkj.com/tush/xpkg/global"
"gitlab.wanzhuangkj.com/tush/xpkg/ips" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/eventbus"
"gitlab.wanzhuangkj.com/tush/xpkg/logger" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/ips"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/stat"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/tracer"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
"gitlab.wanzhuangkj.com/tush/xpkg/rd/nacos" "gitlab.wanzhuangkj.com/tush/xpkg/rd/nacos"
"gitlab.wanzhuangkj.com/tush/xpkg/stat"
"gitlab.wanzhuangkj.com/tush/xpkg/tracer"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/dxsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/dxsf"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/xerrors/xerror"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/app"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
) )
func init() { func parseInit() {
if confType, ok := os.LookupEnv("CONF_TYPE"); (ok && sliceUtils.NotContains([]string{"local", "nacos", "consul"}, confType)) || !ok { if confType, ok := os.LookupEnv("CONF_TYPE"); (ok && sliceUtils.NotContains([]string{"local", "nacos", "consul"}, confType)) || !ok {
return return
} }
if err := config.Parse(); err != nil { if err := config.ParseConf(); err != nil {
logger.Fatal(err.Error()) fmt.Println(err.Error())
} }
logger.Info("[conf] parse conf finish.")
if err := xsf.Init(); err != nil { if err := xsf.Init(); err != nil {
logger.Fatal(err.Error()) logger.Fatal(err.Error())
} }
logger.Info("[xsf] initialized.")
if err := dxsf.Init(); err != nil { if err := dxsf.Init(); err != nil {
logger.Fatal(err.Error()) logger.Fatal(err.Error())
} }
if err := Init(); err != nil { logger.Info("[dxsf] initialized.")
if err := initOthers(); err != nil {
logger.Fatal(err.Error()) logger.Fatal(err.Error())
} }
} }
func Init() (err error) { type Application struct {
app *app.App
h func() *gin.Engine
}
func (x *Application) Run() {
defer Recover()
parseInit()
services := CreateServices(x.h())
closes := Close(services)
x.app = app.New(services, closes)
x.app.Run()
}
func Recover() {
if r := recover(); r != nil {
pc, file, line, _ := runtime.Caller(3)
logger.Fatalf("recovered panic at %s[%s:%d]: %v\n", runtime.FuncForPC(pc).Name(), file, line, r)
}
}
func New(h func() *gin.Engine) *Application {
return &Application{
h: h,
}
}
// init logger,trace,stat,database,cache,rd...
func initOthers() (err error) {
conf := config.Cfg conf := config.Cfg
if err := initLogger(conf); err != nil { if err := initLogger(conf); err != nil {
return err return err
...@@ -73,13 +108,14 @@ func Init() (err error) { ...@@ -73,13 +108,14 @@ func Init() (err error) {
database.InitCache(conf.App.CacheType) database.InitCache(conf.App.CacheType)
eventbus.Eb.Publish(ctx, eventbus.TopicCacheInitFinish) eventbus.Eb.Publish(ctx, eventbus.TopicCacheInitFinish)
if conf.App.CacheType != "" { if conf.App.CacheType != "" {
logger.Info(fmt.Sprintf("[%s] initialized", conf.App.CacheType)) logger.Info(fmt.Sprintf("[cache-%s] initialized", conf.App.CacheType))
} }
rdt := conf.App.RegistryDiscoveryType rdt := conf.App.RegistryDiscoveryType
if rdt == "nacos" { if rdt == "nacos" {
if err := nacosRegisterInstance(); err != nil { if err := nacosRegisterInstance(); err != nil {
return err return err
} }
logger.Info("[rd] initialized.")
} }
eventbus.Eb.Publish(ctx, eventbus.TopicCoreInitFinish) eventbus.Eb.Publish(ctx, eventbus.TopicCoreInitFinish)
return nil return nil
......
...@@ -6,7 +6,7 @@ import ( ...@@ -6,7 +6,7 @@ import (
"time" "time"
"github.com/jinzhu/copier" "github.com/jinzhu/copier"
"gitlab.wanzhuangkj.com/tush/xpkg/third/oss" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/oss"
) )
var Cfg = &Config{ var Cfg = &Config{
......
...@@ -7,9 +7,9 @@ import ( ...@@ -7,9 +7,9 @@ import (
"github.com/hashicorp/consul/api" "github.com/hashicorp/consul/api"
"github.com/spf13/viper" "github.com/spf13/viper"
"gitlab.wanzhuangkj.com/tush/xpkg/logger" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/hashUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/hashUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/xerrors/xerror"
) )
type ConsulConfFetcher struct { type ConsulConfFetcher struct {
......
...@@ -8,8 +8,8 @@ import ( ...@@ -8,8 +8,8 @@ import (
"github.com/spf13/cast" "github.com/spf13/cast"
"github.com/spf13/viper" "github.com/spf13/viper"
"gitlab.wanzhuangkj.com/tush/xpkg/eventbus" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/eventbus"
"gitlab.wanzhuangkj.com/tush/xpkg/logger" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
) )
var ( var (
...@@ -21,7 +21,7 @@ type IExtend interface { ...@@ -21,7 +21,7 @@ type IExtend interface {
Unlock() Unlock()
} }
func Parse() (err error) { func ParseConf() (err error) {
if hostname := os.Getenv("HOSTNAME"); hostname != "" { if hostname := os.Getenv("HOSTNAME"); hostname != "" {
Cfg.App.PodName = hostname Cfg.App.PodName = hostname
} }
......
...@@ -11,7 +11,7 @@ import ( ...@@ -11,7 +11,7 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"gitlab.wanzhuangkj.com/tush/xpkg/xerrors/xerror" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
"github.com/fsnotify/fsnotify" "github.com/fsnotify/fsnotify"
"github.com/spf13/viper" "github.com/spf13/viper"
......
...@@ -7,8 +7,8 @@ import ( ...@@ -7,8 +7,8 @@ import (
"github.com/nacos-group/nacos-sdk-go/clients/config_client" "github.com/nacos-group/nacos-sdk-go/clients/config_client"
"github.com/nacos-group/nacos-sdk-go/common/constant" "github.com/nacos-group/nacos-sdk-go/common/constant"
"github.com/nacos-group/nacos-sdk-go/vo" "github.com/nacos-group/nacos-sdk-go/vo"
"gitlab.wanzhuangkj.com/tush/xpkg/logger" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
"gitlab.wanzhuangkj.com/tush/xpkg/xerrors/xerror" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
"go.uber.org/zap" "go.uber.org/zap"
) )
......
...@@ -5,8 +5,8 @@ import ( ...@@ -5,8 +5,8 @@ import (
"strings" "strings"
"gitlab.wanzhuangkj.com/tush/xpkg/config" "gitlab.wanzhuangkj.com/tush/xpkg/config"
"gitlab.wanzhuangkj.com/tush/xpkg/sgorm" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/sgorm"
"gitlab.wanzhuangkj.com/tush/xpkg/xerrors/xerror" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
) )
var ( var (
......
...@@ -6,9 +6,9 @@ import ( ...@@ -6,9 +6,9 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/config" "gitlab.wanzhuangkj.com/tush/xpkg/config"
"gitlab.wanzhuangkj.com/tush/xpkg/logger" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
"gitlab.wanzhuangkj.com/tush/xpkg/sgorm" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/sgorm"
"gitlab.wanzhuangkj.com/tush/xpkg/sgorm/mysql" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/sgorm/mysql"
"gitlab.wanzhuangkj.com/tush/xpkg/utils" "gitlab.wanzhuangkj.com/tush/xpkg/utils"
) )
......
...@@ -7,9 +7,9 @@ import ( ...@@ -7,9 +7,9 @@ import (
"github.com/dgraph-io/ristretto" "github.com/dgraph-io/ristretto"
"github.com/jinzhu/copier" "github.com/jinzhu/copier"
"gitlab.wanzhuangkj.com/tush/xpkg/config" "gitlab.wanzhuangkj.com/tush/xpkg/config"
"gitlab.wanzhuangkj.com/tush/xpkg/goredis" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/goredis"
"gitlab.wanzhuangkj.com/tush/xpkg/logger" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
"gitlab.wanzhuangkj.com/tush/xpkg/tracer" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/tracer"
) )
var ( var (
......
...@@ -9,7 +9,7 @@ import ( ...@@ -9,7 +9,7 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"gitlab.wanzhuangkj.com/tush/xpkg/errcode" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/errcode"
"gitlab.wanzhuangkj.com/tush/xpkg/utils" "gitlab.wanzhuangkj.com/tush/xpkg/utils"
) )
......
...@@ -3,10 +3,10 @@ package middleware ...@@ -3,10 +3,10 @@ package middleware
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"gitlab.wanzhuangkj.com/tush/xpkg/errcode"
"gitlab.wanzhuangkj.com/tush/xpkg/gin/response" "gitlab.wanzhuangkj.com/tush/xpkg/gin/response"
"gitlab.wanzhuangkj.com/tush/xpkg/jwt" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/errcode"
"gitlab.wanzhuangkj.com/tush/xpkg/logger" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/jwt"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
) )
...@@ -110,6 +110,17 @@ func Auth(opts ...JwtOption) gin.HandlerFunc { ...@@ -110,6 +110,17 @@ func Auth(opts ...JwtOption) gin.HandlerFunc {
} }
} }
func JwtFields() gin.HandlerFunc {
return func(c *gin.Context) {
params := c.Request.URL.Query()
for key, values := range params {
if len(values) > 0 {
c.Set(key, values[0])
}
}
}
}
// ------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------
// VerifyCustomFn verify custom function, tokenTail10 is the last 10 characters of the token. // VerifyCustomFn verify custom function, tokenTail10 is the last 10 characters of the token.
......
...@@ -5,9 +5,9 @@ import ( ...@@ -5,9 +5,9 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"gitlab.wanzhuangkj.com/tush/xpkg/container/group"
"gitlab.wanzhuangkj.com/tush/xpkg/gin/response" "gitlab.wanzhuangkj.com/tush/xpkg/gin/response"
"gitlab.wanzhuangkj.com/tush/xpkg/shield/circuitbreaker" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/container/group"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/shield/circuitbreaker"
) )
// ErrNotAllowed error not allowed. // ErrNotAllowed error not allowed.
......
...@@ -11,10 +11,10 @@ import ( ...@@ -11,10 +11,10 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"gitlab.wanzhuangkj.com/tush/xpkg/container/group"
"gitlab.wanzhuangkj.com/tush/xpkg/gin/response" "gitlab.wanzhuangkj.com/tush/xpkg/gin/response"
"gitlab.wanzhuangkj.com/tush/xpkg/httpcli" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/container/group"
"gitlab.wanzhuangkj.com/tush/xpkg/shield/circuitbreaker" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/httpcli"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/shield/circuitbreaker"
"gitlab.wanzhuangkj.com/tush/xpkg/utils" "gitlab.wanzhuangkj.com/tush/xpkg/utils"
) )
......
...@@ -2,13 +2,14 @@ package middleware ...@@ -2,13 +2,14 @@ package middleware
import ( import (
"bytes" "bytes"
"gitlab.wanzhuangkj.com/tush/xpkg/httpcli/entity"
"io" "io"
"net/http" "net/http"
"strings" "strings"
"time" "time"
"gitlab.wanzhuangkj.com/tush/xpkg/ips" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/httpcli/entity"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/ips"
ctxUtils "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils" ctxUtils "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
......
...@@ -8,8 +8,8 @@ import ( ...@@ -8,8 +8,8 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"gitlab.wanzhuangkj.com/tush/xpkg/gin/response" "gitlab.wanzhuangkj.com/tush/xpkg/gin/response"
"gitlab.wanzhuangkj.com/tush/xpkg/httpcli" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/httpcli"
"gitlab.wanzhuangkj.com/tush/xpkg/logger" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
"gitlab.wanzhuangkj.com/tush/xpkg/utils" "gitlab.wanzhuangkj.com/tush/xpkg/utils"
ctxUtil "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils" ctxUtil "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils"
) )
......
package middleware
import (
"net/http"
"time"
"github.com/gin-gonic/gin"
"github.com/redis/go-redis/v9"
"gitlab.wanzhuangkj.com/tush/xpkg/gin/middleware/ratelimiter"
srl "gitlab.wanzhuangkj.com/tush/xpkg/gin/middleware/sync_ratelimiter"
"gitlab.wanzhuangkj.com/tush/xpkg/gin/response"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/errcode"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/ips"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils"
)
func IPRateLimiter(windowSize time.Duration, maxRequests int) func(c *gin.Context) {
rl := ratelimiter.NewIPRateLimiter(windowSize, maxRequests)
return func(c *gin.Context) {
clientIP := ips.GetClientIP(c)
if rl.Allow(clientIP) {
c.Next()
} else {
Fail(c, errcode.TooManyRequests.Code(), errcode.TooManyRequests.Msg())
}
}
}
func SyncIPRateLimiter(windowSize time.Duration, maxRequests int64, cli redis.Cmdable) func(c *gin.Context) {
rl := srl.NewIPRateLimiter(
srl.WithWindowSize(windowSize),
srl.WithMaxRequests(maxRequests),
srl.WithLogger(logger.Get()),
srl.WithRedisCli(cli),
)
return func(c *gin.Context) {
clientIP := ips.GetClientIP(c)
ctx := ctxUtils.WrapCtx(c)
if rl.Allow(ctx, clientIP) {
c.Next()
} else {
Fail(c, errcode.TooManyRequests.Code(), errcode.TooManyRequests.Msg())
}
}
}
func Fail(c *gin.Context, code int, msg string, data ...any) {
c.AbortWithStatusJSON(http.StatusOK, response.Result{Code: code, Msg: msg, Data: nil, TimeStamp: time.Now().Unix(), TraceID: ctxUtils.GetGinCtxTid(c)})
}
...@@ -8,7 +8,7 @@ import ( ...@@ -8,7 +8,7 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"gitlab.wanzhuangkj.com/tush/xpkg/gin/response" "gitlab.wanzhuangkj.com/tush/xpkg/gin/response"
rl "gitlab.wanzhuangkj.com/tush/xpkg/shield/ratelimit" rl "gitlab.wanzhuangkj.com/tush/xpkg/pkg/shield/ratelimit"
) )
// ErrLimitExceed is returned when the rate limiter is // ErrLimitExceed is returned when the rate limiter is
......
...@@ -12,7 +12,7 @@ import ( ...@@ -12,7 +12,7 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"gitlab.wanzhuangkj.com/tush/xpkg/gin/response" "gitlab.wanzhuangkj.com/tush/xpkg/gin/response"
"gitlab.wanzhuangkj.com/tush/xpkg/httpcli" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/httpcli"
"gitlab.wanzhuangkj.com/tush/xpkg/utils" "gitlab.wanzhuangkj.com/tush/xpkg/utils"
) )
......
...@@ -6,7 +6,7 @@ import ( ...@@ -6,7 +6,7 @@ import (
"time" "time"
"gitlab.wanzhuangkj.com/tush/xpkg/gin/response" "gitlab.wanzhuangkj.com/tush/xpkg/gin/response"
"gitlab.wanzhuangkj.com/tush/xpkg/httpcli" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/httpcli"
"gitlab.wanzhuangkj.com/tush/xpkg/utils" "gitlab.wanzhuangkj.com/tush/xpkg/utils"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
......
...@@ -8,14 +8,14 @@ import ( ...@@ -8,14 +8,14 @@ import (
"strconv" "strconv"
"time" "time"
"gitlab.wanzhuangkj.com/tush/xpkg/httpcli/entity" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/httpcli/entity"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"gitlab.wanzhuangkj.com/tush/xpkg/errcode" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/errcode"
"gitlab.wanzhuangkj.com/tush/xpkg/logger" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
ctxUtils "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils" ctxUtils "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/xerrors/xerror"
) )
const CustomErrorCode = 0 const CustomErrorCode = 0
......
...@@ -10,8 +10,8 @@ import ( ...@@ -10,8 +10,8 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"gitlab.wanzhuangkj.com/tush/xpkg/errcode" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/errcode"
"gitlab.wanzhuangkj.com/tush/xpkg/httpcli" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/httpcli"
"gitlab.wanzhuangkj.com/tush/xpkg/utils" "gitlab.wanzhuangkj.com/tush/xpkg/utils"
) )
......
...@@ -11,7 +11,7 @@ import ( ...@@ -11,7 +11,7 @@ import (
ginSwagger "github.com/swaggo/gin-swagger" ginSwagger "github.com/swaggo/gin-swagger"
"github.com/swaggo/swag" "github.com/swaggo/swag"
"gitlab.wanzhuangkj.com/tush/xpkg/gofile" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/gofile"
) )
// DefaultRouter default swagger router, request url is http://<ip:port>/swagger/index.html // DefaultRouter default swagger router, request url is http://<ip:port>/swagger/index.html
......
...@@ -12,16 +12,16 @@ import ( ...@@ -12,16 +12,16 @@ import (
ginSwagger "github.com/swaggo/gin-swagger" ginSwagger "github.com/swaggo/gin-swagger"
"gitlab.wanzhuangkj.com/tush/xpkg/config" "gitlab.wanzhuangkj.com/tush/xpkg/config"
"gitlab.wanzhuangkj.com/tush/xpkg/consts" "gitlab.wanzhuangkj.com/tush/xpkg/consts"
"gitlab.wanzhuangkj.com/tush/xpkg/errcode"
"gitlab.wanzhuangkj.com/tush/xpkg/gin/handlerfunc" "gitlab.wanzhuangkj.com/tush/xpkg/gin/handlerfunc"
"gitlab.wanzhuangkj.com/tush/xpkg/gin/middleware" "gitlab.wanzhuangkj.com/tush/xpkg/gin/middleware"
"gitlab.wanzhuangkj.com/tush/xpkg/gin/middleware/metrics" "gitlab.wanzhuangkj.com/tush/xpkg/gin/middleware/metrics"
"gitlab.wanzhuangkj.com/tush/xpkg/gin/prof" "gitlab.wanzhuangkj.com/tush/xpkg/gin/prof"
"gitlab.wanzhuangkj.com/tush/xpkg/gin/validator" "gitlab.wanzhuangkj.com/tush/xpkg/gin/validator"
"gitlab.wanzhuangkj.com/tush/xpkg/ips" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/errcode"
"gitlab.wanzhuangkj.com/tush/xpkg/jwt" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/ips"
"gitlab.wanzhuangkj.com/tush/xpkg/logger" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/jwt"
"gitlab.wanzhuangkj.com/tush/xpkg/text" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/text"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/webLogUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/webLogUtils"
xvalidator "gitlab.wanzhuangkj.com/tush/xpkg/xcommon/validator" xvalidator "gitlab.wanzhuangkj.com/tush/xpkg/xcommon/validator"
) )
......
...@@ -10,9 +10,9 @@ import ( ...@@ -10,9 +10,9 @@ import (
"golang.org/x/sync/errgroup" "golang.org/x/sync/errgroup"
"gitlab.wanzhuangkj.com/tush/xpkg/prof" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/prof"
xlogger "gitlab.wanzhuangkj.com/tush/xpkg/logger" xlogger "gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
) )
// IServer server interface // IServer server interface
......
...@@ -6,8 +6,8 @@ import ( ...@@ -6,8 +6,8 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"gitlab.wanzhuangkj.com/tush/xpkg/encoding" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/encoding"
"gitlab.wanzhuangkj.com/tush/xpkg/gotest" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/gotest"
"gitlab.wanzhuangkj.com/tush/xpkg/utils" "gitlab.wanzhuangkj.com/tush/xpkg/utils"
) )
......
...@@ -10,11 +10,11 @@ import ( ...@@ -10,11 +10,11 @@ import (
"github.com/dgraph-io/ristretto" "github.com/dgraph-io/ristretto"
"github.com/spf13/cast" "github.com/spf13/cast"
"gitlab.wanzhuangkj.com/tush/xpkg/encoding" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/encoding"
"gitlab.wanzhuangkj.com/tush/xpkg/logger" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
ctxUtil "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils" ctxUtil "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils"
xslice "gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceUtils" xslice "gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/xerrors/xerror"
) )
type memoryCache struct { type memoryCache struct {
......
...@@ -6,7 +6,7 @@ import ( ...@@ -6,7 +6,7 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"gitlab.wanzhuangkj.com/tush/xpkg/gotest" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/gotest"
"gitlab.wanzhuangkj.com/tush/xpkg/utils" "gitlab.wanzhuangkj.com/tush/xpkg/utils"
) )
......
...@@ -10,8 +10,8 @@ import ( ...@@ -10,8 +10,8 @@ import (
"github.com/redis/go-redis/v9" "github.com/redis/go-redis/v9"
"gitlab.wanzhuangkj.com/tush/xpkg/encoding" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/encoding"
"gitlab.wanzhuangkj.com/tush/xpkg/xerrors/xerror" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
) )
// CacheNotFound no hit cache // CacheNotFound no hit cache
......
...@@ -6,8 +6,8 @@ import ( ...@@ -6,8 +6,8 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"gitlab.wanzhuangkj.com/tush/xpkg/encoding" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/encoding"
"gitlab.wanzhuangkj.com/tush/xpkg/gotest" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/gotest"
"gitlab.wanzhuangkj.com/tush/xpkg/utils" "gitlab.wanzhuangkj.com/tush/xpkg/utils"
) )
......
...@@ -7,7 +7,7 @@ import ( ...@@ -7,7 +7,7 @@ import (
"github.com/mojocn/base64Captcha" "github.com/mojocn/base64Captcha"
"github.com/redis/go-redis/v9" "github.com/redis/go-redis/v9"
"gitlab.wanzhuangkj.com/tush/xpkg/xerrors/xerror" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
) )
const ( const (
......
...@@ -4,9 +4,10 @@ import ( ...@@ -4,9 +4,10 @@ import (
"crypto/rand" "crypto/rand"
"crypto/tls" "crypto/tls"
"fmt" "fmt"
"gitlab.wanzhuangkj.com/tush/xpkg/xerrors/xerror"
"math/big" "math/big"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
"gopkg.in/gomail.v2" "gopkg.in/gomail.v2"
) )
......
...@@ -8,7 +8,7 @@ import ( ...@@ -8,7 +8,7 @@ import (
"google.golang.org/protobuf/encoding/protojson" "google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
"gitlab.wanzhuangkj.com/tush/xpkg/encoding" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/encoding"
) )
// Name is the name registered for the json codec. // Name is the name registered for the json codec.
......
...@@ -6,7 +6,7 @@ import ( ...@@ -6,7 +6,7 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
"gitlab.wanzhuangkj.com/tush/xpkg/encoding" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/encoding"
) )
// Name is the name registered for the proto compressor. // Name is the name registered for the proto compressor.
......
...@@ -3,6 +3,7 @@ package eventbus ...@@ -3,6 +3,7 @@ package eventbus
var Eb = New() var Eb = New()
const ( const (
TopicParseConfStart string = "event:application:conf:init:start" // 配置文件解析开始
TopicParseConfFinish string = "event:application:conf:init:finish" // 配置文件解析完毕 TopicParseConfFinish string = "event:application:conf:init:finish" // 配置文件解析完毕
TopicDBInitFinish string = "event:application:database:init:finish" // 数据库连接初始化完成 TopicDBInitFinish string = "event:application:database:init:finish" // 数据库连接初始化完成
TopicCacheInitFinish string = "event:application:cache:init:finish" // cache初始化完成 TopicCacheInitFinish string = "event:application:cache:init:finish" // cache初始化完成
......
...@@ -7,7 +7,7 @@ import ( ...@@ -7,7 +7,7 @@ import (
"runtime" "runtime"
"time" "time"
"gitlab.wanzhuangkj.com/tush/xpkg/logger" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
ctxUtil "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils" ctxUtil "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils"
"github.com/redis/go-redis/v9" "github.com/redis/go-redis/v9"
......
...@@ -9,7 +9,7 @@ import ( ...@@ -9,7 +9,7 @@ import (
"github.com/DATA-DOG/go-sqlmock" "github.com/DATA-DOG/go-sqlmock"
"gorm.io/gorm" "gorm.io/gorm"
"gitlab.wanzhuangkj.com/tush/xpkg/sgorm/query" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/sgorm/query"
) )
func TestNewDao(t *testing.T) { func TestNewDao(t *testing.T) {
......
...@@ -13,12 +13,12 @@ import ( ...@@ -13,12 +13,12 @@ import (
"strings" "strings"
"time" "time"
"gitlab.wanzhuangkj.com/tush/xpkg/httpcli/entity" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/httpcli/entity"
"gitlab.wanzhuangkj.com/tush/xpkg/httpcli/httpContentType" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/httpcli/httpContentType"
"gitlab.wanzhuangkj.com/tush/xpkg/xerrors/xerror" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
"github.com/duke-git/lancet/v2/retry" "github.com/duke-git/lancet/v2/retry"
"gitlab.wanzhuangkj.com/tush/xpkg/logger" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils"
) )
......
...@@ -76,10 +76,10 @@ func Init(opts ...Option) (*zap.Logger, error) { ...@@ -76,10 +76,10 @@ func Init(opts ...Option) (*zap.Logger, error) {
if err != nil { if err != nil {
panic(err) panic(err)
} }
str = fmt.Sprintf("[log]initialize logger finish, config is output to 'terminal', format=%s, level=%s", encoding, levelName) str = fmt.Sprintf("[logger] config is output to 'terminal', format=%s, level=%s", encoding, levelName)
} else { } else {
zapLog = log2File(encoding, levelName, o.fileConfig) zapLog = log2File(encoding, levelName, o.fileConfig)
str = fmt.Sprintf("[log]initialize logger finish, config is output to 'file', format=%s, level=%s, file=%s", encoding, levelName, o.fileConfig.filename) str = fmt.Sprintf("[logger] config is output to 'file', format=%s, level=%s, file=%s", encoding, levelName, o.fileConfig.filename)
} }
if len(o.hooks) > 0 { if len(o.hooks) > 0 {
......
...@@ -4,8 +4,8 @@ import ( ...@@ -4,8 +4,8 @@ import (
"io" "io"
"mime/multipart" "mime/multipart"
"gitlab.wanzhuangkj.com/tush/xpkg/logger" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
"gitlab.wanzhuangkj.com/tush/xpkg/xerrors/xerror" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
"github.com/aliyun/aliyun-oss-go-sdk/oss" "github.com/aliyun/aliyun-oss-go-sdk/oss"
) )
......
package server
import (
"context"
"fmt"
"net/http"
"time"
"github.com/gin-gonic/gin"
"gitlab.wanzhuangkj.com/tush/xpkg/config"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/app"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/text"
)
var _ app.IServer = (*httpServer)(nil)
type httpServer struct {
addr string
server *http.Server
}
func (s *httpServer) Start() error {
if err := s.server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
return fmt.Errorf("listen server error: %v", err)
}
return nil
}
func (s *httpServer) Stop() error {
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) //nolint
defer cancel()
return s.server.Shutdown(ctx)
}
func (s *httpServer) String() string {
var host, name string
var port int
config.Read(func(c *config.Config) {
name = c.App.Name
host = c.App.Host
port = c.HTTP.Port
})
addr := fmt.Sprintf("%s:%d", host, port)
return text.Green(fmt.Sprintf("server[%s] started, listen on: ", name)) + text.Red("[ "+addr+" ]")
}
func NewHTTPServer(addr string, handler http.Handler, opts ...HTTPOption) app.IServer {
o := defaultHTTPOptions()
o.apply(opts...)
if o.isProd {
gin.SetMode(gin.ReleaseMode)
} else {
gin.SetMode(gin.DebugMode)
}
// router := routers.NewRouter()
server := &http.Server{
Addr: addr,
Handler: handler,
MaxHeaderBytes: 1 << 20,
}
return &httpServer{
addr: addr,
server: server,
}
}
package server
// HTTPOption setting up http
type HTTPOption func(*httpOptions)
type httpOptions struct {
isProd bool
}
func defaultHTTPOptions() *httpOptions {
return &httpOptions{
isProd: false,
}
}
func (o *httpOptions) apply(opts ...HTTPOption) {
for _, opt := range opts {
opt(o)
}
}
func WithHTTPIsProd(isProd bool) HTTPOption {
return func(o *httpOptions) {
o.isProd = isProd
}
}
...@@ -8,7 +8,7 @@ import ( ...@@ -8,7 +8,7 @@ import (
"github.com/huandu/xstrings" "github.com/huandu/xstrings"
"gorm.io/gorm" "gorm.io/gorm"
"gitlab.wanzhuangkj.com/tush/xpkg/sgorm/dbclose" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/sgorm/dbclose"
) )
type DB = gorm.DB type DB = gorm.DB
......
...@@ -13,9 +13,9 @@ import ( ...@@ -13,9 +13,9 @@ import (
"gorm.io/gorm/schema" "gorm.io/gorm/schema"
"gorm.io/plugin/dbresolver" "gorm.io/plugin/dbresolver"
"gitlab.wanzhuangkj.com/tush/xpkg/sgorm/dbclose" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/sgorm/dbclose"
"gitlab.wanzhuangkj.com/tush/xpkg/sgorm/glog" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/sgorm/glog"
"gitlab.wanzhuangkj.com/tush/xpkg/xerrors/xerror" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
) )
// Init mysql // Init mysql
......
...@@ -12,8 +12,8 @@ import ( ...@@ -12,8 +12,8 @@ import (
"gorm.io/gorm/logger" "gorm.io/gorm/logger"
"gorm.io/gorm/schema" "gorm.io/gorm/schema"
"gitlab.wanzhuangkj.com/tush/xpkg/sgorm/dbclose" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/sgorm/dbclose"
"gitlab.wanzhuangkj.com/tush/xpkg/sgorm/glog" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/sgorm/glog"
) )
// Init postgresql // Init postgresql
......
...@@ -5,8 +5,8 @@ import ( ...@@ -5,8 +5,8 @@ import (
"fmt" "fmt"
"strings" "strings"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime"
"gitlab.wanzhuangkj.com/tush/xpkg/xerrors/xerror"
) )
const ( const (
......
...@@ -12,8 +12,8 @@ import ( ...@@ -12,8 +12,8 @@ import (
"gorm.io/gorm/logger" "gorm.io/gorm/logger"
"gorm.io/gorm/schema" "gorm.io/gorm/schema"
"gitlab.wanzhuangkj.com/tush/xpkg/sgorm/dbclose" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/sgorm/dbclose"
"gitlab.wanzhuangkj.com/tush/xpkg/sgorm/glog" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/sgorm/glog"
) )
// Init sqlite // Init sqlite
......
...@@ -9,7 +9,7 @@ Circuit Breaker for web middleware and rpc interceptor. ...@@ -9,7 +9,7 @@ Circuit Breaker for web middleware and rpc interceptor.
**gin circuit breaker middleware** **gin circuit breaker middleware**
```go ```go
import "gitlab.wanzhuangkj.com/tush/xpkg/shield/circuitbreaker" import "gitlab.wanzhuangkj.com/tush/xpkg/pkg/shield/circuitbreaker"
// CircuitBreaker a circuit breaker middleware // CircuitBreaker a circuit breaker middleware
func CircuitBreaker(opts ...CircuitBreakerOption) gin.HandlerFunc { func CircuitBreaker(opts ...CircuitBreakerOption) gin.HandlerFunc {
...@@ -45,7 +45,7 @@ func CircuitBreaker(opts ...CircuitBreakerOption) gin.HandlerFunc { ...@@ -45,7 +45,7 @@ func CircuitBreaker(opts ...CircuitBreakerOption) gin.HandlerFunc {
**rpc server circuit breaker interceptor** **rpc server circuit breaker interceptor**
```go ```go
import "gitlab.wanzhuangkj.com/tush/xpkg/shield/circuitbreaker" import "gitlab.wanzhuangkj.com/tush/xpkg/pkg/shield/circuitbreaker"
// UnaryServerCircuitBreaker server-side unary circuit breaker interceptor // UnaryServerCircuitBreaker server-side unary circuit breaker interceptor
func UnaryServerCircuitBreaker(opts ...CircuitBreakerOption) grpc.UnaryServerInterceptor { func UnaryServerCircuitBreaker(opts ...CircuitBreakerOption) grpc.UnaryServerInterceptor {
......
...@@ -3,7 +3,7 @@ package circuitbreaker_test ...@@ -3,7 +3,7 @@ package circuitbreaker_test
import ( import (
"testing" "testing"
"gitlab.wanzhuangkj.com/tush/xpkg/shield/circuitbreaker" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/shield/circuitbreaker"
) )
// This is an example of using a circuit breaker Do() when return nil. // This is an example of using a circuit breaker Do() when return nil.
......
...@@ -7,7 +7,7 @@ import ( ...@@ -7,7 +7,7 @@ import (
"sync/atomic" "sync/atomic"
"time" "time"
"gitlab.wanzhuangkj.com/tush/xpkg/shield/window" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/shield/window"
) )
// Option is sre breaker option function. // Option is sre breaker option function.
......
...@@ -8,7 +8,7 @@ import ( ...@@ -8,7 +8,7 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"gitlab.wanzhuangkj.com/tush/xpkg/shield/window" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/shield/window"
) )
func getSREBreaker() *Breaker { func getSREBreaker() *Breaker {
......
...@@ -7,8 +7,8 @@ import ( ...@@ -7,8 +7,8 @@ import (
"sync/atomic" "sync/atomic"
"time" "time"
"gitlab.wanzhuangkj.com/tush/xpkg/shield/cpu" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/shield/cpu"
"gitlab.wanzhuangkj.com/tush/xpkg/shield/window" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/shield/window"
) )
var ( var (
......
...@@ -9,7 +9,7 @@ import ( ...@@ -9,7 +9,7 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"gitlab.wanzhuangkj.com/tush/xpkg/shield/window" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/shield/window"
) )
var ( var (
......
...@@ -8,8 +8,8 @@ import ( ...@@ -8,8 +8,8 @@ import (
"go.uber.org/zap" "go.uber.org/zap"
"gitlab.wanzhuangkj.com/tush/xpkg/stat/cpu" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/stat/cpu"
"gitlab.wanzhuangkj.com/tush/xpkg/stat/mem" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/stat/mem"
) )
var ( var (
......
...@@ -7,10 +7,10 @@ import ( ...@@ -7,10 +7,10 @@ import (
"sync" "sync"
"time" "time"
"gitlab.wanzhuangkj.com/tush/xpkg/jwt" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/jwt"
"gitlab.wanzhuangkj.com/tush/xpkg/logger" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/xerrors/xerror"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
......
...@@ -3,7 +3,7 @@ package xerror ...@@ -3,7 +3,7 @@ package xerror
import ( import (
"fmt" "fmt"
"gitlab.wanzhuangkj.com/tush/xpkg/xerrors/xcode" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xcode"
) )
// New 用于创建一个自定义文本错误信息的 error 对象,并包含堆栈信息。 // New 用于创建一个自定义文本错误信息的 error 对象,并包含堆栈信息。
......
...@@ -2,8 +2,9 @@ package xerror ...@@ -2,8 +2,9 @@ package xerror
import ( import (
"fmt" "fmt"
"gitlab.wanzhuangkj.com/tush/xpkg/xerrors/xcode"
"strings" "strings"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xcode"
) )
// NewCode 用于创建一个自定义错误信息的 error 对象,并包含堆栈信息,并增加错误码对象的输入。 // NewCode 用于创建一个自定义错误信息的 error 对象,并包含堆栈信息,并增加错误码对象的输入。
......
package xerror package xerror
import "gitlab.wanzhuangkj.com/tush/xpkg/xerrors/xcode" import "gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xcode"
// Code 获取错误码。 // Code 获取错误码。
// 如果没有错误代码,则返回 `xcode.CodeDefault`。 // 如果没有错误代码,则返回 `xcode.CodeDefault`。
......
package xerror_test package xerror_test
import ( import (
"gitlab.wanzhuangkj.com/tush/xpkg/xerrors/xerror"
"testing" "testing"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
......
...@@ -2,8 +2,9 @@ package xerror_test ...@@ -2,8 +2,9 @@ package xerror_test
import ( import (
"fmt" "fmt"
"gitlab.wanzhuangkj.com/tush/xpkg/xerrors/xcode"
"gitlab.wanzhuangkj.com/tush/xpkg/xerrors/xerror" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xcode"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
......
...@@ -3,12 +3,13 @@ package xerror_test ...@@ -3,12 +3,13 @@ package xerror_test
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"gitlab.wanzhuangkj.com/tush/xpkg/xerrors/xcode"
"testing" "testing"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xcode"
"github.com/pkg/errors" "github.com/pkg/errors"
"gitlab.wanzhuangkj.com/tush/xpkg/xerrors/xerror" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
"gorm.io/gorm" "gorm.io/gorm"
......
...@@ -7,7 +7,7 @@ import ( ...@@ -7,7 +7,7 @@ import (
"github.com/nacos-group/nacos-sdk-go/model" "github.com/nacos-group/nacos-sdk-go/model"
"github.com/nacos-group/nacos-sdk-go/vo" "github.com/nacos-group/nacos-sdk-go/vo"
"gitlab.wanzhuangkj.com/tush/xpkg/config" "gitlab.wanzhuangkj.com/tush/xpkg/config"
"gitlab.wanzhuangkj.com/tush/xpkg/logger" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
) )
type NacosServiceClient struct { type NacosServiceClient struct {
......
package sms
type SmsMessage struct {
Phone string
Title string
Content string
}
type SmsConfig struct {
}
type SmsSender struct{}
// Send 发送短消息
func (m *SmsSender) Send(msg *SmsMessage, config *SmsConfig) error {
if msg == nil {
return nil
}
return m.Sends(append([]*SmsMessage{}, msg), config)
}
func (m *SmsSender) Sends(msgs []*SmsMessage, config *SmsConfig) error {
if len(msgs) == 0 {
return nil
}
return nil
}
...@@ -8,8 +8,8 @@ import ( ...@@ -8,8 +8,8 @@ import (
"time" "time"
"gitlab.wanzhuangkj.com/tush/xpkg/config" "gitlab.wanzhuangkj.com/tush/xpkg/config"
"gitlab.wanzhuangkj.com/tush/xpkg/httpcli" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/httpcli"
"gitlab.wanzhuangkj.com/tush/xpkg/logger" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
) )
......
...@@ -4,7 +4,7 @@ import ( ...@@ -4,7 +4,7 @@ import (
"context" "context"
"time" "time"
"gitlab.wanzhuangkj.com/tush/xpkg/xerrors/xerror" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
"golang.org/x/sync/errgroup" "golang.org/x/sync/errgroup"
) )
......
...@@ -5,7 +5,7 @@ import ( ...@@ -5,7 +5,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"gitlab.wanzhuangkj.com/tush/xpkg/xerrors/xerror" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
) )
func ToJsonString(v any) string { func ToJsonString(v any) string {
......
...@@ -7,9 +7,9 @@ import ( ...@@ -7,9 +7,9 @@ import (
"github.com/go-redsync/redsync/v4" "github.com/go-redsync/redsync/v4"
"github.com/go-redsync/redsync/v4/redis/goredis/v9" "github.com/go-redsync/redsync/v4/redis/goredis/v9"
"github.com/redis/go-redis/v9" "github.com/redis/go-redis/v9"
"gitlab.wanzhuangkj.com/tush/xpkg/logger" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/xerrors/xerror"
) )
var ( var (
......
package setUtils package setUtils
import ( import (
"gitlab.wanzhuangkj.com/tush/xpkg/xtype" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/xtype"
) )
type Set[T xtype.Key] struct { type Set[T xtype.Key] struct {
......
...@@ -4,13 +4,13 @@ import ( ...@@ -4,13 +4,13 @@ import (
"fmt" "fmt"
"strings" "strings"
"gitlab.wanzhuangkj.com/tush/xpkg/errcode" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/errcode"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xtype"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/setUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/setUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/xtype"
"github.com/jinzhu/copier" "github.com/jinzhu/copier"
"github.com/spf13/cast" "github.com/spf13/cast"
"gitlab.wanzhuangkj.com/tush/xpkg/xerrors/xerror" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
) )
// connector 连接符 // connector 连接符
......
...@@ -14,9 +14,9 @@ import ( ...@@ -14,9 +14,9 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/jinzhu/copier" "github.com/jinzhu/copier"
"github.com/spf13/cast" "github.com/spf13/cast"
"gitlab.wanzhuangkj.com/tush/xpkg/httpcli/entity" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/httpcli/entity"
"gitlab.wanzhuangkj.com/tush/xpkg/logger" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
merge "gitlab.wanzhuangkj.com/tush/xpkg/merger" merge "gitlab.wanzhuangkj.com/tush/xpkg/pkg/merger"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/json_utils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/json_utils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/retryUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/retryUtils"
......
...@@ -2,10 +2,11 @@ package wg ...@@ -2,10 +2,11 @@ package wg
import ( import (
"context" "context"
"gitlab.wanzhuangkj.com/tush/xpkg/logger"
ctxUtil "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/xerrors/xerror"
"sync" "sync"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
ctxUtil "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils"
) )
func Go(ctx context.Context, n int, fn func() error) error { func Go(ctx context.Context, n int, fn func() error) error {
......
...@@ -10,7 +10,7 @@ import ( ...@@ -10,7 +10,7 @@ import (
"github.com/bwmarrin/snowflake" "github.com/bwmarrin/snowflake"
"gitlab.wanzhuangkj.com/tush/xpkg/config" "gitlab.wanzhuangkj.com/tush/xpkg/config"
"gitlab.wanzhuangkj.com/tush/xpkg/xerrors/xerror" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
) )
var ( var (
......
...@@ -4,7 +4,7 @@ import "github.com/swaggo/swag" ...@@ -4,7 +4,7 @@ import "github.com/swaggo/swag"
var xapi *swag.Spec var xapi *swag.Spec
func Init(apiDoc *swag.Spec) (err error) { func Spec(apiDoc *swag.Spec) (err error) {
xapi = apiDoc xapi = apiDoc
return initApiM(xapi) return initApiM(xapi)
} }
...@@ -4,7 +4,7 @@ import ( ...@@ -4,7 +4,7 @@ import (
"context" "context"
"database/sql" "database/sql"
"gitlab.wanzhuangkj.com/tush/xpkg/xerrors/xerror" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
"gorm.io/gorm" "gorm.io/gorm"
) )
......
...@@ -7,7 +7,7 @@ import ( ...@@ -7,7 +7,7 @@ import (
"strings" "strings"
"unicode" "unicode"
"gitlab.wanzhuangkj.com/tush/xpkg/logger" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
) )
/* /*
......
package xcommon package xcommon
import ( import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xtype"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/xtype"
) )
type IConverter[ID xtype.Key, T, B any] interface { type IConverter[ID xtype.Key, T, B any] interface {
......
...@@ -9,7 +9,7 @@ import ( ...@@ -9,7 +9,7 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"gitlab.wanzhuangkj.com/tush/xpkg/gin/response" "gitlab.wanzhuangkj.com/tush/xpkg/gin/response"
"gitlab.wanzhuangkj.com/tush/xpkg/httpcli" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/httpcli"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/map_utils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/map_utils"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon/validator" "gitlab.wanzhuangkj.com/tush/xpkg/xcommon/validator"
) )
......
...@@ -6,7 +6,7 @@ import ( ...@@ -6,7 +6,7 @@ import (
) )
func Init(apiSpec *swag.Spec) (err error) { func Init(apiSpec *swag.Spec) (err error) {
if err := api.Init(apiSpec); err != nil { if err := api.Spec(apiSpec); err != nil {
return err return err
} }
return nil return nil
......
...@@ -8,11 +8,11 @@ import ( ...@@ -8,11 +8,11 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/database" "gitlab.wanzhuangkj.com/tush/xpkg/database"
"gitlab.wanzhuangkj.com/tush/xpkg/cache" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/cache"
"gitlab.wanzhuangkj.com/tush/xpkg/encoding" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/encoding"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
"gitlab.wanzhuangkj.com/tush/xpkg/utils" "gitlab.wanzhuangkj.com/tush/xpkg/utils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/xerrors/xerror"
) )
const ( const (
......
...@@ -7,16 +7,16 @@ import ( ...@@ -7,16 +7,16 @@ import (
"strings" "strings"
"gitlab.wanzhuangkj.com/tush/xpkg/database" "gitlab.wanzhuangkj.com/tush/xpkg/database"
"gitlab.wanzhuangkj.com/tush/xpkg/goredis" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/goredis"
"gitlab.wanzhuangkj.com/tush/xpkg/logger" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
"gitlab.wanzhuangkj.com/tush/xpkg/sgorm" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/sgorm"
"gitlab.wanzhuangkj.com/tush/xpkg/sgorm/query" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/sgorm/query"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
"gitlab.wanzhuangkj.com/tush/xpkg/utils" "gitlab.wanzhuangkj.com/tush/xpkg/utils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/setUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/setUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon/ocache" "gitlab.wanzhuangkj.com/tush/xpkg/xcommon/ocache"
"gitlab.wanzhuangkj.com/tush/xpkg/xerrors/xerror"
"golang.org/x/sync/singleflight" "golang.org/x/sync/singleflight"
"gorm.io/gorm" "gorm.io/gorm"
olog "gorm.io/gorm/logger" olog "gorm.io/gorm/logger"
......
...@@ -7,8 +7,8 @@ import ( ...@@ -7,8 +7,8 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
ut "github.com/go-playground/universal-translator" ut "github.com/go-playground/universal-translator"
"github.com/go-playground/validator/v10" "github.com/go-playground/validator/v10"
"gitlab.wanzhuangkj.com/tush/xpkg/errcode" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/errcode"
"gitlab.wanzhuangkj.com/tush/xpkg/xerrors/xerror" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
) )
var ( var (
......
...@@ -9,10 +9,10 @@ import ( ...@@ -9,10 +9,10 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/go-redsync/redsync/v4" "github.com/go-redsync/redsync/v4"
"gitlab.wanzhuangkj.com/tush/xpkg/config" "gitlab.wanzhuangkj.com/tush/xpkg/config"
"gitlab.wanzhuangkj.com/tush/xpkg/eventbus"
"gitlab.wanzhuangkj.com/tush/xpkg/gin/response" "gitlab.wanzhuangkj.com/tush/xpkg/gin/response"
"gitlab.wanzhuangkj.com/tush/xpkg/gocron" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/eventbus"
"gitlab.wanzhuangkj.com/tush/xpkg/logger" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/gocron"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/redSyncUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/redSyncUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceUtils"
......
...@@ -7,8 +7,8 @@ import ( ...@@ -7,8 +7,8 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/xcron/enums" "gitlab.wanzhuangkj.com/tush/xpkg/xcron/enums"
"gitlab.wanzhuangkj.com/tush/xpkg/xcron/models" "gitlab.wanzhuangkj.com/tush/xpkg/xcron/models"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/xerrors/xerror"
"golang.org/x/sync/singleflight" "golang.org/x/sync/singleflight"
"gorm.io/gorm" "gorm.io/gorm"
glogger "gorm.io/gorm/logger" glogger "gorm.io/gorm/logger"
......
...@@ -5,7 +5,7 @@ import ( ...@@ -5,7 +5,7 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/config" "gitlab.wanzhuangkj.com/tush/xpkg/config"
"gitlab.wanzhuangkj.com/tush/xpkg/database" "gitlab.wanzhuangkj.com/tush/xpkg/database"
"gitlab.wanzhuangkj.com/tush/xpkg/eventbus" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/eventbus"
) )
func init() { func init() {
......
...@@ -4,7 +4,7 @@ import ( ...@@ -4,7 +4,7 @@ import (
"context" "context"
"gitlab.wanzhuangkj.com/tush/xpkg/database" "gitlab.wanzhuangkj.com/tush/xpkg/database"
"gitlab.wanzhuangkj.com/tush/xpkg/eventbus" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/eventbus"
"gitlab.wanzhuangkj.com/tush/xpkg/xcron/cache" "gitlab.wanzhuangkj.com/tush/xpkg/xcron/cache"
) )
......
package ecode package ecode
import "gitlab.wanzhuangkj.com/tush/xpkg/errcode" import "gitlab.wanzhuangkj.com/tush/xpkg/pkg/errcode"
var ( var (
ErrCronJobNotFound = errcode.NewError(12001, "未查询到任务") ErrCronJobNotFound = errcode.NewError(12001, "未查询到任务")
......
...@@ -14,8 +14,8 @@ import ( ...@@ -14,8 +14,8 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/xcron/types" "gitlab.wanzhuangkj.com/tush/xpkg/xcron/types"
"github.com/jinzhu/copier" "github.com/jinzhu/copier"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceUtils" "gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/xerrors/xerror"
) )
type cronJobService struct { type cronJobService struct {
......
package types package types
import ( import (
"gitlab.wanzhuangkj.com/tush/xpkg/sgorm/query" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/sgorm/query"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime"
"gitlab.wanzhuangkj.com/tush/xpkg/xcron/biz" "gitlab.wanzhuangkj.com/tush/xpkg/xcron/biz"
......
package types package types
import ( import (
"gitlab.wanzhuangkj.com/tush/xpkg/sgorm/query" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/sgorm/query"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime"
"gitlab.wanzhuangkj.com/tush/xpkg/xcron/biz" "gitlab.wanzhuangkj.com/tush/xpkg/xcron/biz"
......
package types package types
import ( import (
"gitlab.wanzhuangkj.com/tush/xpkg/sgorm/query" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/sgorm/query"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime"
"gitlab.wanzhuangkj.com/tush/xpkg/xcron/biz" "gitlab.wanzhuangkj.com/tush/xpkg/xcron/biz"
......
...@@ -4,10 +4,10 @@ package types ...@@ -4,10 +4,10 @@ package types
import ( import (
"math" "math"
"gitlab.wanzhuangkj.com/tush/xpkg/errcode"
"gitlab.wanzhuangkj.com/tush/xpkg/gin/response" "gitlab.wanzhuangkj.com/tush/xpkg/gin/response"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/errcode"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf" "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/xerrors/xerror"
) )
var ( var (
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论