app.go 842 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. }
  26. // URL 传参 path 拼接接点的 URL
  27. func URL(path string) string {
  28. return config.GetString("app.url") + path
  29. }
  30. // V1URL 拼接 v1 版本的 URL
  31. func V1URL(path string) string {
  32. return URL("/v1/" + path)
  33. }