gyrogpsc/cmd/server/server.go

75 lines
1.8 KiB
Go

package main
import (
"git.timovolkmann.de/gyrogpsc/core"
"git.timovolkmann.de/gyrogpsc/storage"
"git.timovolkmann.de/gyrogpsc/web"
"github.com/sirupsen/logrus"
"github.com/spf13/viper"
"os"
"time"
)
func main() {
conf := configurationFromFile()
logrus.Debug(conf)
repo := storage.NewRepository(conf)
disp := core.NewDispatcher()
service := core.TrackingService(conf, repo, disp)
go func() {
service.StartPipeline(core.TCP, core.SERIAL)
time.Sleep(5 * time.Second)
service.StartRecord()
time.Sleep(10 * time.Second)
service.StopRecord()
time.Sleep(5 * time.Second)
service.StartPipeline(core.TCP, core.SERIAL)
time.Sleep(5 * time.Second)
service.StartRecord()
time.Sleep(60 * time.Second)
service.StopRecord()
time.Sleep(2 * time.Second)
service.StopAll()
time.Sleep(5 * time.Second)
//pprof.StopCPUProfile()
os.Exit(0)
}()
web.CreateServer(service, disp, conf)
}
func configurationFromFile() *core.Configuration {
viper.SetDefault("collectors.porttcp", ":3010")
viper.SetDefault("collectors.portserial", "/dev/tty.usbmodem14201")
viper.SetDefault("webserver.port", ":3011")
viper.SetDefault("pipeline.publishIntervalMs", 50)
viper.SetDefault("pipeline.syncUpdateIntervalMs", 494)
viper.SetDefault("debuglevel", "INFO")
viper.SetConfigName("gpsconfig") // name of config file (without extension)
viper.SetConfigType("yaml")
viper.AddConfigPath(".")
viper.AddConfigPath("./../../")
if err := viper.ReadInConfig(); err != nil {
logrus.Warn("couldn't find config file. using standard configuration")
}
c := core.Configuration{}
if err := viper.Unmarshal(&c); err != nil {
logrus.Debug("couldn't load config...")
logrus.Error(err)
}
lvl, err := logrus.ParseLevel(c.Debuglevel)
if err != nil {
logrus.Error(err)
}
logrus.SetLevel(lvl)
return &c
}