diff --git a/dataType/date.go b/dataType/date.go index e91c91a..d57ddd8 100644 --- a/dataType/date.go +++ b/dataType/date.go @@ -167,7 +167,7 @@ func (c CustomTime) ToTime() time.Time { // noinspection all func (c CustomTime) IsZero() bool { - return c.IsZero() + return c.Time.IsZero() } // AdjustTimezoneIfNeeded 调整时区 diff --git a/dataType/string.go b/dataType/string.go index aedace1..f17f3b7 100644 --- a/dataType/string.go +++ b/dataType/string.go @@ -12,6 +12,10 @@ import ( type String string +func NewString(s string) String { + return String(s) +} + // noinspection all func (s *String) Scan(val interface{}) (err error) { return HelperStringScan(val, s) diff --git a/net/http/response/resp.go b/net/http/response/resp.go index 010d6e3..e02f9d9 100644 --- a/net/http/response/resp.go +++ b/net/http/response/resp.go @@ -28,6 +28,10 @@ func ReqError(r *http.Request, i ...any) { log.Println(append(msg, i...)...) } +func RespHtml(w http.ResponseWriter) { + w.Header().Set("Content-Type", "text/html; charset=utf-8") +} + func RespJson(w http.ResponseWriter) { w.Header().Set("Content-Type", "application/json; charset=utf-8") } diff --git a/net/http/route/file.go b/net/http/route/file.go index 6f98d81..0366623 100644 --- a/net/http/route/file.go +++ b/net/http/route/file.go @@ -111,6 +111,10 @@ func (ro *Route) Index(w http.ResponseWriter, r *http.Request) { } func (ro *Route) singleFile(w http.ResponseWriter, r *http.Request, path string) { + // 检查最后一个字符 是不是 / + if len(path) > 0 && path[len(path)-1] == '/' { + path = path + ro.opt.Index + } hfs, enableEmbed := ro.loadFile(path) // 获取文件 f, d, err := HttpFS(hfs, path) @@ -167,10 +171,7 @@ func (ro *Route) loadFile(path string) (http.FileSystem, bool) { hfs http.FileSystem enableEmbed = false ) - // 检查最后一个字符 是不是 / - if len(path) > 0 && path[len(path)-1] == '/' { - path = path + ro.opt.Index - } + for _, cache := range ro.embed { if strings.HasPrefix(path, cache.Search) { if cache.Prefix != "" { @@ -182,7 +183,7 @@ func (ro *Route) loadFile(path string) (http.FileSystem, bool) { } } - // 判断hfs是否是空 + // 判断 hfs 是否是空 if hfs == nil { hfs = http.Dir(ro.opt.Root) } diff --git a/template/template_engine/engine.go b/template/template_engine/engine.go index 695fdfa..9d2979a 100644 --- a/template/template_engine/engine.go +++ b/template/template_engine/engine.go @@ -124,7 +124,7 @@ func (e *Engine) loadLayout() error { return err } } - // 先打开layout目录 + // 先打开 layout 目录 subFs, err = fs.Sub(subFs, e.layoutDir) if err != nil { return err diff --git a/template/template_engine/enginetools.go b/template/template_engine/enginetools.go index bdb9c6d..e21c2a4 100644 --- a/template/template_engine/enginetools.go +++ b/template/template_engine/enginetools.go @@ -44,7 +44,7 @@ func builtinFuncMap() template.FuncMap { return tools.Any2string(v) }, "toInt": func(v any) int64 { - return tools.MustAny2int[int64](v) + return tools.MustAny2Int[int64](v) }, "toFloat": func(v any) float64 { n, _ := tools.Any2float64(v) diff --git a/tools/sonyflakekit/sonyflake.go b/tools/sonyflakekit/sonyflake.go index a46fc26..3d4d5fb 100644 --- a/tools/sonyflakekit/sonyflake.go +++ b/tools/sonyflakekit/sonyflake.go @@ -5,13 +5,12 @@ import ( "sync" "time" - "github.com/helays/utils/v2/logger/ulogs" "github.com/sony/sonyflake/v2" ) type SonyFlake struct { BitsSequence int `json:"bits_sequence" yaml:"bits_sequence" ini:"bits_sequence"` // 序列号位数 - BitsMachineID int `json:"bits_machine_id" yaml:"bits_machine_id" ini:"bits_machine_id"` // 机器ID位数 + BitsMachineID int `json:"bits_machine_id" yaml:"bits_machine_id" ini:"bits_machine_id"` // 机器 ID 位数 TimeUnit time.Duration `json:"time_unit" yaml:"time_unit" ini:"time_unit"` // 时间单位 StartTime time.Time `json:"start_time" yaml:"start_time" ini:"start_time"` // 起始时间 } @@ -23,10 +22,10 @@ var ( idInstance *IDGenerator idOnce sync.Once cfg = &SonyFlake{ - BitsSequence: 12, - BitsMachineID: 10, - TimeUnit: time.Millisecond, - StartTime: time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC), + BitsSequence: 8, + BitsMachineID: 16, + TimeUnit: 10 * time.Millisecond, + StartTime: time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC), } ) @@ -44,7 +43,7 @@ func NewIDGenerator() *IDGenerator { StartTime: cfg.StartTime, } if sf, err := sonyflake.New(settings); err != nil { - ulogs.DieCheckerr(err, "sonyflake初始化失败") + panic(fmt.Errorf("sonyflake初始化失败: %v", err)) } else { idInstance = &IDGenerator{ sf: sf,