github.com/kuoss/venti@v0.2.20/pkg/service/status/status.go (about) 1 package status 2 3 import ( 4 "fmt" 5 "os" 6 "runtime" 7 "runtime/debug" 8 "time" 9 10 "github.com/kuoss/venti/pkg/model" 11 ) 12 13 type StatusService struct { 14 buildInfo BuildInfo 15 runtimeInfo RuntimeInfo 16 } 17 18 func New(cfg *model.Config) (*StatusService, error) { 19 cwd, err := os.Getwd() 20 if err != nil { 21 return nil, fmt.Errorf("getwd err: %w", err) 22 } 23 return &StatusService{ 24 buildInfo: BuildInfo{ 25 Version: cfg.AppInfo.Version, 26 Revision: "(TBD)", 27 Branch: "(TBD)", 28 BuildUser: "(TBD)", 29 BuildDate: "(TBD)", 30 GoVersion: runtime.Version(), 31 }, 32 runtimeInfo: RuntimeInfo{ 33 StartTime: time.Now(), 34 CWD: cwd, 35 ReloadConfigSuccess: true, 36 LastConfigTime: time.Now(), 37 CorruptionCount: -1, 38 GoroutineCount: -1, 39 GOMAXPROCS: runtime.GOMAXPROCS(0), 40 GOMEMLIMIT: -1, 41 GOGC: os.Getenv("GOGC"), 42 GODEBUG: os.Getenv("GODEBUG"), 43 StorageRetention: "N/A", 44 }, 45 }, nil 46 } 47 48 func (s *StatusService) BuildInfo() BuildInfo { 49 return s.buildInfo 50 } 51 52 func (s *StatusService) RuntimeInfo() RuntimeInfo { 53 s.runtimeInfo.GOMEMLIMIT = debug.SetMemoryLimit(-1) 54 s.runtimeInfo.GoroutineCount = runtime.NumGoroutine() 55 return s.runtimeInfo 56 }