调整项目结构,factory只负责暴露方法,不实现业务细节

This commit is contained in:
2025-12-07 00:04:01 +08:00
parent b66f345281
commit 339920a940
23 changed files with 2165 additions and 1231 deletions

View File

@@ -4,7 +4,7 @@ import (
"context"
"net/http"
"git.toowon.com/jimmy/go-common/datetime"
"git.toowon.com/jimmy/go-common/tools"
)
// TimezoneKey context中存储时区的key
@@ -14,7 +14,7 @@ type timezoneKey struct{}
const TimezoneHeaderName = "X-Timezone"
// DefaultTimezone 默认时区
const DefaultTimezone = datetime.AsiaShanghai
const DefaultTimezone = tools.AsiaShanghai
// GetTimezoneFromContext 从context中获取时区
func GetTimezoneFromContext(ctx context.Context) string {
@@ -38,7 +38,7 @@ func Timezone(next http.Handler) http.Handler {
}
// 验证时区是否有效
if _, err := datetime.GetLocation(timezone); err != nil {
if _, err := tools.GetLocation(timezone); err != nil {
// 如果时区无效,使用默认时区
timezone = DefaultTimezone
}
@@ -53,7 +53,7 @@ func Timezone(next http.Handler) http.Handler {
// defaultTimezone: 默认时区,如果未指定则使用 AsiaShanghai
func TimezoneWithDefault(defaultTimezone string) func(http.Handler) http.Handler {
// 验证默认时区是否有效
if _, err := datetime.GetLocation(defaultTimezone); err != nil {
if _, err := tools.GetLocation(defaultTimezone); err != nil {
defaultTimezone = DefaultTimezone
}
@@ -68,7 +68,7 @@ func TimezoneWithDefault(defaultTimezone string) func(http.Handler) http.Handler
}
// 验证时区是否有效
if _, err := datetime.GetLocation(timezone); err != nil {
if _, err := tools.GetLocation(timezone); err != nil {
// 如果时区无效,使用默认时区
timezone = defaultTimezone
}
@@ -79,4 +79,3 @@ func TimezoneWithDefault(defaultTimezone string) func(http.Handler) http.Handler
})
}
}