调整项目结构,factory只负责暴露方法,不实现业务细节
This commit is contained in:
@@ -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
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user