git.zd.zone/hrpc/hrpc@v0.0.12/utils/location/location.go (about) 1 package location 2 3 import "time" 4 5 type location struct { 6 pst *time.Location 7 bjs *time.Location 8 } 9 10 var loc location 11 12 // New the constructor function but can not be used directly 13 // It must be registered in plugins by plugin.Register() and Loaded at begining 14 func New() *location { 15 loc = location{} 16 return &loc 17 } 18 19 func (l *location) Load() error { 20 var err error 21 l.pst, err = time.LoadLocation("America/Los_Angeles") 22 if err != nil { 23 return err 24 } 25 l.bjs, err = time.LoadLocation("Asia/Chongqing") 26 if err != nil { 27 return err 28 } 29 return nil 30 } 31 32 func (l location) Loaded() bool { 33 return l.bjs != nil 34 } 35 36 func (l location) Name() string { 37 return "hrpc-location" 38 } 39 40 func (l location) DependsOn() []string { 41 return nil 42 } 43 44 // PST can be used for LA 45 func PST() *time.Location { 46 return loc.pst 47 } 48 49 // BJS can be used for CN 50 func BJS() *time.Location { 51 return loc.bjs 52 }