提交 1e052455 authored 作者: mooncake's avatar mooncake

rename package

上级 55ac0e28
......@@ -19,7 +19,7 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/rd/nacos"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/dxsf"
goutils "gitlab.wanzhuangkj.com/tush/xpkg/utils/goutils"
"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/pkg/app"
......@@ -54,7 +54,7 @@ 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
}
if err := config.ParseConf(); err != nil {
......
......@@ -3,14 +3,15 @@ package config
import (
"bytes"
"context"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/eventbus"
"time"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/eventbus"
"github.com/hashicorp/consul/api"
"github.com/spf13/viper"
"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"
)
type ConsulConfFetcher struct {
......@@ -52,7 +53,7 @@ func (x *ConsulConfFetcher) sync() *ConsulConfFetcher {
x.err = xerror.New("[consul]请先配置consul")
return x
}
if hashUtils.Md5(kv.Value) != hashUtils.Md5(x.cfg.GetContent()) {
if hashutils.Md5(kv.Value) != hashutils.Md5(x.cfg.GetContent()) {
x.count++
x.isNew = true
x.cfg.SetContent(kv.Value)
......
......@@ -3,7 +3,7 @@ package database
import (
"time"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils"
ctxutils "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxutils"
"gitlab.wanzhuangkj.com/tush/xpkg/config"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
......@@ -25,7 +25,7 @@ func InitMysql(dbConfig *config.Database) (*sgorm.DB, error) {
if dbConfig.Mysql.EnableLog {
opts = append(opts,
mysql.WithLogging(logger.Get()),
mysql.WithLogRequestIDKey(ctxUtils.ContextTraceIDKey),
mysql.WithLogRequestIDKey(ctxutils.ContextTraceIDKey),
)
}
......
......@@ -7,7 +7,7 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/errcode"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/jwt"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils"
ctxutils "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
)
......@@ -102,8 +102,8 @@ func Auth(opts ...JwtOption) gin.HandlerFunc {
}
} else {
xsfID, _ := xsf.ParseString(claims.UID)
c.Set(ctxUtils.KeyUID, xsfID)
c.Set(ctxUtils.KeyUName, claims.Name)
c.Set(ctxutils.KeyUID, xsfID)
c.Set(ctxutils.KeyUName, claims.Name)
}
c.Next()
......@@ -130,7 +130,7 @@ func HeaderFields(keys []string) gin.HandlerFunc {
c.Set(key, c.Request.Header.Get(key))
kv[key] = c.Request.Header.Get(key)
}
logger.Info("[middleware][headerFields]header kvs", logger.Any("kv", kv), ctxUtils.GinTraceIDField(c))
logger.Info("[middleware][headerFields]header kvs", logger.Any("kv", kv), ctxutils.GinTraceIDField(c))
}
}
......
......@@ -8,9 +8,9 @@ import (
"time"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/httpcli/entity"
ctxutils "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxutils"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/ips"
ctxUtils "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
......@@ -206,19 +206,19 @@ func Logging(opts ...Option) gin.HandlerFunc {
entity.SetCopyReq(c, buf)
c.Set(ctxUtils.KeyAppName, o.appName)
c.Set(ctxutils.KeyAppName, o.appName)
reqID := ""
if o.traceIDFrom == 1 {
if v, isExist := c.Get(ctxUtils.ContextTraceIDKey); isExist {
if v, isExist := c.Get(ctxutils.ContextTraceIDKey); isExist {
if requestID, ok := v.(string); ok {
reqID = requestID
fields = append(fields, zap.String(ctxUtils.ContextTraceIDKey, reqID))
fields = append(fields, zap.String(ctxutils.ContextTraceIDKey, reqID))
}
}
} else if o.traceIDFrom == 2 {
reqID = c.Request.Header.Get(ctxUtils.HeaderXRequestIDKey)
fields = append(fields, zap.String(ctxUtils.ContextTraceIDKey, reqID))
reqID = c.Request.Header.Get(ctxutils.HeaderXRequestIDKey)
fields = append(fields, zap.String(ctxutils.ContextTraceIDKey, reqID))
}
o.log.Info("[middleware][logging]<<<<<<<<<req", fields...)
......@@ -229,12 +229,12 @@ func Logging(opts ...Option) gin.HandlerFunc {
c.Writer = newWriter
ip := ips.GetClientIP(c)
c.Set(ctxUtils.KeyClientIP, ip)
c.Set(ctxutils.KeyClientIP, ip)
// processing requests
c.Next()
rspBodyMax := c.GetInt(ctxUtils.KeyRspBodyMax)
rspBodyMax := c.GetInt(ctxutils.KeyRspBodyMax)
contentType := c.Writer.Header().Get("Content-Type")
isMedia := false
if strings.Contains(contentType, "image") {
......@@ -260,7 +260,7 @@ func Logging(opts ...Option) gin.HandlerFunc {
}
}
if reqID != "" {
fields = append(fields, zap.String(ctxUtils.ContextTraceIDKey, reqID))
fields = append(fields, zap.String(ctxutils.ContextTraceIDKey, reqID))
}
o.log.Info("[middleware][logging]>>>>>>>>>rsp", fields...)
......@@ -285,13 +285,13 @@ func SimpleLog(opts ...Option) gin.HandlerFunc {
reqID := ""
switch o.traceIDFrom {
case 1:
if v, isExist := c.Get(ctxUtils.ContextTraceIDKey); isExist {
if v, isExist := c.Get(ctxutils.ContextTraceIDKey); isExist {
if requestID, ok := v.(string); ok {
reqID = requestID
}
}
case 2:
reqID = c.Request.Header.Get(ctxUtils.HeaderXRequestIDKey)
reqID = c.Request.Header.Get(ctxutils.HeaderXRequestIDKey)
}
// processing requests
......@@ -306,7 +306,7 @@ func SimpleLog(opts ...Option) gin.HandlerFunc {
zap.Int("size", c.Writer.Size()),
}
if reqID != "" {
fields = append(fields, zap.String(ctxUtils.ContextTraceIDKey, reqID))
fields = append(fields, zap.String(ctxutils.ContextTraceIDKey, reqID))
}
o.log.Info("[middleware][logging]]>>>>>>>>>rsp", fields...)
}
......
......@@ -11,7 +11,7 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/httpcli"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
"gitlab.wanzhuangkj.com/tush/xpkg/utils"
ctxUtil "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils"
ctxUtil "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxutils"
)
func init() {
......
......@@ -14,7 +14,7 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/eventbus"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/ips"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils"
ctxutils "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxutils"
)
var (
......@@ -48,7 +48,7 @@ func SyncIPRateLimiter(windowSize time.Duration, maxRequests int, cli *redis.Cli
})
return func(c *gin.Context) {
clientIP := ips.GetClientIP(c)
ctx := ctxUtils.WrapCtx(c)
ctx := ctxutils.WrapCtx(c)
if redisIPRateLimiter.Allow(ctx, clientIP) {
c.Next()
} else {
......@@ -58,5 +58,5 @@ func SyncIPRateLimiter(windowSize time.Duration, maxRequests int, cli *redis.Cli
}
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)})
c.AbortWithStatusJSON(http.StatusOK, response.Result{Code: code, Msg: msg, Data: nil, TimeStamp: time.Now().Unix(), TraceID: ctxutils.GetGinCtxTid(c)})
}
......@@ -3,7 +3,7 @@ package middleware
import (
"net/http"
ctxUtil "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils"
ctxUtil "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxutils"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
......
......@@ -2,11 +2,12 @@ package middleware
import (
"context"
"github.com/gin-gonic/gin"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils"
"go.uber.org/zap"
"net/http"
"time"
"github.com/gin-gonic/gin"
ctxutils "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxutils"
"go.uber.org/zap"
)
// RequestIDOption set the request id options.
......@@ -20,8 +21,8 @@ type requestIDOptions struct {
func defaultRequestIDOptions() *requestIDOptions {
return &requestIDOptions{
contextRequestIDKey: ctxUtils.ContextTraceIDKey,
headerXRequestIDKey: ctxUtils.HeaderXRequestIDKey,
contextRequestIDKey: ctxutils.ContextTraceIDKey,
headerXRequestIDKey: ctxutils.HeaderXRequestIDKey,
}
}
......@@ -32,11 +33,11 @@ func (o *requestIDOptions) apply(opts ...RequestIDOption) {
}
func (o *requestIDOptions) setRequestIDKey() {
if o.contextRequestIDKey != ctxUtils.ContextTraceIDKey {
ctxUtils.ContextTraceIDKey = o.contextRequestIDKey
if o.contextRequestIDKey != ctxutils.ContextTraceIDKey {
ctxutils.ContextTraceIDKey = o.contextRequestIDKey
}
if o.headerXRequestIDKey != ctxUtils.HeaderXRequestIDKey {
ctxUtils.HeaderXRequestIDKey = o.headerXRequestIDKey
if o.headerXRequestIDKey != ctxutils.HeaderXRequestIDKey {
ctxutils.HeaderXRequestIDKey = o.headerXRequestIDKey
}
}
......@@ -64,7 +65,7 @@ func WithHeaderRequestIDKey(key string) RequestIDOption {
type CtxKeyString string
// RequestIDKey request_id
var RequestIDKey = CtxKeyString(ctxUtils.ContextTraceIDKey)
var RequestIDKey = CtxKeyString(ctxutils.ContextTraceIDKey)
// -------------------------------------------------------------------------------------------
......@@ -76,21 +77,21 @@ func RequestID(opts ...RequestIDOption) gin.HandlerFunc {
o.setRequestIDKey()
return func(c *gin.Context) {
requestID := c.Request.Header.Get(ctxUtils.HeaderXRequestIDKey)
requestID := c.Request.Header.Get(ctxutils.HeaderXRequestIDKey)
// Create request id
if requestID == "" {
requestID = ctxUtils.GenerateTid()
c.Request.Header.Set(ctxUtils.HeaderXRequestIDKey, requestID)
requestID = ctxutils.GenerateTid()
c.Request.Header.Set(ctxutils.HeaderXRequestIDKey, requestID)
}
st := time.Now()
// Expose it for use in the application
c.Set(ctxUtils.ContextTraceIDKey, requestID)
c.Set(ctxUtils.KeyApiStartTime, st)
c.Set(ctxutils.ContextTraceIDKey, requestID)
c.Set(ctxutils.KeyApiStartTime, st)
// Set X-Request-Id header
c.Writer.Header().Set(ctxUtils.HeaderXRequestIDKey, requestID)
c.Writer.Header().Set(ctxutils.HeaderXRequestIDKey, requestID)
c.Next()
}
......@@ -98,12 +99,12 @@ func RequestID(opts ...RequestIDOption) gin.HandlerFunc {
// HeaderRequestID get request id from the header
func HeaderRequestID(c *gin.Context) string {
return c.Request.Header.Get(ctxUtils.HeaderXRequestIDKey)
return c.Request.Header.Get(ctxutils.HeaderXRequestIDKey)
}
// HeaderRequestIDField get request id field from header
func HeaderRequestIDField(c *gin.Context) zap.Field {
return zap.String(ctxUtils.HeaderXRequestIDKey, HeaderRequestID(c))
return zap.String(ctxutils.HeaderXRequestIDKey, HeaderRequestID(c))
}
// -------------------------------------------------------------------------------------------
......@@ -115,7 +116,7 @@ var RequestHeaderKey = "request_header_key"
func AdaptCtx(ctx context.Context) (*gin.Context, context.Context) {
c, ok := ctx.(*gin.Context)
if ok {
ctx = ctxUtils.WrapCtx(c)
ctx = ctxutils.WrapCtx(c)
}
return c, ctx
}
......
......@@ -9,7 +9,7 @@ import (
"github.com/redis/go-redis/v9"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/goredis"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils"
ctxutils "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxutils"
"go.uber.org/zap"
)
......@@ -29,13 +29,13 @@ func (d *RedisDatastore) Add(ctx context.Context, key string, start, value int64
c, err := d.client.IncrBy(ctx, k, value).Result()
if err != nil {
if d.logger != nil {
d.logger.Error(fmt.Sprintf("[SlideWindow] add fail,[k:%s add:%d]", k, value), zap.String("err", err.Error()), zap.String("cost", time.Since(startTime).String()), ctxUtils.CtxTraceIDField(ctx))
d.logger.Error(fmt.Sprintf("[SlideWindow] add fail,[k:%s add:%d]", k, value), zap.String("err", err.Error()), zap.String("cost", time.Since(startTime).String()), ctxutils.CtxTraceIDField(ctx))
}
return 0, err
}
_, _ = d.client.Expire(ctx, k, d.ttl).Result()
if d.logger != nil {
d.logger.Info(fmt.Sprintf("[SlideWindow] add success,[k:%s add:%d -> %d]", k, value, c), zap.String("cost", time.Since(startTime).String()), ctxUtils.CtxTraceIDField(ctx))
d.logger.Info(fmt.Sprintf("[SlideWindow] add success,[k:%s add:%d -> %d]", k, value, c), zap.String("cost", time.Since(startTime).String()), ctxutils.CtxTraceIDField(ctx))
}
return c, err
}
......@@ -49,12 +49,12 @@ func (d *RedisDatastore) Get(ctx context.Context, key string, start int64) (int6
err = nil
}
if d.logger != nil {
d.logger.Error(fmt.Sprintf("[SlideWindow] get fail [k:%s]", k), zap.String("err", err.Error()), zap.String("cost", time.Since(startTime).String()), ctxUtils.CtxTraceIDField(ctx))
d.logger.Error(fmt.Sprintf("[SlideWindow] get fail [k:%s]", k), zap.String("err", err.Error()), zap.String("cost", time.Since(startTime).String()), ctxutils.CtxTraceIDField(ctx))
}
return 0, err
}
if d.logger != nil {
d.logger.Info(fmt.Sprintf("[SlideWindow] get success [k:%s v:%s]", k, value), zap.String("cost", time.Since(startTime).String()), ctxUtils.CtxTraceIDField(ctx))
d.logger.Info(fmt.Sprintf("[SlideWindow] get success [k:%s v:%s]", k, value), zap.String("cost", time.Since(startTime).String()), ctxutils.CtxTraceIDField(ctx))
}
return strconv.ParseInt(value, 10, 64)
}
......
......@@ -10,13 +10,13 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/httpcli/entity"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/sgorm/query"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxutils"
"github.com/gin-gonic/gin"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/errcode"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
ctxUtils "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils"
)
const CustomErrorCode = 0
......@@ -63,7 +63,7 @@ func newResp(c *gin.Context, code int, msg string, data interface{}) *Result {
Code: code,
Msg: msg,
TimeStamp: time.Now().Unix(),
TraceID: ctxUtils.GetGinCtxTid(c),
TraceID: ctxutils.GetGinCtxTid(c),
}
// ensure that the data field is not nil on return, note that it is not nil when resp.data=[]interface {}, it is serialized to null
......@@ -173,10 +173,10 @@ func Out(c *gin.Context, err *errcode.Error, data ...interface{}) {
// status code flat 200, custom error codes in data.code
func respJSONWith200(c *gin.Context, code int, msg string, data ...interface{}) {
c.Writer.Header().Set(ctxUtils.HeaderXTimestampKey, strconv.FormatInt(time.Now().Unix(), 10))
appName := c.GetString(ctxUtils.KeyAppName)
stTime := c.GetTime(ctxUtils.KeyApiStartTime)
ctxUtils.AddApiCost(c, appName, stTime)
c.Writer.Header().Set(ctxutils.HeaderXTimestampKey, strconv.FormatInt(time.Now().Unix(), 10))
appName := c.GetString(ctxutils.KeyAppName)
stTime := c.GetTime(ctxutils.KeyApiStartTime)
ctxutils.AddApiCost(c, appName, stTime)
if len(data) > 0 {
writeJSON(c, http.StatusOK, newResp(c, code, msg, data[0]))
......@@ -188,7 +188,7 @@ func respJSONWith200(c *gin.Context, code int, msg string, data ...interface{})
// Success return success
func Success(c *gin.Context, data ...interface{}) {
c.Set(ctxUtils.KeyRspCode, 1)
c.Set(ctxutils.KeyRspCode, 1)
respJSONWith200(c, errcode.Success.Code(), errcode.Success.Msg(), data...)
}
......@@ -207,7 +207,7 @@ func Success(c *gin.Context, data ...interface{}) {
// if total%int64(pageSize) > 0 {
// totalPage = totalPage + 1
// }
// c.Set(ctxUtils.KeyRspCode, 1)
// c.Set(ctxutils.KeyRspCode, 1)
// if list == nil {
// list = []*T{}
// }
......@@ -221,7 +221,7 @@ func Success(c *gin.Context, data ...interface{}) {
func SuccessWithPage[T any](c *gin.Context, list []*T, total int64) {
pageIndex := 1
pageSize := 10
if req, ok := c.Get(ctxUtils.KeyPagination); ok {
if req, ok := c.Get(ctxutils.KeyPagination); ok {
if pagination, ok := req.(query.Pagination); ok {
pageIndex = pagination.PageIndex
if pagination.PageSize > 0 {
......@@ -233,7 +233,7 @@ func SuccessWithPage[T any](c *gin.Context, list []*T, total int64) {
if total%int64(pageSize) > 0 {
pageTotal = pageTotal + 1
}
c.Set(ctxUtils.KeyRspCode, 1)
c.Set(ctxutils.KeyRspCode, 1)
if list == nil {
list = []*T{}
}
......@@ -244,7 +244,7 @@ func SuccessWithPage[T any](c *gin.Context, list []*T, total int64) {
// SuccessWithList return success
func SuccessWithList[T any](c *gin.Context, list []*T) {
c.Set(ctxUtils.KeyRspCode, 1)
c.Set(ctxutils.KeyRspCode, 1)
if list == nil {
list = []*T{}
}
......@@ -253,24 +253,24 @@ func SuccessWithList[T any](c *gin.Context, list []*T) {
// ErrorE return error
func ErrorE(c *gin.Context, err *errcode.Error, data ...interface{}) {
c.Set(ctxUtils.KeyRspCode, 0)
c.Set(ctxutils.KeyRspCode, 0)
respJSONWith200(c, err.Code(), err.Msg(), data...)
}
func Error(c *gin.Context, err error) {
c.Set(ctxUtils.KeyRspCode, 0)
c.Set(ctxutils.KeyRspCode, 0)
msg := ""
if err != nil {
msg = err.Error()
if e, ok := err.(*xerror.Error); ok {
//if !errcode.IsSysDefinedError(xerr.Code()) {
// logger.Error(err.Error(), logger.Err(err), ctxUtils.GinTraceIDField(c))
// logger.Error(err.Error(), logger.Err(err), ctxutils.GinTraceIDField(c))
//}
if e.Code() != errcode.InvalidParams.Code() {
logger.Error(err.Error(), logger.Err(err), ctxUtils.GinTraceIDField(c))
logger.Error(err.Error(), logger.Err(err), ctxutils.GinTraceIDField(c))
}
} else {
logger.Error(err.Error(), logger.Err(err), ctxUtils.GinTraceIDField(c))
logger.Error(err.Error(), logger.Err(err), ctxutils.GinTraceIDField(c))
}
}
respJSONWith200(c, CustomErrorCode, msg)
......
......@@ -26,7 +26,7 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/jwt"
"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"
"gitlab.wanzhuangkj.com/tush/xpkg/xcron"
)
......@@ -122,7 +122,7 @@ func New() *gin.Engine {
binding.Validator = validator.Init()
// r.Use(xvalidator.Translation())
webLogUtils.Init()
weblogutils.Init()
if config.IsNotProd() {
r.GET(consts.RootRoute+"/config", gin.WrapF(errcode.ShowConfig([]byte(config.Show()))))
......
......@@ -58,7 +58,6 @@ require (
require (
github.com/bwmarrin/snowflake v0.3.0
github.com/bytedance/go-tagexpr/v2 v2.9.11
github.com/duke-git/lancet/v2 v2.3.4
github.com/go-redsync/redsync/v4 v4.13.0
github.com/gocarina/gocsv v0.0.0-20240520201108-78e41c74b4b1
github.com/hashicorp/consul/api v1.12.0
......
......@@ -122,8 +122,6 @@ github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2 h1:tdlZCpZ/P9DhczC
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/duke-git/lancet/v2 v2.3.4 h1:8XGI7P9w+/GqmEBEXYaH/XuNiM0f4/90Ioti0IvYJls=
github.com/duke-git/lancet/v2 v2.3.4/go.mod h1:zGa2R4xswg6EG9I6WnyubDbFO/+A/RROxIbXcwryTsc=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
......
......@@ -13,8 +13,8 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/encoding"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
ctxUtil "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils"
xslice "gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceUtils"
ctxUtil "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxutils"
xslice "gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceutils"
)
type memoryCache struct {
......
......@@ -2,8 +2,8 @@ package biz
import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/setUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/setutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
)
......@@ -16,10 +16,10 @@ type Email struct {
var EmailTool = &Email{}
func (*Email) GetIDs(rs []*Email) []xsf.ID {
return sliceUtils.GetIDs[xsf.ID](rs)
return sliceutils.GetIDs[xsf.ID](rs)
}
func (x *Email) GetTplIDs(rs []*Email) []xsf.ID {
set := setUtils.NewSet[xsf.ID]()
set := setutils.NewSet[xsf.ID]()
for _, r := range rs {
set.Add(r.GetTplID())
}
......
......@@ -2,8 +2,8 @@ package biz
import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/setUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/setutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
)
......@@ -16,10 +16,10 @@ type EmailReceiver struct {
var EmailReceiverTool = &EmailReceiver{}
func (*EmailReceiver) GetIDs(rs []*EmailReceiver) []xsf.ID {
return sliceUtils.GetIDs[xsf.ID](rs)
return sliceutils.GetIDs[xsf.ID](rs)
}
func (x *EmailReceiver) GetEmailIDs(rs []*EmailReceiver) []xsf.ID {
set := setUtils.NewSet[xsf.ID]()
set := setutils.NewSet[xsf.ID]()
for _, r := range rs {
set.Add(r.GetEmailID())
}
......
......@@ -2,8 +2,8 @@ package biz
import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/setUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/setutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
)
......@@ -16,10 +16,10 @@ type EmailSend struct {
var EmailSendTool = &EmailSend{}
func (*EmailSend) GetIDs(rs []*EmailSend) []xsf.ID {
return sliceUtils.GetIDs[xsf.ID](rs)
return sliceutils.GetIDs[xsf.ID](rs)
}
func (x *EmailSend) GetEmailIDs(rs []*EmailSend) []xsf.ID {
set := setUtils.NewSet[xsf.ID]()
set := setutils.NewSet[xsf.ID]()
for _, r := range rs {
set.Add(r.GetEmailID())
}
......
......@@ -2,8 +2,8 @@ package biz
import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/setUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/setutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
)
......@@ -16,10 +16,10 @@ type EmailSendLog struct {
var EmailSendLogTool = &EmailSendLog{}
func (*EmailSendLog) GetIDs(rs []*EmailSendLog) []xsf.ID {
return sliceUtils.GetIDs[xsf.ID](rs)
return sliceutils.GetIDs[xsf.ID](rs)
}
func (x *EmailSendLog) GetEmailSendIDs(rs []*EmailSendLog) []xsf.ID {
set := setUtils.NewSet[xsf.ID]()
set := setutils.NewSet[xsf.ID]()
for _, r := range rs {
set.Add(r.GetEmailSendID())
}
......
......@@ -2,7 +2,7 @@ package biz
import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models"
"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/xcommon"
)
......@@ -15,7 +15,7 @@ type EmailTpl struct {
var EmailTplTool = &EmailTpl{}
func (*EmailTpl) GetIDs(rs []*EmailTpl) []xsf.ID {
return sliceUtils.GetIDs[xsf.ID](rs)
return sliceutils.GetIDs[xsf.ID](rs)
}
func (EmailTpl) NewFromModel(m *models.EmailTpl) *EmailTpl {
......
......@@ -2,8 +2,8 @@ package biz
import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/setUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/setutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
)
......@@ -16,10 +16,10 @@ type EmailTplReceiver struct {
var EmailTplReceiverTool = &EmailTplReceiver{}
func (*EmailTplReceiver) GetIDs(rs []*EmailTplReceiver) []xsf.ID {
return sliceUtils.GetIDs[xsf.ID](rs)
return sliceutils.GetIDs[xsf.ID](rs)
}
func (x *EmailTplReceiver) GetTplIDs(rs []*EmailTplReceiver) []xsf.ID {
set := setUtils.NewSet[xsf.ID]()
set := setutils.NewSet[xsf.ID]()
for _, r := range rs {
set.Add(r.GetTplID())
}
......
......@@ -6,7 +6,7 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/gin/response"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/service"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/types"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils"
ctxutils "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxutils"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
)
......@@ -27,7 +27,7 @@ func (x *emailController) Create(c *gin.Context) {
response.Error(c, err)
return
}
id, err := service.EmailService.Create(ctxUtils.WrapCtx(c), in)
id, err := service.EmailService.Create(ctxutils.WrapCtx(c), in)
if err != nil {
response.Error(c, err)
return
......@@ -40,7 +40,7 @@ func (x *emailController) DeleteByID(c *gin.Context) {
response.Error(c, err)
return
}
if err := service.EmailService.DeleteByID(ctxUtils.WrapCtx(c), in.ID); err != nil {
if err := service.EmailService.DeleteByID(ctxutils.WrapCtx(c), in.ID); err != nil {
response.Error(c, err)
return
}
......@@ -52,7 +52,7 @@ func (x *emailController) UpdateByID(c *gin.Context) {
response.Error(c, err)
return
}
if err := service.EmailService.UpdateByID(ctxUtils.WrapCtx(c), in); err != nil {
if err := service.EmailService.UpdateByID(ctxutils.WrapCtx(c), in); err != nil {
response.Error(c, err)
return
}
......@@ -75,7 +75,7 @@ func (x *emailController) GetByID(c *gin.Context) {
response.Error(c, err)
return
}
email, err := service.EmailService.GetByID(ctxUtils.WrapCtx(c), in.ID)
email, err := service.EmailService.GetByID(ctxutils.WrapCtx(c), in.ID)
if err != nil {
response.Error(c, err)
return
......@@ -89,7 +89,7 @@ func (x *emailController) GetByIDs(c *gin.Context) {
response.Error(c, err)
return
}
emails, err := service.EmailService.GetSliceByIDs(ctxUtils.WrapCtx(c), in.IDs)
emails, err := service.EmailService.GetSliceByIDs(ctxutils.WrapCtx(c), in.IDs)
if err != nil {
response.Error(c, err)
return
......@@ -115,7 +115,7 @@ func (x *emailController) Page(c *gin.Context) {
response.Error(c, err)
return
}
emails, total, err := service.EmailService.Page(ctxUtils.WrapCtx(c), in)
emails, total, err := service.EmailService.Page(ctxutils.WrapCtx(c), in)
if err != nil {
response.Error(c, err)
return
......@@ -141,7 +141,7 @@ func (x *emailController) ExportCSV(c *gin.Context) {
response.Error(c, err)
return
}
url, err := service.EmailService.ExportCSV(ctxUtils.WrapCtx(c), in)
url, err := service.EmailService.ExportCSV(ctxutils.WrapCtx(c), in)
if err != nil {
response.Error(c, err)
return
......
......@@ -6,7 +6,7 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/gin/response"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/service"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/types"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils"
ctxutils "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxutils"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
)
......@@ -27,7 +27,7 @@ func (x *emailReceiverController) Create(c *gin.Context) {
response.Error(c, err)
return
}
id, err := service.EmailReceiverService.Create(ctxUtils.WrapCtx(c), in)
id, err := service.EmailReceiverService.Create(ctxutils.WrapCtx(c), in)
if err != nil {
response.Error(c, err)
return
......@@ -40,7 +40,7 @@ func (x *emailReceiverController) DeleteByID(c *gin.Context) {
response.Error(c, err)
return
}
if err := service.EmailReceiverService.DeleteByID(ctxUtils.WrapCtx(c), in.ID); err != nil {
if err := service.EmailReceiverService.DeleteByID(ctxutils.WrapCtx(c), in.ID); err != nil {
response.Error(c, err)
return
}
......@@ -52,7 +52,7 @@ func (x *emailReceiverController) UpdateByID(c *gin.Context) {
response.Error(c, err)
return
}
if err := service.EmailReceiverService.UpdateByID(ctxUtils.WrapCtx(c), in); err != nil {
if err := service.EmailReceiverService.UpdateByID(ctxutils.WrapCtx(c), in); err != nil {
response.Error(c, err)
return
}
......@@ -75,7 +75,7 @@ func (x *emailReceiverController) GetByID(c *gin.Context) {
response.Error(c, err)
return
}
emailReceiver, err := service.EmailReceiverService.GetByID(ctxUtils.WrapCtx(c), in.ID)
emailReceiver, err := service.EmailReceiverService.GetByID(ctxutils.WrapCtx(c), in.ID)
if err != nil {
response.Error(c, err)
return
......@@ -89,7 +89,7 @@ func (x *emailReceiverController) GetByIDs(c *gin.Context) {
response.Error(c, err)
return
}
emailReceivers, err := service.EmailReceiverService.GetSliceByIDs(ctxUtils.WrapCtx(c), in.IDs)
emailReceivers, err := service.EmailReceiverService.GetSliceByIDs(ctxutils.WrapCtx(c), in.IDs)
if err != nil {
response.Error(c, err)
return
......@@ -115,7 +115,7 @@ func (x *emailReceiverController) Page(c *gin.Context) {
response.Error(c, err)
return
}
emailReceivers, total, err := service.EmailReceiverService.Page(ctxUtils.WrapCtx(c), in)
emailReceivers, total, err := service.EmailReceiverService.Page(ctxutils.WrapCtx(c), in)
if err != nil {
response.Error(c, err)
return
......@@ -141,7 +141,7 @@ func (x *emailReceiverController) ExportCSV(c *gin.Context) {
response.Error(c, err)
return
}
url, err := service.EmailReceiverService.ExportCSV(ctxUtils.WrapCtx(c), in)
url, err := service.EmailReceiverService.ExportCSV(ctxutils.WrapCtx(c), in)
if err != nil {
response.Error(c, err)
return
......
......@@ -6,7 +6,7 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/gin/response"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/service"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/types"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils"
ctxutils "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxutils"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
)
......@@ -27,7 +27,7 @@ func (x *emailSendController) Create(c *gin.Context) {
response.Error(c, err)
return
}
id, err := service.EmailSendService.Create(ctxUtils.WrapCtx(c), in)
id, err := service.EmailSendService.Create(ctxutils.WrapCtx(c), in)
if err != nil {
response.Error(c, err)
return
......@@ -40,7 +40,7 @@ func (x *emailSendController) DeleteByID(c *gin.Context) {
response.Error(c, err)
return
}
if err := service.EmailSendService.DeleteByID(ctxUtils.WrapCtx(c), in.ID); err != nil {
if err := service.EmailSendService.DeleteByID(ctxutils.WrapCtx(c), in.ID); err != nil {
response.Error(c, err)
return
}
......@@ -53,7 +53,7 @@ func (x *emailSendController) UpdateByID(c *gin.Context) {
response.Error(c, err)
return
}
if err := service.EmailSendService.UpdateByID(ctxUtils.WrapCtx(c), in); err != nil {
if err := service.EmailSendService.UpdateByID(ctxutils.WrapCtx(c), in); err != nil {
response.Error(c, err)
return
}
......@@ -76,7 +76,7 @@ func (x *emailSendController) GetByID(c *gin.Context) {
response.Error(c, err)
return
}
emailSend, err := service.EmailSendService.GetByID(ctxUtils.WrapCtx(c), in.ID)
emailSend, err := service.EmailSendService.GetByID(ctxutils.WrapCtx(c), in.ID)
if err != nil {
response.Error(c, err)
return
......@@ -90,7 +90,7 @@ func (x *emailSendController) GetByIDs(c *gin.Context) {
response.Error(c, err)
return
}
emailSends, err := service.EmailSendService.GetSliceByIDs(ctxUtils.WrapCtx(c), in.IDs)
emailSends, err := service.EmailSendService.GetSliceByIDs(ctxutils.WrapCtx(c), in.IDs)
if err != nil {
response.Error(c, err)
return
......@@ -116,7 +116,7 @@ func (x *emailSendController) Page(c *gin.Context) {
response.Error(c, err)
return
}
emailSends, total, err := service.EmailSendService.Page(ctxUtils.WrapCtx(c), in)
emailSends, total, err := service.EmailSendService.Page(ctxutils.WrapCtx(c), in)
if err != nil {
response.Error(c, err)
return
......@@ -142,7 +142,7 @@ func (x *emailSendController) ExportCSV(c *gin.Context) {
response.Error(c, err)
return
}
url, err := service.EmailSendService.ExportCSV(ctxUtils.WrapCtx(c), in)
url, err := service.EmailSendService.ExportCSV(ctxutils.WrapCtx(c), in)
if err != nil {
response.Error(c, err)
return
......
......@@ -6,7 +6,7 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/gin/response"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/service"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/types"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils"
ctxutils "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxutils"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
)
......@@ -27,7 +27,7 @@ func (x *emailSendLogController) Create(c *gin.Context) {
response.Error(c, err)
return
}
id, err := service.EmailSendLogService.Create(ctxUtils.WrapCtx(c), in)
id, err := service.EmailSendLogService.Create(ctxutils.WrapCtx(c), in)
if err != nil {
response.Error(c, err)
return
......@@ -40,7 +40,7 @@ func (x *emailSendLogController) DeleteByID(c *gin.Context) {
response.Error(c, err)
return
}
if err := service.EmailSendLogService.DeleteByID(ctxUtils.WrapCtx(c), in.ID); err != nil {
if err := service.EmailSendLogService.DeleteByID(ctxutils.WrapCtx(c), in.ID); err != nil {
response.Error(c, err)
return
}
......@@ -52,7 +52,7 @@ func (x *emailSendLogController) UpdateByID(c *gin.Context) {
response.Error(c, err)
return
}
if err := service.EmailSendLogService.UpdateByID(ctxUtils.WrapCtx(c), in); err != nil {
if err := service.EmailSendLogService.UpdateByID(ctxutils.WrapCtx(c), in); err != nil {
response.Error(c, err)
return
}
......@@ -75,7 +75,7 @@ func (x *emailSendLogController) GetByID(c *gin.Context) {
response.Error(c, err)
return
}
emailSendLog, err := service.EmailSendLogService.GetByID(ctxUtils.WrapCtx(c), in.ID)
emailSendLog, err := service.EmailSendLogService.GetByID(ctxutils.WrapCtx(c), in.ID)
if err != nil {
response.Error(c, err)
return
......@@ -89,7 +89,7 @@ func (x *emailSendLogController) GetByIDs(c *gin.Context) {
response.Error(c, err)
return
}
emailSendLogs, err := service.EmailSendLogService.GetSliceByIDs(ctxUtils.WrapCtx(c), in.IDs)
emailSendLogs, err := service.EmailSendLogService.GetSliceByIDs(ctxutils.WrapCtx(c), in.IDs)
if err != nil {
response.Error(c, err)
return
......@@ -115,7 +115,7 @@ func (x *emailSendLogController) Page(c *gin.Context) {
response.Error(c, err)
return
}
emailSendLogs, total, err := service.EmailSendLogService.Page(ctxUtils.WrapCtx(c), in)
emailSendLogs, total, err := service.EmailSendLogService.Page(ctxutils.WrapCtx(c), in)
if err != nil {
response.Error(c, err)
return
......@@ -141,7 +141,7 @@ func (x *emailSendLogController) ExportCSV(c *gin.Context) {
response.Error(c, err)
return
}
url, err := service.EmailSendLogService.ExportCSV(ctxUtils.WrapCtx(c), in)
url, err := service.EmailSendLogService.ExportCSV(ctxutils.WrapCtx(c), in)
if err != nil {
response.Error(c, err)
return
......
......@@ -6,7 +6,7 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/gin/response"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/service"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/types"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils"
ctxutils "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxutils"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
)
......@@ -27,7 +27,7 @@ func (x *emailTplController) Create(c *gin.Context) {
response.Error(c, err)
return
}
id, err := service.EmailTplService.Create(ctxUtils.WrapCtx(c), in)
id, err := service.EmailTplService.Create(ctxutils.WrapCtx(c), in)
if err != nil {
response.Error(c, err)
return
......@@ -40,7 +40,7 @@ func (x *emailTplController) DeleteByID(c *gin.Context) {
response.Error(c, err)
return
}
if err := service.EmailTplService.DeleteByID(ctxUtils.WrapCtx(c), in.ID); err != nil {
if err := service.EmailTplService.DeleteByID(ctxutils.WrapCtx(c), in.ID); err != nil {
response.Error(c, err)
return
}
......@@ -52,7 +52,7 @@ func (x *emailTplController) UpdateByID(c *gin.Context) {
response.Error(c, err)
return
}
if err := service.EmailTplService.UpdateByID(ctxUtils.WrapCtx(c), in); err != nil {
if err := service.EmailTplService.UpdateByID(ctxutils.WrapCtx(c), in); err != nil {
response.Error(c, err)
return
}
......@@ -75,7 +75,7 @@ func (x *emailTplController) GetByID(c *gin.Context) {
response.Error(c, err)
return
}
emailTpl, err := service.EmailTplService.GetByID(ctxUtils.WrapCtx(c), in.ID)
emailTpl, err := service.EmailTplService.GetByID(ctxutils.WrapCtx(c), in.ID)
if err != nil {
response.Error(c, err)
return
......@@ -89,7 +89,7 @@ func (x *emailTplController) GetByIDs(c *gin.Context) {
response.Error(c, err)
return
}
emailTpls, err := service.EmailTplService.GetSliceByIDs(ctxUtils.WrapCtx(c), in.IDs)
emailTpls, err := service.EmailTplService.GetSliceByIDs(ctxutils.WrapCtx(c), in.IDs)
if err != nil {
response.Error(c, err)
return
......@@ -115,7 +115,7 @@ func (x *emailTplController) Page(c *gin.Context) {
response.Error(c, err)
return
}
emailTpls, total, err := service.EmailTplService.Page(ctxUtils.WrapCtx(c), in)
emailTpls, total, err := service.EmailTplService.Page(ctxutils.WrapCtx(c), in)
if err != nil {
response.Error(c, err)
return
......@@ -141,7 +141,7 @@ func (x *emailTplController) ExportCSV(c *gin.Context) {
response.Error(c, err)
return
}
url, err := service.EmailTplService.ExportCSV(ctxUtils.WrapCtx(c), in)
url, err := service.EmailTplService.ExportCSV(ctxutils.WrapCtx(c), in)
if err != nil {
response.Error(c, err)
return
......
......@@ -6,7 +6,7 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/gin/response"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/service"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/types"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils"
ctxutils "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxutils"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
)
......@@ -27,7 +27,7 @@ func (x *emailTplReceiverController) Create(c *gin.Context) {
response.Error(c, err)
return
}
id, err := service.EmailTplReceiverService.Create(ctxUtils.WrapCtx(c), in)
id, err := service.EmailTplReceiverService.Create(ctxutils.WrapCtx(c), in)
if err != nil {
response.Error(c, err)
return
......@@ -40,7 +40,7 @@ func (x *emailTplReceiverController) DeleteByID(c *gin.Context) {
response.Error(c, err)
return
}
if err := service.EmailTplReceiverService.DeleteByID(ctxUtils.WrapCtx(c), in.ID); err != nil {
if err := service.EmailTplReceiverService.DeleteByID(ctxutils.WrapCtx(c), in.ID); err != nil {
response.Error(c, err)
return
}
......@@ -52,7 +52,7 @@ func (x *emailTplReceiverController) UpdateByID(c *gin.Context) {
response.Error(c, err)
return
}
if err := service.EmailTplReceiverService.UpdateByID(ctxUtils.WrapCtx(c), in); err != nil {
if err := service.EmailTplReceiverService.UpdateByID(ctxutils.WrapCtx(c), in); err != nil {
response.Error(c, err)
return
}
......@@ -75,7 +75,7 @@ func (x *emailTplReceiverController) GetByID(c *gin.Context) {
response.Error(c, err)
return
}
emailTplReceiver, err := service.EmailTplReceiverService.GetByID(ctxUtils.WrapCtx(c), in.ID)
emailTplReceiver, err := service.EmailTplReceiverService.GetByID(ctxutils.WrapCtx(c), in.ID)
if err != nil {
response.Error(c, err)
return
......@@ -89,7 +89,7 @@ func (x *emailTplReceiverController) GetByIDs(c *gin.Context) {
response.Error(c, err)
return
}
emailTplReceivers, err := service.EmailTplReceiverService.GetSliceByIDs(ctxUtils.WrapCtx(c), in.IDs)
emailTplReceivers, err := service.EmailTplReceiverService.GetSliceByIDs(ctxutils.WrapCtx(c), in.IDs)
if err != nil {
response.Error(c, err)
return
......@@ -115,7 +115,7 @@ func (x *emailTplReceiverController) Page(c *gin.Context) {
response.Error(c, err)
return
}
emailTplReceivers, total, err := service.EmailTplReceiverService.Page(ctxUtils.WrapCtx(c), in)
emailTplReceivers, total, err := service.EmailTplReceiverService.Page(ctxutils.WrapCtx(c), in)
if err != nil {
response.Error(c, err)
return
......@@ -141,7 +141,7 @@ func (x *emailTplReceiverController) ExportCSV(c *gin.Context) {
response.Error(c, err)
return
}
url, err := service.EmailTplReceiverService.ExportCSV(ctxUtils.WrapCtx(c), in)
url, err := service.EmailTplReceiverService.ExportCSV(ctxutils.WrapCtx(c), in)
if err != nil {
response.Error(c, err)
return
......
......@@ -15,7 +15,7 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/enums"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/service"
xsfUtils "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/xsf_utils"
xsfutils "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/xsf_utils"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
......@@ -166,7 +166,7 @@ func (x *oEmail) SendTLS(ctx context.Context, in *Params) (err error) {
from := fmt.Sprintf("%s<%s>", config.Cfg.Alias, config.Cfg.Addr)
email := models.Email{}
email.ID = xsfUtils.EmailID(ctx)
email.ID = xsfutils.EmailID(ctx)
email.TplID = et.ID
email.UType = in.UType
email.UID = in.UID
......@@ -199,12 +199,12 @@ func (x *oEmail) SendTLS(ctx context.Context, in *Params) (err error) {
}
emailSend := models.EmailSend{}
emailSend.ID = xsfUtils.EmailSendID(ctx)
emailSend.ID = xsfutils.EmailSendID(ctx)
emailSend.EmailID = email.ID
emailSend.State = enums.EmailSend_State_Wait
emailSendLog := models.EmailSendLog{}
emailSendLog.ID = xsfUtils.EmailSendLogID(ctx)
emailSendLog.ID = xsfutils.EmailSendLogID(ctx)
emailSendLog.EmailSendID = emailSend.ID
emailSendLog.State = emailSend.State
......
package models
import (
"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/xtime"
"gorm.io/gorm"
......@@ -33,7 +33,7 @@ func (x *Email) GetTplID() xsf.ID {
return x.TplID
}
func (x *Email) GetTplIDs(rs []*Email) []xsf.ID {
set := setUtils.NewSet[xsf.ID]()
set := setutils.NewSet[xsf.ID]()
for _, r := range rs {
set.Add(r.GetTplID())
}
......
package models
import (
"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/xtime"
"gorm.io/gorm"
......@@ -29,7 +29,7 @@ func (x *EmailReceiver) GetEmailID() xsf.ID {
return x.EmailID
}
func (x *EmailReceiver) GetEmailIDs(rs []*EmailReceiver) []xsf.ID {
set := setUtils.NewSet[xsf.ID]()
set := setutils.NewSet[xsf.ID]()
for _, r := range rs {
set.Add(r.GetEmailID())
}
......
......@@ -2,7 +2,7 @@ package models
import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/enums"
"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/xtime"
"gorm.io/gorm"
......@@ -30,7 +30,7 @@ func (x *EmailSend) GetEmailID() xsf.ID {
return x.EmailID
}
func (x *EmailSend) GetEmailIDs(rs []*EmailSend) []xsf.ID {
set := setUtils.NewSet[xsf.ID]()
set := setutils.NewSet[xsf.ID]()
for _, r := range rs {
set.Add(r.GetEmailID())
}
......
......@@ -2,7 +2,7 @@ package models
import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/enums"
"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/xtime"
"gorm.io/gorm"
......@@ -30,7 +30,7 @@ func (x *EmailSendLog) GetEmailSendID() xsf.ID {
return x.EmailSendID
}
func (x *EmailSendLog) GetEmailSendIDs(rs []*EmailSendLog) []xsf.ID {
set := setUtils.NewSet[xsf.ID]()
set := setutils.NewSet[xsf.ID]()
for _, r := range rs {
set.Add(r.GetEmailSendID())
}
......
package models
import (
"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/xtime"
"gorm.io/gorm"
......@@ -29,7 +29,7 @@ func (x *EmailTplReceiver) GetTplID() xsf.ID {
return x.TplID
}
func (x *EmailTplReceiver) GetTplIDs(rs []*EmailTplReceiver) []xsf.ID {
set := setUtils.NewSet[xsf.ID]()
set := setutils.NewSet[xsf.ID]()
for _, r := range rs {
set.Add(r.GetTplID())
}
......
......@@ -2,9 +2,10 @@ package service
import (
"context"
"github.com/spf13/cast"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils"
"time"
"github.com/spf13/cast"
ctxutils "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxutils"
)
type commonService struct{}
......@@ -18,8 +19,8 @@ const (
)
func csvName(ctx context.Context, tableName string) string {
if ctxUtils.GetCtxUID(ctx) > 0 {
return "csv/" + tableName + "" + cast.ToString(ctxUtils.GetCtxUID(ctx)) + "_" + time.Now().Format("20060102150405") + ".csv"
if ctxutils.GetCtxUID(ctx) > 0 {
return "csv/" + tableName + "" + cast.ToString(ctxutils.GetCtxUID(ctx)) + "_" + time.Now().Format("20060102150405") + ".csv"
}
return "csv/" + tableName + "_" + time.Now().Format("20060102150405") + ".csv"
}
......@@ -9,7 +9,7 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/ecode"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/types"
xsfUtils "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/xsf_utils"
xsfutils "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/xsf_utils"
csvexporter "gitlab.wanzhuangkj.com/tush/xpkg/utils/csv_exporter"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
......@@ -32,7 +32,7 @@ func newEmailService() *emailService {
func (x *emailService) Create(ctx context.Context, in *types.EmailCreateReq) (id xsf.ID, err error) {
email := &models.Email{}
_ = copier.Copy(email, in)
email.ID = xsfUtils.EmailID(ctx)
email.ID = xsfutils.EmailID(ctx)
if err = dao.EmailDao.Create(ctx, email); err != nil {
return 0, err
}
......
......@@ -9,7 +9,7 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/ecode"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/types"
xsfUtils "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/xsf_utils"
xsfutils "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/xsf_utils"
csvexporter "gitlab.wanzhuangkj.com/tush/xpkg/utils/csv_exporter"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
......@@ -32,7 +32,7 @@ func newEmailReceiverService() *emailReceiverService {
func (x *emailReceiverService) Create(ctx context.Context, in *types.EmailReceiverCreateReq) (id xsf.ID, err error) {
emailReceiver := &models.EmailReceiver{}
_ = copier.Copy(emailReceiver, in)
emailReceiver.ID = xsfUtils.EmailReceiverID(ctx)
emailReceiver.ID = xsfutils.EmailReceiverID(ctx)
if err = dao.EmailReceiverDao.Create(ctx, emailReceiver); err != nil {
return 0, err
}
......
......@@ -10,7 +10,7 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/enums"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/types"
xsfUtils "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/xsf_utils"
xsfutils "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/xsf_utils"
csvexporter "gitlab.wanzhuangkj.com/tush/xpkg/utils/csv_exporter"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
......@@ -33,7 +33,7 @@ func newEmailSendService() *emailSendService {
func (x *emailSendService) Create(ctx context.Context, in *types.EmailSendCreateReq) (id xsf.ID, err error) {
emailSend := &models.EmailSend{}
_ = copier.Copy(emailSend, in)
emailSend.ID = xsfUtils.EmailSendID(ctx)
emailSend.ID = xsfutils.EmailSendID(ctx)
if err = dao.EmailSendDao.Create(ctx, emailSend); err != nil {
return 0, err
}
......
......@@ -9,7 +9,7 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/ecode"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/types"
xsfUtils "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/xsf_utils"
xsfutils "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/xsf_utils"
csvexporter "gitlab.wanzhuangkj.com/tush/xpkg/utils/csv_exporter"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
......@@ -32,7 +32,7 @@ func newEmailSendLogService() *emailSendLogService {
func (x *emailSendLogService) Create(ctx context.Context, in *types.EmailSendLogCreateReq) (id xsf.ID, err error) {
emailSendLog := &models.EmailSendLog{}
_ = copier.Copy(emailSendLog, in)
emailSendLog.ID = xsfUtils.EmailSendLogID(ctx)
emailSendLog.ID = xsfutils.EmailSendLogID(ctx)
if err = dao.EmailSendLogDao.Create(ctx, emailSendLog); err != nil {
return 0, err
}
......
......@@ -9,7 +9,7 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/ecode"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/types"
xsfUtils "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/xsf_utils"
xsfutils "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/xsf_utils"
csvexporter "gitlab.wanzhuangkj.com/tush/xpkg/utils/csv_exporter"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
......@@ -32,7 +32,7 @@ func newEmailTplService() *emailTplService {
func (x *emailTplService) Create(ctx context.Context, in *types.EmailTplCreateReq) (id xsf.ID, err error) {
emailTpl := &models.EmailTpl{}
_ = copier.Copy(emailTpl, in)
emailTpl.ID = xsfUtils.EmailTplID(ctx)
emailTpl.ID = xsfutils.EmailTplID(ctx)
if err = dao.EmailTplDao.Create(ctx, emailTpl); err != nil {
return 0, err
}
......
......@@ -9,7 +9,7 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/ecode"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/models"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/types"
xsfUtils "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/xsf_utils"
xsfutils "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/xsf_utils"
csvexporter "gitlab.wanzhuangkj.com/tush/xpkg/utils/csv_exporter"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
......@@ -32,7 +32,7 @@ func newEmailTplReceiverService() *emailTplReceiverService {
func (x *emailTplReceiverService) Create(ctx context.Context, in *types.EmailTplReceiverCreateReq) (id xsf.ID, err error) {
emailTplReceiver := &models.EmailTplReceiver{}
_ = copier.Copy(emailTplReceiver, in)
emailTplReceiver.ID = xsfUtils.EmailTplReceiverID(ctx)
emailTplReceiver.ID = xsfutils.EmailTplReceiverID(ctx)
if err = dao.EmailTplReceiverDao.Create(ctx, emailTplReceiver); err != nil {
return 0, err
}
......
......@@ -7,7 +7,7 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/errcode"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/sgorm/query"
"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/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime"
)
......@@ -24,7 +24,7 @@ func (x *EmailSendCreateReq) Valid() error {
if x.EmailID <= 0 {
return xerror.NewC(errcode.InvalidParams.Code(), "参数[emailID]不合法")
}
if sliceUtils.NotContains(enums.EmailSend_State_Enums_ALL, x.State) {
if sliceutils.NotContains(enums.EmailSend_State_Enums_ALL, x.State) {
return xerror.NewC(errcode.InvalidParams.Code(), "参数[state]不合法")
}
return nil
......@@ -48,7 +48,7 @@ type EmailSendGetByStateReq struct {
}
func (x *EmailSendGetByStateReq) Valid() error {
if sliceUtils.NotContains(enums.EmailSend_State_Enums_ALL, x.State) {
if sliceutils.NotContains(enums.EmailSend_State_Enums_ALL, x.State) {
return xerror.NewC(errcode.InvalidParams.Code(), "参数[state]不合法")
}
return nil
......@@ -68,7 +68,7 @@ func (x *EmailSendUpdateByIDReq) Valid() error {
if x.EmailID <= 0 {
return xerror.NewC(errcode.InvalidParams.Code(), "参数[emailID]不合法")
}
if sliceUtils.NotContains(enums.EmailSend_State_Enums_ALL, x.State) {
if sliceutils.NotContains(enums.EmailSend_State_Enums_ALL, x.State) {
return xerror.NewC(errcode.InvalidParams.Code(), "参数[state]不合法")
}
return nil
......@@ -88,7 +88,7 @@ func (x *EmailSendUpdateByIDsReq) Valid() error {
if x.EmailID <= 0 {
return xerror.NewC(errcode.InvalidParams.Code(), "参数[emailID]不合法")
}
if sliceUtils.NotContains(enums.EmailSend_State_Enums_ALL, x.State) {
if sliceutils.NotContains(enums.EmailSend_State_Enums_ALL, x.State) {
return xerror.NewC(errcode.InvalidParams.Code(), "参数[state]不合法")
}
return nil
......
......@@ -7,7 +7,7 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/errcode"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/sgorm/query"
"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/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime"
)
......@@ -24,7 +24,7 @@ func (x *EmailSendLogCreateReq) Valid() error {
if x.EmailSendID <= 0 {
return xerror.NewC(errcode.InvalidParams.Code(), "参数[emailSendID]不合法")
}
if sliceUtils.NotContains(enums.EmailSendLog_State_Enums_ALL, x.State) {
if sliceutils.NotContains(enums.EmailSendLog_State_Enums_ALL, x.State) {
return xerror.NewC(errcode.InvalidParams.Code(), "参数[state]不合法")
}
return nil
......@@ -48,7 +48,7 @@ type EmailSendLogGetByStateReq struct {
}
func (x *EmailSendLogGetByStateReq) Valid() error {
if sliceUtils.NotContains(enums.EmailSendLog_State_Enums_ALL, x.State) {
if sliceutils.NotContains(enums.EmailSendLog_State_Enums_ALL, x.State) {
return xerror.NewC(errcode.InvalidParams.Code(), "参数[state]不合法")
}
return nil
......@@ -68,7 +68,7 @@ func (x *EmailSendLogUpdateByIDReq) Valid() error {
if x.EmailSendID <= 0 {
return xerror.NewC(errcode.InvalidParams.Code(), "参数[emailSendID]不合法")
}
if sliceUtils.NotContains(enums.EmailSendLog_State_Enums_ALL, x.State) {
if sliceutils.NotContains(enums.EmailSendLog_State_Enums_ALL, x.State) {
return xerror.NewC(errcode.InvalidParams.Code(), "参数[state]不合法")
}
return nil
......@@ -88,7 +88,7 @@ func (x *EmailSendLogUpdateByIDsReq) Valid() error {
if x.EmailSendID <= 0 {
return xerror.NewC(errcode.InvalidParams.Code(), "参数[emailSendID]不合法")
}
if sliceUtils.NotContains(enums.EmailSendLog_State_Enums_ALL, x.State) {
if sliceutils.NotContains(enums.EmailSendLog_State_Enums_ALL, x.State) {
return xerror.NewC(errcode.InvalidParams.Code(), "参数[state]不合法")
}
return nil
......
package xsfUtils
package xsfutils
import (
"context"
"fmt"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils"
ctxutils "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/dxsf"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
)
......@@ -121,7 +121,7 @@ func WithdrawID(ctx context.Context) xsf.ID {
func generateID(ctx context.Context, bizTag string) xsf.ID {
xsf, err := dxsf.GenerateID(ctx, bizTag)
if err != nil {
logger.Error(fmt.Sprintf("GenerateID[%s] failed", bizTag), logger.Err(err), ctxUtils.CtxTraceIDField(ctx))
logger.Error(fmt.Sprintf("GenerateID[%s] failed", bizTag), logger.Err(err), ctxutils.CtxTraceIDField(ctx))
return xsf
}
return xsf
......
......@@ -8,7 +8,7 @@ import (
"time"
"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"
"go.uber.org/zap"
......
......@@ -5,7 +5,7 @@ import (
"fmt"
"github.com/gin-gonic/gin"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils"
ctxutils "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxutils"
)
type CopyHttpReq struct {
......@@ -26,11 +26,11 @@ func SetCopyReq(c *gin.Context, buf *bytes.Buffer) {
copyHttpReq.URL = c.Request.URL.String()
copyHttpReq.Headers = c.Request.Header
copyHttpReq.Body = buf.String()
c.Set(ctxUtils.KeyReqBody, copyHttpReq)
c.Set(ctxutils.KeyReqBody, copyHttpReq)
}
func GetCopyReq(c *gin.Context) *CopyHttpReq {
if val, isExist := c.Get(ctxUtils.KeyReqBody); isExist {
if val, isExist := c.Get(ctxutils.KeyReqBody); isExist {
if req, ok := val.(*CopyHttpReq); ok {
return req
}
......@@ -42,11 +42,11 @@ func SetCopyRsp(c *gin.Context, buf *bytes.Buffer) {
copyHttpRsp := &CopyHttpRsp{}
copyHttpRsp.Headers = c.Writer.Header()
copyHttpRsp.Body = buf.String()
c.Set(ctxUtils.KeyRspBody, copyHttpRsp)
c.Set(ctxutils.KeyRspBody, copyHttpRsp)
}
func GetCopyRsp(c *gin.Context) *CopyHttpRsp {
if val, isExist := c.Get(ctxUtils.KeyRspBody); isExist {
if val, isExist := c.Get(ctxutils.KeyRspBody); isExist {
if rsp, ok := val.(*CopyHttpRsp); ok {
return rsp
}
......@@ -60,11 +60,11 @@ func SetCopyApiReq(c *gin.Context, buf *bytes.Buffer) {
copyHttpReq.URL = c.Request.URL.String()
copyHttpReq.Headers = c.Request.Header
copyHttpReq.Body = buf.String()
c.Set(fmt.Sprintf(ctxUtils.KeyOApiReqBody, ctxUtils.GetGinCtxTraceID(c)), copyHttpReq)
c.Set(fmt.Sprintf(ctxutils.KeyOApiReqBody, ctxutils.GetGinCtxTraceID(c)), copyHttpReq)
}
func GetCopyApiReq(c *gin.Context) *CopyHttpReq {
if val, isExist := c.Get(fmt.Sprintf(ctxUtils.KeyOApiReqBody, ctxUtils.GetGinCtxTraceID(c))); isExist {
if val, isExist := c.Get(fmt.Sprintf(ctxutils.KeyOApiReqBody, ctxutils.GetGinCtxTraceID(c))); isExist {
if req, ok := val.(*CopyHttpReq); ok {
return req
}
......@@ -76,11 +76,11 @@ func SetCopyApiRsp(c *gin.Context, buf *bytes.Buffer) {
copyHttpRsp := &CopyHttpRsp{}
copyHttpRsp.Headers = c.Writer.Header()
copyHttpRsp.Body = buf.String()
c.Set(fmt.Sprintf(ctxUtils.KeyOApiRspBody, ctxUtils.GetGinCtxTraceID(c)), copyHttpRsp)
c.Set(fmt.Sprintf(ctxutils.KeyOApiRspBody, ctxutils.GetGinCtxTraceID(c)), copyHttpRsp)
}
func GetCopyApiRsp(c *gin.Context) *CopyHttpRsp {
if val, isExist := c.Get(fmt.Sprintf(ctxUtils.KeyOApiRspBody, ctxUtils.GetGinCtxTraceID(c))); isExist {
if val, isExist := c.Get(fmt.Sprintf(ctxutils.KeyOApiRspBody, ctxutils.GetGinCtxTraceID(c))); isExist {
if rsp, ok := val.(*CopyHttpRsp); ok {
return rsp
}
......
......@@ -17,9 +17,9 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/httpcli/httpContentType"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
"github.com/duke-git/lancet/v2/retry"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils"
ctxutils "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxutils"
retryutils "gitlab.wanzhuangkj.com/tush/xpkg/utils/retryutils"
)
const defaultTimeout = 30 * time.Second
......@@ -296,7 +296,7 @@ func (x *Request) send(ctx context.Context) {
return
}
if x.reqBody != nil {
if c, _ := ctxUtils.GetGinCtx(ctx); c != nil {
if c, _ := ctxutils.GetGinCtx(ctx); c != nil {
entity.SetCopyApiReq(c, bodyBuf)
}
}
......@@ -305,7 +305,7 @@ func (x *Request) send(ctx context.Context) {
x.request.Header.Add(k, v)
}
}
x.request.Header.Add(ctxUtils.HeaderXRequestIDKey, ctxUtils.CtxRequestID(ctx))
x.request.Header.Add(ctxutils.HeaderXRequestIDKey, ctxutils.CtxRequestID(ctx))
if x.timeout < 1 {
x.timeout = defaultTimeout
}
......@@ -319,18 +319,18 @@ func (x *Request) send(ctx context.Context) {
logger.String("url", x.url),
logger.Any("header", x.request.Header),
logger.String("body", bodyBuf.String()),
ctxUtils.CtxTraceIDField(ctx))
ctxutils.CtxTraceIDField(ctx))
}
st := time.Now()
if x.retryCount > 0 {
x.err = retry.Retry(func() error {
x.err = retryutils.Retry(func() error {
x.pushDo(ctx)
return x.err
},
retry.RetryTimes(uint(x.retryCount)),
retry.RetryWithLinearBackoff(8*time.Second),
retry.Context(ctx),
retryutils.RetryTimes(uint(x.retryCount)),
retryutils.RetryWithLinearBackoff(8*time.Second),
retryutils.Context(ctx),
)
} else {
x.pushDo(ctx)
......@@ -347,7 +347,7 @@ func (x *Request) send(ctx context.Context) {
logger.String("status", x.response.Status),
logger.Any("header", x.Response().Header),
logger.String("body", body),
ctxUtils.CtxTraceIDField(ctx))
ctxutils.CtxTraceIDField(ctx))
}
}
......@@ -400,7 +400,7 @@ func (x *Request) pushDo(ctx context.Context) {
x.response.Status = rsp.Status
x.response.Header = rsp.Header
x.response.StatusCode = rsp.StatusCode
ctxUtils.SetApiCost(ctx, x.response.Header)
ctxutils.SetApiCost(ctx, x.response.Header)
if rsp.Body != nil {
defer rsp.Body.Close()
x.response.body, x.err = io.ReadAll(rsp.Body)
......@@ -409,13 +409,13 @@ func (x *Request) pushDo(ctx context.Context) {
return
}
if len(x.response.body) > 0 {
if c, _ := ctxUtils.GetGinCtx(ctx); c != nil {
if c, _ := ctxutils.GetGinCtx(ctx); c != nil {
entity.SetCopyApiRsp(c, x.response.BodyBuf())
}
}
}
if rsp.StatusCode != http.StatusOK {
x.err = xerror.Newf("http %d, %s ", rsp.StatusCode, rsp.Status)
x.err = errors.New(rsp.Status)
return
}
}
......
......@@ -6,7 +6,7 @@ import (
"github.com/stretchr/testify/assert"
)
func TestUtils(t *testing.T) {
func Testutils(t *testing.T) {
_, err := readFile("notfound")
assert.Error(t, err)
_, err = readFile("utils.go")
......
package convert_utils
package convertutils
import "strconv"
......
......@@ -12,7 +12,7 @@ import (
"github.com/jinzhu/copier"
"gitlab.wanzhuangkj.com/tush/xpkg/config"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/oss"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils"
ctxutils "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxutils"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon/odao"
)
......@@ -126,7 +126,7 @@ func (x *CSVExporter[T]) WriteToReply(ctx context.Context) *CSVExporter[T] {
if x.err != nil {
return x
}
c, err := ctxUtils.GetGinCtx(ctx)
c, err := ctxutils.GetGinCtx(ctx)
if err != nil {
x.err = err
return x
......
package ctxUtils
package ctxutils
import (
"context"
......
package ctxUtils_test
package ctxutils_test
import (
"fmt"
......
package fileUtils
package fileutils
import (
"os"
......
package fileUtils
package fileutils
const (
prefix = "prefix"
......
package hashUtils
package hashutils
import (
"crypto/md5"
......
package map_utils
package maputils
import (
"encoding/json"
......
package redSyncUtils
package redsyncutils
import (
"context"
......@@ -9,7 +9,7 @@ import (
"github.com/redis/go-redis/v9"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils"
ctxutils "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxutils"
)
var (
......@@ -33,12 +33,12 @@ func Sync(ctx context.Context, key string, fn func(), options ...redsync.Option)
}
mutex := redSync.NewMutex(key, options...)
if err := mutex.LockContext(ctx); err != nil {
logger.Error("[redSync]try get lock fail", logger.Any("err", err), ctxUtils.CtxTraceIDField(ctx))
logger.Error("[redSync]try get lock fail", logger.Any("err", err), ctxutils.CtxTraceIDField(ctx))
return xerror.Wrap(err, fmt.Sprintf("[redSync][%s]get lock fail", key))
}
defer func() {
if _, err := mutex.UnlockContext(ctx); err != nil {
logger.Error("[redSync]release lock fail", logger.Any("err", err), ctxUtils.CtxTraceIDField(ctx))
logger.Error("[redSync]release lock fail", logger.Any("err", err), ctxutils.CtxTraceIDField(ctx))
}
}()
fn()
......
package retryUtils
package retryutils
import (
"context"
......@@ -6,9 +6,6 @@ import (
"fmt"
"math"
"math/rand"
"reflect"
"runtime"
"strings"
"time"
)
......@@ -105,9 +102,12 @@ func Retry(retryFunc RetryFunc, opts ...Option) error {
}
}
var i uint
var (
i uint
err error
)
for i < config.retryTimes {
err := retryFunc()
err = retryFunc()
if err != nil {
after := time.After(config.backoffStrategy.CalculateInterval())
select {
......@@ -121,11 +121,11 @@ func Retry(retryFunc RetryFunc, opts ...Option) error {
i++
}
funcPath := runtime.FuncForPC(reflect.ValueOf(retryFunc).Pointer()).Name()
lastSlash := strings.LastIndex(funcPath, "/")
funcName := funcPath[lastSlash+1:]
// funcPath := runtime.FuncForPC(reflect.ValueOf(retryFunc).Pointer()).Name()
// lastSlash := strings.LastIndex(funcPath, "/")
// funcName := funcPath[lastSlash+1:]
return fmt.Errorf("function %s run failed after %d times retry", funcName, i)
return fmt.Errorf("retry[3] faild, %s", err.Error())
}
type BackoffStrategy interface {
......
package setUtils
package setutils
import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xtype"
......
package sliceUtils
package sliceutils
import (
"fmt"
......@@ -6,7 +6,7 @@ import (
"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"
"github.com/jinzhu/copier"
"github.com/spf13/cast"
......@@ -67,7 +67,7 @@ func GetIDs[ID xtype.Key, T IID[ID]](rs []*T) []ID {
if len(rs) == 0 {
return nil
}
set := setUtils.NewSet[ID]()
set := setutils.NewSet[ID]()
for _, r := range rs {
set.Add((*r).GetID())
}
......@@ -173,7 +173,7 @@ func StrMapToSlice[T any](m map[string]*T) []*T {
}
func GetStrMapIDs[ID xtype.Key, T IID[ID]](m map[string]*T) []ID {
st := setUtils.NewSet[ID]()
st := setutils.NewSet[ID]()
for _, v := range m {
st.Add((*v).GetID())
}
......@@ -189,7 +189,7 @@ func IDMapToSlice[ID xtype.Key, T any](m map[ID]*T) []*T {
}
func GetIDMapIDs[ID xtype.Key, T IID[ID]](m map[ID]*T) []ID {
st := setUtils.NewSet[ID]()
st := setutils.NewSet[ID]()
for _, v := range m {
st.Add((*v).GetID())
}
......@@ -205,7 +205,7 @@ func StrMapSliceToSlice[T any](m map[string][]*T) []*T {
}
func GetStrMapSliceIDs[ID xtype.Key, T IID[ID]](m map[string][]*T) []ID {
st := setUtils.NewSet[ID]()
st := setutils.NewSet[ID]()
for _, rs := range m {
for _, r := range rs {
st.Add((*r).GetID())
......@@ -223,7 +223,7 @@ func IDMapSliceToSlice[ID xtype.Key, T any](m map[ID][]*T) []*T {
}
func GetIDMapSliceIDs[ID xtype.Key, T IID[ID]](m map[ID][]*T) []ID {
st := setUtils.NewSet[ID]()
st := setutils.NewSet[ID]()
for _, rs := range m {
for _, r := range rs {
st.Add((*r).GetID())
......@@ -281,7 +281,7 @@ func ArrayUnique[T comparable](array []T) []T {
// if len(rs) == 0 {
// return nil
// }
// set := setUtils.NewSet[id]()
// set := setutils.NewSet[id]()
// for _, r := range rs {
// set.Add((*r).GetID())
// }
......
package stackUtils
package stackutils
import "runtime"
......
package stringUtils
package stringutils
import (
"strings"
......
package uriUtils
package uriutils
import (
"net/url"
......
package uuidUtils
package uuidutils
import (
"strings"
......
package webLogUtils
package weblogutils
import (
"container/list"
......@@ -15,9 +15,9 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/httpcli/entity"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
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/jsonutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/retryUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/retryutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime"
"gorm.io/gorm"
......@@ -51,10 +51,10 @@ func WebLogInterceptor() func(c *gin.Context) {
rsp *entity.CopyHttpRsp
// respCode int
)
ctx := ctxUtils.WrapCtx(c)
ctx := ctxutils.WrapCtx(c)
xApi, ok := api.XApi.M[URL]
if ok {
uid := ctxUtils.GetGinUID(c)
uid := ctxutils.GetGinUID(c)
req = entity.GetCopyReq(c)
if uid > 0 {
defer func() {
......@@ -101,7 +101,7 @@ func Init() {
if l.Len() == 0 {
return nil
}
ctx := context.WithValue(context.Background(), ctxUtils.ContextTraceIDKey, xsf.GenerateID().String())
ctx := context.WithValue(context.Background(), ctxutils.ContextTraceIDKey, xsf.GenerateID().String())
ors := make([]*WebLog, 0, l.Len())
for e := l.Front(); e != nil; e = e.Next() {
le, ok := e.Value.(*WebLog)
......@@ -115,12 +115,12 @@ func Init() {
insertFn := func() error {
if debug {
if err := webLogDaoInstance.CreateSlice(ctx, ors); err != nil {
logger.Error("[webLog] insert fail detail", logger.Err(err), ctxUtils.CtxTraceIDField(ctx))
logger.Error("[webLog] insert fail detail", logger.Err(err), ctxutils.CtxTraceIDField(ctx))
return err
}
} else {
if err := webLogDaoInstance.CreateSliceSilent(ctx, ors); err != nil {
logger.Error("[webLog] insert fail detail", logger.Err(err), ctxUtils.CtxTraceIDField(ctx))
logger.Error("[webLog] insert fail detail", logger.Err(err), ctxutils.CtxTraceIDField(ctx))
return err
}
}
......@@ -130,10 +130,10 @@ func Init() {
if debug {
logger.Info("[webLog]batch insert start")
}
if err := retryUtils.Retry(insertFn, retryUtils.RetryTimes(10), retryUtils.RetryWithLinearBackoff(32*time.Minute)); err != nil {
logger.Error("[webLog] insert fail", logger.String("err", err.Error()), ctxUtils.CtxTraceIDField(ctx))
if err := retryutils.Retry(insertFn, retryutils.RetryTimes(10), retryutils.RetryWithLinearBackoff(32*time.Minute)); err != nil {
logger.Error("[webLog] insert fail", logger.String("err", err.Error()), ctxutils.CtxTraceIDField(ctx))
for _, or := range ors {
logger.Error("[webLog] insert fail detail", logger.String("user_id", or.UID.String()), logger.String("operate", or.Operate), ctxUtils.CtxTraceIDField(ctx))
logger.Error("[webLog] insert fail detail", logger.String("user_id", or.UID.String()), logger.String("operate", or.Operate), ctxutils.CtxTraceIDField(ctx))
}
}
if debug {
......@@ -151,11 +151,11 @@ func Init() {
func AddAsync(ctx context.Context, operate string, req *entity.CopyHttpReq, rsp *entity.CopyHttpRsp) {
wl := &WebLog{}
wl.ID = xsf.GenerateID()
wl.CompanyName = ctxUtils.GetCtxCompanyName(ctx)
wl.CompanyID = ctxUtils.GetCtxCompanyID(ctx)
wl.UID = ctxUtils.GetCtxUID(ctx)
wl.UName = ctxUtils.GetCtxUName(ctx)
wl.TraceID = ctxUtils.GetCtxTid(ctx)
wl.CompanyName = ctxutils.GetCtxCompanyName(ctx)
wl.CompanyID = ctxutils.GetCtxCompanyID(ctx)
wl.UID = ctxutils.GetCtxUID(ctx)
wl.UName = ctxutils.GetCtxUName(ctx)
wl.TraceID = ctxutils.GetCtxTid(ctx)
wl.Operate = operate
wl.CreatedAt = xtime.Now()
if req != nil {
......
......@@ -6,7 +6,7 @@ import (
"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"
)
func Go(ctx context.Context, n int, fn func() error) error {
......
......@@ -13,8 +13,8 @@ import (
"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/ctxUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/setUtils"
ctxutils "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxutils"
setutils "gitlab.wanzhuangkj.com/tush/xpkg/utils/setutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon/ocache"
"golang.org/x/sync/singleflight"
......@@ -125,7 +125,7 @@ func (x *ODao[T]) CreateSliceTx(ctx context.Context, tx *gorm.DB, tbs []*T) erro
}
func (x *ODao[T]) getIDs(tbs []*T) []xsf.ID {
idsSet := setUtils.NewSet[xsf.ID]()
idsSet := setutils.NewSet[xsf.ID]()
for _, r := range tbs {
if id := (*r).GetID(); id > 0 {
idsSet.Add(id)
......@@ -303,13 +303,13 @@ type IListParams interface {
}
func (x *ODao[T]) Page(ctx context.Context, where IPageParams) (rs []*T, total int64, err error) {
if ginCtx, err := ctxUtils.GetGinCtx(ctx); err == nil && ginCtx != nil {
ginCtx.Set(ctxUtils.KeyApiType, "page")
if ginCtx, err := ctxutils.GetGinCtx(ctx); err == nil && ginCtx != nil {
ginCtx.Set(ctxutils.KeyApiType, "page")
pagination := query.Pagination{
PageIndex: where.GetPageIndex(),
PageSize: where.GetPageSize(),
}
ginCtx.Set(ctxUtils.KeyPagination, pagination)
ginCtx.Set(ctxutils.KeyPagination, pagination)
}
condition := x.DB().WithContext(ctx).Model(new(T)).Scopes(x.MakeCondition(where))
if where.Unscoped() {
......@@ -479,14 +479,14 @@ func (x *ODao[T]) GetByID(ctx context.Context, id xsf.ID) (record *T, err error)
if err = x.DB().WithContext(ctx).Where("id = ?", id).First(&record).Error; err != nil {
if xerror.Is(err, ErrRecordNotFound) {
if err = x.Cache.SetPlaceholder(ctx, id); err != nil {
logger.Warn("cache.SetPlaceholder error", logger.Err(err), logger.Any("id", id), ctxUtils.CtxTraceIDField(ctx))
logger.Warn("cache.SetPlaceholder error", logger.Err(err), logger.Any("id", id), ctxutils.CtxTraceIDField(ctx))
}
return nil, nil
}
return nil, xerror.New(err.Error())
}
if err = x.Cache.Set(ctx, id, record, x.Cache.ExpireTime); err != nil {
logger.Warn("cache.Set error", logger.Err(err), logger.Any("id", id), ctxUtils.CtxTraceIDField(ctx))
logger.Warn("cache.Set error", logger.Err(err), logger.Any("id", id), ctxutils.CtxTraceIDField(ctx))
}
return record, nil
})
......@@ -542,7 +542,7 @@ func (x *ODao[T]) GetMapByIDs(ctx context.Context, ids []xsf.ID) (itemMap map[xs
recordIDMap[(*record).GetID()] = struct{}{}
}
if err = x.Cache.MultiSet(ctx, records, x.Cache.ExpireTime); err != nil {
logger.Warn("cache.MultiSet error", logger.Err(err), logger.Any("ids", records), ctxUtils.CtxTraceIDField(ctx))
logger.Warn("cache.MultiSet error", logger.Err(err), logger.Any("ids", records), ctxutils.CtxTraceIDField(ctx))
}
if len(records) == len(missedIDs) {
return itemMap, nil
......@@ -551,7 +551,7 @@ func (x *ODao[T]) GetMapByIDs(ctx context.Context, ids []xsf.ID) (itemMap map[xs
for _, id := range missedIDs {
if _, ok := recordIDMap[id]; !ok {
if err = x.Cache.SetPlaceholder(ctx, id); err != nil {
logger.Warn("cache.SetPlaceholder error", logger.Err(err), logger.Any("id", id), ctxUtils.CtxTraceIDField(ctx))
logger.Warn("cache.SetPlaceholder error", logger.Err(err), logger.Any("id", id), ctxutils.CtxTraceIDField(ctx))
}
}
}
......
package xmodels
import (
"gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/setUtils"
ctxutils "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxutils"
setutils "gitlab.wanzhuangkj.com/tush/xpkg/utils/setutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gorm.io/gorm"
)
func GetUid(tx *gorm.DB) xsf.ID {
ctx := tx.Statement.Context
return ctxUtils.GetCtxUID(ctx)
return ctxutils.GetCtxUID(ctx)
}
type IModel interface {
......@@ -17,7 +17,7 @@ type IModel interface {
}
func GetIDs[T IModel](rs []*T) []xsf.ID {
st := setUtils.NewSet[xsf.ID]()
st := setutils.NewSet[xsf.ID]()
for _, v := range rs {
st.Add((*v).GetID())
}
......@@ -33,7 +33,7 @@ func StrMapToSlice[T any](m map[string]*T) []*T {
}
func GetStrMapIDs[T IModel](m map[string]*T) []xsf.ID {
st := setUtils.NewSet[xsf.ID]()
st := setutils.NewSet[xsf.ID]()
for _, v := range m {
st.Add((*v).GetID())
}
......@@ -49,7 +49,7 @@ func IDMapToSlice[T any](m map[xsf.ID]*T) []*T {
}
func GetIDMapIDs[T IModel](m map[xsf.ID]*T) []xsf.ID {
st := setUtils.NewSet[xsf.ID]()
st := setutils.NewSet[xsf.ID]()
for _, v := range m {
st.Add((*v).GetID())
}
......@@ -73,7 +73,7 @@ func IDMapSliceToSlice[T any](m map[xsf.ID][]*T) []*T {
}
func GetIDMapSliceIDs[T IModel](m map[xsf.ID][]*T) []xsf.ID {
st := setUtils.NewSet[xsf.ID]()
st := setutils.NewSet[xsf.ID]()
for _, rs := range m {
for _, r := range rs {
st.Add((*r).GetID())
......
......@@ -5,7 +5,7 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/xcron/models"
"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/xtime"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
......@@ -36,7 +36,7 @@ func (x *CronJob) ParseJobInfo() {
var CronJobTool = &CronJob{}
func (*CronJob) GetIDs(rs []*CronJob) []xsf.ID {
return sliceUtils.GetIDs(rs)
return sliceutils.GetIDs(rs)
}
func (CronJob) NewFromModel(m *models.CronJob) *CronJob {
......
package biz
import (
"gitlab.wanzhuangkj.com/tush/xpkg/utils/setUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/setutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
"gitlab.wanzhuangkj.com/tush/xpkg/xcron/models"
......@@ -16,10 +16,10 @@ type CronJobLog struct {
var CronJobLogTool = &CronJobLog{}
func (*CronJobLog) GetIDs(rs []*CronJobLog) []xsf.ID {
return sliceUtils.GetIDs(rs)
return sliceutils.GetIDs(rs)
}
func (x *CronJobLog) GetJobIDs(rs []*CronJobLog) []xsf.ID {
set := setUtils.NewSet[xsf.ID]()
set := setutils.NewSet[xsf.ID]()
for _, r := range rs {
set.Add(r.GetJobID())
}
......
......@@ -3,8 +3,8 @@ package biz
import (
"gitlab.wanzhuangkj.com/tush/xpkg/xcron/models"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/setUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/setutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
)
......@@ -17,10 +17,10 @@ type CronJobRecord struct {
var CronJobRecordTool = &CronJobRecord{}
func (*CronJobRecord) GetIDs(rs []*CronJobRecord) []xsf.ID {
return sliceUtils.GetIDs(rs)
return sliceutils.GetIDs(rs)
}
func (x *CronJobRecord) GetJobIDs(rs []*CronJobRecord) []xsf.ID {
set := setUtils.NewSet[xsf.ID]()
set := setutils.NewSet[xsf.ID]()
for _, r := range rs {
set.Add(r.GetJobID())
}
......
......@@ -12,8 +12,8 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/gin/response"
"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/redSyncUtils"
ctxutils "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/redsyncutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon"
"gitlab.wanzhuangkj.com/tush/xpkg/xcron/biz"
......@@ -44,13 +44,13 @@ func (x *cronJobController) StartByCode(c *gin.Context) {
response.Error(c, errors.New("pwd err"))
return
}
ctx := ctxUtils.WrapCtx(c)
job, err := service.CronJobService.GetByJobCode(ctx, req.JobCode, &biz.CronJobOpts{})
ctx := ctxutils.WrapCtx(c)
job, err := service.CronJobService.GetByJobCode(ctx, req.JobCode)
if err != nil {
response.Error(c, err)
return
}
if err := service.CronJobService.StartByID(ctx, job.ID, nil); err != nil {
if err := service.CronJobService.StartByID(ctx, job.ID); err != nil {
response.Error(c, err)
return
}
......@@ -74,13 +74,13 @@ func (x *cronJobController) StopByCode(c *gin.Context) {
response.Error(c, errors.New("pwd err"))
return
}
ctx := ctxUtils.WrapCtx(c)
job, err := service.CronJobService.GetByJobCode(ctx, req.JobCode, &biz.CronJobOpts{})
ctx := ctxutils.WrapCtx(c)
job, err := service.CronJobService.GetByJobCode(ctx, req.JobCode)
if err != nil {
response.Error(c, err)
return
}
if err := service.CronJobService.StopByID(ctx, job.ID, nil); err != nil {
if err := service.CronJobService.StopByID(ctx, job.ID); err != nil {
response.Error(c, err)
return
}
......@@ -98,12 +98,12 @@ func (x *cronJobController) CallOnceByCode(c *gin.Context) {
response.Error(c, errors.New("pwd err"))
return
}
job, err := service.CronJobService.GetByJobCode(ctxUtils.WrapCtx(c), req.JobCode, &biz.CronJobOpts{})
job, err := service.CronJobService.GetByJobCode(ctxutils.WrapCtx(c), req.JobCode)
if err != nil {
response.Error(c, err)
return
}
err = ExecJob(ctxUtils.WrapCtx(c), job)
err = ExecJob(ctxutils.WrapCtx(c), job)
if err != nil {
response.Error(c, err)
return
......@@ -117,7 +117,7 @@ func (x *cronJobController) Create(c *gin.Context) {
response.Error(c, err)
return
}
id, err := service.CronJobService.Create(ctxUtils.WrapCtx(c), in, nil)
id, err := service.CronJobService.Create(ctxutils.WrapCtx(c), in)
if err != nil {
response.Error(c, err)
return
......@@ -131,7 +131,7 @@ func (x *cronJobController) DeleteByID(c *gin.Context) {
response.Error(c, err)
return
}
if err := service.CronJobService.DeleteByID(ctxUtils.WrapCtx(c), in.ID, nil); err != nil {
if err := service.CronJobService.DeleteByID(ctxutils.WrapCtx(c), in.ID); err != nil {
response.Error(c, err)
return
}
......@@ -144,7 +144,7 @@ func (x *cronJobController) UpdateByID(c *gin.Context) {
response.Error(c, err)
return
}
if err := service.CronJobService.UpdateByID(ctxUtils.WrapCtx(c), in, nil); err != nil {
if err := service.CronJobService.UpdateByID(ctxutils.WrapCtx(c), in); err != nil {
response.Error(c, err)
return
}
......@@ -157,7 +157,7 @@ func (x *cronJobController) GetByID(c *gin.Context) {
response.Error(c, err)
return
}
cj, err := service.CronJobService.GetByID(ctxUtils.WrapCtx(c), in.ID, nil)
cj, err := service.CronJobService.GetByID(ctxutils.WrapCtx(c), in.ID)
if err != nil {
response.Error(c, err)
return
......@@ -172,18 +172,18 @@ func (x *cronJobController) StartByID(c *gin.Context) {
response.Error(c, err)
return
}
cj, err := service.CronJobService.GetByID(ctxUtils.WrapCtx(c), in.ID, nil)
cj, err := service.CronJobService.GetByID(ctxutils.WrapCtx(c), in.ID)
if err != nil {
response.Error(c, err)
return
}
ctx := ctxUtils.WrapCtx(c)
job, err := service.CronJobService.GetByJobCode(ctx, cj.JobCode, &biz.CronJobOpts{})
ctx := ctxutils.WrapCtx(c)
job, err := service.CronJobService.GetByJobCode(ctx, cj.JobCode)
if err != nil {
response.Error(c, err)
return
}
if err := service.CronJobService.StartByID(ctx, job.ID, nil); err != nil {
if err := service.CronJobService.StartByID(ctx, job.ID); err != nil {
response.Error(c, err)
return
}
......@@ -203,17 +203,17 @@ func (x *cronJobController) StopByID(c *gin.Context) {
response.Error(c, err)
return
}
cj, err := service.CronJobService.GetByID(ctxUtils.WrapCtx(c), in.ID, nil)
cj, err := service.CronJobService.GetByID(ctxutils.WrapCtx(c), in.ID)
if err != nil {
response.Error(c, err)
return
}
job, err := service.CronJobService.GetByJobCode(ctxUtils.WrapCtx(c), cj.JobCode, &biz.CronJobOpts{})
job, err := service.CronJobService.GetByJobCode(ctxutils.WrapCtx(c), cj.JobCode)
if err != nil {
response.Error(c, err)
return
}
err = ExecJob(ctxUtils.WrapCtx(c), job)
err = ExecJob(ctxutils.WrapCtx(c), job)
if err != nil {
response.Error(c, err)
return
......@@ -226,17 +226,17 @@ func (x *cronJobController) RunByID(c *gin.Context) {
response.Error(c, err)
return
}
cj, err := service.CronJobService.GetByID(ctxUtils.WrapCtx(c), in.ID, nil)
cj, err := service.CronJobService.GetByID(ctxutils.WrapCtx(c), in.ID)
if err != nil {
response.Error(c, err)
return
}
job, err := service.CronJobService.GetByJobCode(ctxUtils.WrapCtx(c), cj.JobCode, &biz.CronJobOpts{})
job, err := service.CronJobService.GetByJobCode(ctxutils.WrapCtx(c), cj.JobCode)
if err != nil {
response.Error(c, err)
return
}
err = ExecJob(ctxUtils.WrapCtx(c), job)
err = ExecJob(ctxutils.WrapCtx(c), job)
if err != nil {
response.Error(c, err)
return
......@@ -250,7 +250,7 @@ func (x *cronJobController) Page(c *gin.Context) {
response.Error(c, err)
return
}
cjs, total, err := service.CronJobService.Page(ctxUtils.WrapCtx(c), in, nil)
cjs, total, err := service.CronJobService.Page(ctxutils.WrapCtx(c), in)
if err != nil {
response.Error(c, err)
return
......@@ -267,9 +267,9 @@ func ExecJob(ctx context.Context, j *biz.CronJob) error {
if !ok {
return errors.New("handler not found")
}
return redSyncUtils.Sync(ctx, j.JobCode, func() {
return redsyncutils.Sync(ctx, j.JobCode, func() {
if err := execTask(ctx, j); err != nil {
logger.Error(fmt.Sprintf("[cronJob][%s] exec err: %s", j.JobName, err.Error()), ctxUtils.CtxTraceIDField(ctx))
logger.Error(fmt.Sprintf("[cronJob][%s] exec err: %s", j.JobName, err.Error()), ctxutils.CtxTraceIDField(ctx))
}
},
redsync.WithExpiry(5*time.Minute),
......@@ -297,13 +297,13 @@ func execTask(ctx context.Context, j *biz.CronJob) error {
if job == nil {
return nil
}
logger.Info(fmt.Sprintf("[cronJob][%s] start", j.JobName), ctxUtils.CtxTraceIDField(ctx))
logger.Info(fmt.Sprintf("[cronJob][%s] start", j.JobName), ctxutils.CtxTraceIDField(ctx))
cronJobRecord := &models.CronJobRecord{JobID: job.ID, BeginTime: xtime.Now()}
_ = dao.CronJobRecordDao.CreateSilent(ctx, cronJobRecord)
_ = dao.CronJobLogDao.CreateSilent(ctx, &models.CronJobLog{JobID: job.ID, Info: "job started."})
defer func() {
logger.Info(fmt.Sprintf("[cronJob][%s] end", j.JobName), logger.Any("cost", time.Since(startTime).String()), ctxUtils.CtxTraceIDField(ctx))
logger.Info(fmt.Sprintf("[cronJob][%s] end", j.JobName), logger.Any("cost", time.Since(startTime).String()), ctxutils.CtxTraceIDField(ctx))
_ = dao.CronJobDao.UpdateByIDSilent(ctx, job.ID, &models.CronJob{State: enums.CronJob_State_NOT_RUNNING})
}()
......
......@@ -7,9 +7,8 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/config"
"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/sliceUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/xcron/biz"
ctxutils "gitlab.wanzhuangkj.com/tush/xpkg/utils/ctxutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceutils"
"gitlab.wanzhuangkj.com/tush/xpkg/xcron/controller"
"gitlab.wanzhuangkj.com/tush/xpkg/xcron/enums"
"gitlab.wanzhuangkj.com/tush/xpkg/xcron/service"
......@@ -32,15 +31,15 @@ func initCron() error {
return nil
}
ctx := context.TODO()
cronJobs, err := service.CronJobService.GetSliceByEnable(ctx, enums.CronJob_Enable_OPEN, &biz.CronJobOpts{})
cronJobs, err := service.CronJobService.GetSliceByEnable(ctx, enums.CronJob_Enable_OPEN)
if err != nil {
return err
}
if len(cronJobs) == 0 {
return nil
}
cronJobIDs := sliceUtils.GetIDs(cronJobs)
_ = service.CronJobService.UpdateByIDs(ctx, &types.CronJobUpdateByIDsReq{IDs: cronJobIDs, State: enums.CronJob_State_NOT_RUNNING}, nil)
cronJobIDs := sliceutils.GetIDs(cronJobs)
_ = service.CronJobService.UpdateByIDs(ctx, &types.CronJobUpdateByIDsReq{IDs: cronJobIDs, State: enums.CronJob_State_NOT_RUNNING})
var tasks []*gocron.Task
for _, job := range cronJobs {
job.ParseJobInfo()
......@@ -50,13 +49,13 @@ func initCron() error {
TimeSpec: job.TimeSpec,
Name: job.JobCode,
Fn: func() {
ctx := context.WithValue(ctx, ctxUtils.HeaderXRequestIDKey, ctxUtils.GenerateTid())
ctx := context.WithValue(ctx, ctxutils.HeaderXRequestIDKey, ctxutils.GenerateTid())
if err := controller.ExecJob(ctx, job); err != nil {
logger.Error(fmt.Sprintf("[cron]exec err: %s", err.Error()), logger.Any("name", job.JobName), logger.Any("timeSpec", job.TimeSpec), logger.Any("args", job.Info), ctxUtils.CtxTraceIDField(ctx))
logger.Error(fmt.Sprintf("[cron]exec err: %s", err.Error()), logger.Any("name", job.JobName), logger.Any("timeSpec", job.TimeSpec), logger.Any("args", job.Info), ctxutils.CtxTraceIDField(ctx))
}
},
}
logger.Info("[cron]add cron job", logger.Any("name", job.JobName), logger.Any("timeSpec", job.TimeSpec), logger.Any("args", job.Info), ctxUtils.CtxTraceIDField(ctx))
logger.Info("[cron]add cron job", logger.Any("name", job.JobName), logger.Any("timeSpec", job.TimeSpec), logger.Any("args", job.Info), ctxutils.CtxTraceIDField(ctx))
tasks = append(tasks, &tsk)
}
}
......@@ -69,6 +68,6 @@ func initCron() error {
if err = gocron.Add(tasks...); err != nil {
return err
}
logger.Info("[cron] initialized", ctxUtils.CtxTraceIDField(ctx))
logger.Info("[cron] initialized", ctxutils.CtxTraceIDField(ctx))
return nil
}
package models
import (
"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/xtime"
"gorm.io/gorm"
......@@ -34,7 +34,7 @@ func (x *CronJobLog) GetJobID() xsf.ID {
return x.JobID
}
func (x *CronJobLog) GetJobIDs(rs []*CronJobLog) []xsf.ID {
set := setUtils.NewSet[xsf.ID]()
set := setutils.NewSet[xsf.ID]()
for _, r := range rs {
set.Add(r.GetJobID())
}
......
package models
import (
"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/xtime"
"gorm.io/gorm"
......@@ -37,7 +37,7 @@ func (x *CronJobRecord) GetJobID() xsf.ID {
return x.JobID
}
func (x *CronJobRecord) GetJobIDs(rs []*CronJobRecord) []xsf.ID {
set := setUtils.NewSet[xsf.ID]()
set := setutils.NewSet[xsf.ID]()
for _, r := range rs {
set.Add(r.GetJobID())
}
......
......@@ -15,7 +15,7 @@ import (
"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"
)
type cronJobService struct {
......@@ -75,7 +75,7 @@ func (x *cronJobService) DeleteByIDs(ctx context.Context, ids []xsf.ID) error {
if err != nil {
return err
}
err = sliceUtils.CompareSlice(ids, cronJobs, ecode.ErrCronJobNotFound)
err = sliceutils.CompareSlice(ids, cronJobs, ecode.ErrCronJobNotFound)
if err != nil {
return err
}
......@@ -122,7 +122,7 @@ func (x *cronJobService) UpdateByIDs(ctx context.Context, req *types.CronJobUpda
if err != nil {
return err
}
err = sliceUtils.CompareSlice(req.IDs, cronJobs, ecode.ErrCronJobNotFound)
err = sliceutils.CompareSlice(req.IDs, cronJobs, ecode.ErrCronJobNotFound)
if err != nil {
return err
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论