mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-03 16:00:25 +08:00
refactor: cast包替换
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"cmp"
|
||||
sysapp "mayfly-go/internal/sys/application"
|
||||
"mayfly-go/pkg/utils/stringx"
|
||||
|
||||
"github.com/may-fly/cast"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -28,8 +29,8 @@ func GetAccountLoginSecurity() *AccountLoginSecurity {
|
||||
als := new(AccountLoginSecurity)
|
||||
als.UseCaptcha = c.ConvBool(jm["useCaptcha"], true)
|
||||
als.UseOtp = c.ConvBool(jm["useOtp"], false)
|
||||
als.LoginFailCount = cast.ToIntD(jm["loginFailCount"], 5)
|
||||
als.LoginFailMin = cast.ToIntD(jm["loginFailMin"], 10)
|
||||
als.LoginFailCount = cmp.Or(cast.ToInt(jm["loginFailCount"]), 5)
|
||||
als.LoginFailMin = cmp.Or(cast.ToInt(jm["loginFailMin"]), 10)
|
||||
otpIssuer := jm["otpIssuer"]
|
||||
if otpIssuer == "" {
|
||||
otpIssuer = "mayfly-go"
|
||||
|
||||
@@ -29,7 +29,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/may-fly/cast"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
type Db struct {
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
"mayfly-go/pkg/utils/stringx"
|
||||
"strings"
|
||||
|
||||
"github.com/may-fly/cast"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
type DataSyncTask struct {
|
||||
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
"mayfly-go/pkg/utils/collx"
|
||||
"strings"
|
||||
|
||||
"github.com/may-fly/cast"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
type Instance struct {
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"mayfly-go/pkg/req"
|
||||
"mayfly-go/pkg/utils/collx"
|
||||
|
||||
"github.com/may-fly/cast"
|
||||
"github.com/spf13/cast"
|
||||
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
"mayfly-go/pkg/req"
|
||||
"strings"
|
||||
|
||||
"github.com/may-fly/cast"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
type DbTransferTask struct {
|
||||
|
||||
@@ -23,7 +23,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/may-fly/cast"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
type DataSyncTask interface {
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
|
||||
"github.com/may-fly/cast"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -29,7 +29,7 @@ func GetDbms() *Dbms {
|
||||
dbmsConf := new(Dbms)
|
||||
dbmsConf.QuerySqlSave = c.ConvBool(jm["querySqlSave"], false)
|
||||
dbmsConf.MaxResultSet = cast.ToInt(jm["maxResultSet"])
|
||||
dbmsConf.SqlExecTl = cast.ToIntD(jm["sqlExecTl"], 60)
|
||||
dbmsConf.SqlExecTl = cmp.Or(cast.ToInt(jm["sqlExecTl"]), 60)
|
||||
return dbmsConf
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/may-fly/cast"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"mayfly-go/pkg/utils/stringx"
|
||||
"strings"
|
||||
|
||||
"github.com/may-fly/cast"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"mayfly-go/pkg/utils/stringx"
|
||||
"strings"
|
||||
|
||||
"github.com/may-fly/cast"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"mayfly-go/pkg/utils/stringx"
|
||||
"strings"
|
||||
|
||||
"github.com/may-fly/cast"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"mayfly-go/pkg/utils/collx"
|
||||
"strings"
|
||||
|
||||
"github.com/may-fly/cast"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
type SQLGenerator struct {
|
||||
|
||||
@@ -8,8 +8,8 @@ import (
|
||||
"mayfly-go/pkg/utils/collx"
|
||||
"strings"
|
||||
|
||||
"github.com/may-fly/cast"
|
||||
go_ora "github.com/sijms/go-ora/v2"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"mayfly-go/pkg/utils/stringx"
|
||||
"strings"
|
||||
|
||||
"github.com/may-fly/cast"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
// ---------------------------------- DM元数据 -----------------------------------
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"mayfly-go/pkg/utils/collx"
|
||||
"strings"
|
||||
|
||||
"github.com/may-fly/cast"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"mayfly-go/internal/db/dbm/dbi"
|
||||
"time"
|
||||
|
||||
"github.com/may-fly/cast"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
type PgsqlDialect struct {
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"mayfly-go/pkg/utils/stringx"
|
||||
"strings"
|
||||
|
||||
"github.com/may-fly/cast"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/may-fly/cast"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
mysqlparser "mayfly-go/internal/db/dbm/sqlparser/mysql/antlr4"
|
||||
"mayfly-go/internal/db/dbm/sqlparser/sqlstmt"
|
||||
|
||||
"github.com/may-fly/cast"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
type MysqlVisitor struct {
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
pgparser "mayfly-go/internal/db/dbm/sqlparser/pgsql/antlr4"
|
||||
"mayfly-go/internal/db/dbm/sqlparser/sqlstmt"
|
||||
|
||||
"github.com/may-fly/cast"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
type PgsqlVisitor struct {
|
||||
|
||||
@@ -19,7 +19,7 @@ import (
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/may-fly/cast"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
type Instance struct {
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/may-fly/cast"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
type File interface {
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"cmp"
|
||||
sysapp "mayfly-go/internal/sys/application"
|
||||
|
||||
"github.com/may-fly/cast"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -19,6 +20,6 @@ func GetFileConfig() *FileConfig {
|
||||
jm := c.GetJsonMap()
|
||||
|
||||
fc := new(FileConfig)
|
||||
fc.BasePath = cast.ToStringD(jm["basePath"], "./file")
|
||||
fc.BasePath = cmp.Or(cast.ToString(jm["basePath"]), "./file")
|
||||
return fc
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
"mayfly-go/pkg/utils/structx"
|
||||
"strings"
|
||||
|
||||
"github.com/may-fly/cast"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
type Procdef struct {
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"mayfly-go/pkg/global"
|
||||
"strings"
|
||||
|
||||
"github.com/may-fly/cast"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
/******************* 用户任务节点 *******************/
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"mayfly-go/pkg/model"
|
||||
"mayfly-go/pkg/utils/stringx"
|
||||
|
||||
"github.com/may-fly/cast"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
type ProcinstTask interface {
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"mayfly-go/pkg/utils/stringx"
|
||||
"strings"
|
||||
|
||||
"github.com/may-fly/cast"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
// 流程定义信息
|
||||
|
||||
@@ -28,7 +28,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/may-fly/cast"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
type Machine struct {
|
||||
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
"mayfly-go/pkg/scheduler"
|
||||
"mayfly-go/pkg/utils/collx"
|
||||
|
||||
"github.com/may-fly/cast"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
type MachineCronJob struct {
|
||||
|
||||
@@ -30,8 +30,8 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/may-fly/cast"
|
||||
"github.com/pkg/sftp"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
type MachineFile struct {
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
"mayfly-go/pkg/utils/stringx"
|
||||
"strings"
|
||||
|
||||
"github.com/may-fly/cast"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
type MachineScript struct {
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"cmp"
|
||||
sysapp "mayfly-go/internal/sys/application"
|
||||
"mayfly-go/pkg/logx"
|
||||
"mayfly-go/pkg/utils/bytex"
|
||||
|
||||
"github.com/may-fly/cast"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -38,11 +39,11 @@ func GetMachine() *Machine {
|
||||
}
|
||||
}
|
||||
mc.UploadMaxFileSize = uploadMaxFileSize
|
||||
mc.TermOpSaveDays = cast.ToIntD(jm["termOpSaveDays"], 30)
|
||||
mc.TermOpSaveDays = cmp.Or(cast.ToInt(jm["termOpSaveDays"]), 30)
|
||||
// guacd
|
||||
mc.GuacdHost = cast.ToString(jm["guacdHost"])
|
||||
mc.GuacdPort = cast.ToIntD(jm["guacdPort"], 4822)
|
||||
mc.GuacdFilePath = cast.ToStringD(jm["guacdFilePath"], "")
|
||||
mc.GuacdPort = cmp.Or(cast.ToInt(jm["guacdPort"]), 4822)
|
||||
mc.GuacdFilePath = cast.ToString(jm["guacdFilePath"])
|
||||
|
||||
return mc
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
"mayfly-go/pkg/logx"
|
||||
"strings"
|
||||
|
||||
"github.com/may-fly/cast"
|
||||
"github.com/pkg/sftp"
|
||||
"github.com/spf13/cast"
|
||||
"golang.org/x/crypto/ssh"
|
||||
)
|
||||
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
package mcm
|
||||
|
||||
import (
|
||||
"cmp"
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"mayfly-go/pkg/errorx"
|
||||
"mayfly-go/pkg/logx"
|
||||
|
||||
"github.com/may-fly/cast"
|
||||
"github.com/spf13/cast"
|
||||
|
||||
"strings"
|
||||
"time"
|
||||
@@ -258,15 +259,15 @@ func parseMsg(msg []byte) (*WsMsg, error) {
|
||||
}
|
||||
|
||||
// 获取消息类型, 提取第一个 "|" 之前的内容
|
||||
msgType := cast.ToIntD(msgStr[:index], Ping)
|
||||
msgType := cmp.Or(cast.ToInt(msgStr[:index]), Ping)
|
||||
// 其余内容则为消息内容
|
||||
msgContent := msgStr[index+1:]
|
||||
|
||||
wsMsg := &WsMsg{Type: msgType, Msg: msgContent}
|
||||
if msgType == Resize {
|
||||
rowsAndCols := strings.Split(msgContent, MsgSplit)
|
||||
wsMsg.Rows = cast.ToIntD(rowsAndCols[0], 80)
|
||||
wsMsg.Cols = cast.ToIntD(rowsAndCols[1], 80)
|
||||
wsMsg.Rows = cmp.Or(cast.ToInt(rowsAndCols[0]), 80)
|
||||
wsMsg.Cols = cmp.Or(cast.ToInt(rowsAndCols[1]), 80)
|
||||
}
|
||||
return wsMsg, nil
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/may-fly/cast"
|
||||
"github.com/spf13/cast"
|
||||
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo/options"
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"mayfly-go/pkg/req"
|
||||
"strings"
|
||||
|
||||
"github.com/may-fly/cast"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
type MsgChannel struct {
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
"mayfly-go/pkg/utils/jsonx"
|
||||
"strings"
|
||||
|
||||
"github.com/may-fly/cast"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
type MsgTmpl struct {
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"net/smtp"
|
||||
"strings"
|
||||
|
||||
"github.com/may-fly/cast"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
type EmailSender struct{}
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
|
||||
"time"
|
||||
|
||||
"github.com/may-fly/cast"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
type feishuBotMsgReq struct {
|
||||
|
||||
@@ -20,8 +20,8 @@ import (
|
||||
"mayfly-go/pkg/utils/stringx"
|
||||
"strings"
|
||||
|
||||
"github.com/may-fly/cast"
|
||||
"github.com/redis/go-redis/v9"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
type Redis struct {
|
||||
|
||||
@@ -24,8 +24,8 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/may-fly/cast"
|
||||
"github.com/redis/go-redis/v9"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
type Redis interface {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package rdm
|
||||
|
||||
import "github.com/may-fly/cast"
|
||||
import "github.com/spf13/cast"
|
||||
|
||||
// write cmd
|
||||
var writeCmd = map[string]string{
|
||||
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/may-fly/cast"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"mayfly-go/pkg/utils/collx"
|
||||
"strings"
|
||||
|
||||
"github.com/may-fly/cast"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
type Role struct {
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package entity
|
||||
|
||||
import (
|
||||
"cmp"
|
||||
"encoding/json"
|
||||
"mayfly-go/pkg/model"
|
||||
|
||||
"github.com/may-fly/cast"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -50,7 +51,7 @@ func (c *Config) IntValue(defaultValue int) int {
|
||||
if c.Id == 0 {
|
||||
return defaultValue
|
||||
}
|
||||
return cast.ToIntD(c.Value, defaultValue)
|
||||
return cmp.Or(cast.ToInt(c.Value), defaultValue)
|
||||
}
|
||||
|
||||
// 转换配置中的值为bool类型(默认"1"或"true"为true,其他为false)
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"mayfly-go/pkg/req"
|
||||
"strings"
|
||||
|
||||
"github.com/may-fly/cast"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
type ResourceAuthCert struct {
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
"mayfly-go/pkg/utils/collx"
|
||||
"strings"
|
||||
|
||||
"github.com/may-fly/cast"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
type Team struct {
|
||||
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/may-fly/cast"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
type TagTree interface {
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/may-fly/cast"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
func TestTagPath(t *testing.T) {
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"mayfly-go/pkg/utils/collx"
|
||||
"strings"
|
||||
|
||||
"github.com/may-fly/cast"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
type TypePath string
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"mayfly-go/pkg/utils/collx"
|
||||
"strings"
|
||||
|
||||
"github.com/may-fly/cast"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
// 标签树
|
||||
|
||||
Reference in New Issue
Block a user