Chore: put log in engine

This commit is contained in:
xjasonlyu
2022-03-27 14:19:36 +08:00
parent 7df522a91f
commit 620d5ac834
2 changed files with 13 additions and 15 deletions

View File

@@ -17,13 +17,17 @@ import (
var _engine = &engine{}
// Start starts the default engine up.
func Start() error {
return _engine.start()
func Start() {
if err := _engine.start(); err != nil {
log.Fatalf("[ENGINE] failed to start: %v", err)
}
}
// Stop shuts the default engine down.
func Stop() error {
return _engine.stop()
func Stop() {
if err := _engine.stop(); err != nil {
log.Fatalf("[ENGINE] failed to stop: %v", err)
}
}
// Insert loads *Key to the default engine.
@@ -120,7 +124,7 @@ func (e *engine) applyStats() error {
go func() {
if err := stats.Start(addr.String(), e.Token); err != nil {
log.Warnf("[STATS] stats start error: %v", err)
log.Warnf("[STATS] failed to start: %v", err)
}
}()
log.Infof("[STATS] serve at: http://%s", addr)

14
main.go
View File

@@ -49,23 +49,17 @@ func main() {
if configFile != "" {
data, err := os.ReadFile(configFile)
if err != nil {
log.Fatalf("Failed to read config %s: %v", configFile, err)
log.Fatalf("Failed to read config file '%s': %v", configFile, err)
}
if err = yaml.Unmarshal(data, key); err != nil {
log.Fatalf("Failed to unmarshal config %s: %v", configFile, err)
log.Fatalf("Failed to unmarshal config file '%s': %v", configFile, err)
}
}
engine.Insert(key)
assert := func(msg string, f func() error) {
if err := f(); err != nil {
log.Fatalf("Failed to %s: %v", msg, err)
}
}
assert("start engine", engine.Start)
defer assert("stop engine", engine.Stop)
engine.Start()
defer engine.Stop()
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)