Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dataType/date.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 调整时区
Expand Down
4 changes: 4 additions & 0 deletions dataType/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions net/http/response/resp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
11 changes: 6 additions & 5 deletions net/http/route/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 != "" {
Expand All @@ -182,7 +183,7 @@ func (ro *Route) loadFile(path string) (http.FileSystem, bool) {
}
}

// 判断hfs是否是空
// 判断 hfs 是否是空
if hfs == nil {
hfs = http.Dir(ro.opt.Root)
}
Expand Down
2 changes: 1 addition & 1 deletion template/template_engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion template/template_engine/enginetools.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 6 additions & 7 deletions tools/sonyflakekit/sonyflake.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"` // 起始时间
}
Expand All @@ -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),
}
)

Expand All @@ -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,
Expand Down