调整项目结构,factory只负责暴露方法,不实现业务细节
This commit is contained in:
22
README.md
22
README.md
@@ -295,12 +295,24 @@ http.HandleFunc("/user", commonhttp.HandleFunc(GetUser))
|
||||
```
|
||||
|
||||
### 日期时间
|
||||
```go
|
||||
import "git.toowon.com/jimmy/go-common/datetime"
|
||||
**推荐方式:通过 factory 使用(黑盒模式)**
|
||||
|
||||
datetime.SetDefaultTimeZone(datetime.AsiaShanghai)
|
||||
now := datetime.Now()
|
||||
str := datetime.FormatDateTime(now)
|
||||
```go
|
||||
import "git.toowon.com/jimmy/go-common/factory"
|
||||
|
||||
fac, _ := factory.NewFactoryFromFile("config.json")
|
||||
now := fac.Now("Asia/Shanghai")
|
||||
str := fac.FormatDateTime(now)
|
||||
```
|
||||
|
||||
**或者直接使用 tools 包:**
|
||||
|
||||
```go
|
||||
import "git.toowon.com/jimmy/go-common/tools"
|
||||
|
||||
tools.SetDefaultTimeZone(tools.AsiaShanghai)
|
||||
now := tools.Now()
|
||||
str := tools.FormatDateTime(now)
|
||||
```
|
||||
|
||||
更多示例:[examples目录](./examples/)
|
||||
|
||||
Reference in New Issue
Block a user