app.go 630 B

12345678910111213141516171819202122232425262728293031
  1. // package app 应用信息包
  2. package app
  3. import (
  4. "time"
  5. "github.com/runningwater/gohub/pkg/config"
  6. )
  7. func IsLocal() bool {
  8. // 判断是否是本地环境
  9. return config.Get("app.env") == "local"
  10. }
  11. func IsProduction() bool {
  12. return config.Get("app.env") == "production"
  13. }
  14. func IsTesting() bool {
  15. return config.Get("app.env") == "testing"
  16. }
  17. // TimenowInTimezone 获取当前时间, 支持时区
  18. func TimenowInTimezone() time.Time {
  19. timezone := config.GetString("app.timezone")
  20. if timezone == "" {
  21. timezone = "Asia/Shanghai"
  22. }
  23. chinaTimeZone, _ := time.LoadLocation(timezone)
  24. return time.Now().In(chinaTimeZone)
  25. }