| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- // Package app 应用信息包
- package app
- import (
- "time"
- "github.com/runningwater/gohub/pkg/config"
- )
- func IsLocal() bool {
- // 判断是否是本地环境
- return config.Get("app.env") == "local"
- }
- func IsProduction() bool {
- return config.Get("app.env") == "production"
- }
- func IsTesting() bool {
- return config.Get("app.env") == "testing"
- }
- // TimenowInTimezone 获取当前时间, 支持时区
- func TimenowInTimezone() time.Time {
- timezone := config.GetString("app.timezone")
- if timezone == "" {
- timezone = "Asia/Shanghai"
- }
- chinaTimeZone, _ := time.LoadLocation(timezone)
- return time.Now().In(chinaTimeZone)
- }
- // URL 传参 path 拼接接点的 URL
- func URL(path string) string {
- return config.GetString("app.url") + path
- }
- // V1URL 拼接 v1 版本的 URL
- func V1URL(path string) string {
- return URL("/v1/" + path)
- }
|