2021-06-08 16:22:14 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
2021-07-13 01:34:56 +03:00
|
|
|
"git.mills.io/prologic/tube/app"
|
2021-06-08 16:22:14 +03:00
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
flag "github.com/spf13/pflag"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
debug bool
|
|
|
|
version bool
|
|
|
|
config string
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
flag.Usage = func() {
|
|
|
|
fmt.Fprintf(os.Stderr, "Usage: %s [options] [file]\n", os.Args[0])
|
|
|
|
flag.PrintDefaults()
|
|
|
|
}
|
|
|
|
|
|
|
|
flag.BoolVarP(&version, "version", "v", false, "display version information")
|
|
|
|
flag.BoolVarP(&debug, "debug", "d", false, "enable debug logging")
|
|
|
|
flag.StringVarP(&config, "config", "c", "config.json", "path to configuration file")
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
if debug {
|
|
|
|
log.SetLevel(log.DebugLevel)
|
|
|
|
} else {
|
|
|
|
log.SetLevel(log.InfoLevel)
|
|
|
|
}
|
|
|
|
|
|
|
|
if version {
|
|
|
|
fmt.Printf("tube version %s", FullVersion())
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
|
|
|
|
cfg := app.DefaultConfig()
|
2023-01-05 15:27:42 +03:00
|
|
|
log.Infof("Reading configuration from %s", config)
|
2021-06-08 16:22:14 +03:00
|
|
|
err := cfg.ReadFile(config)
|
2023-01-05 15:27:42 +03:00
|
|
|
if err != nil {
|
|
|
|
if flag.Lookup("config").Changed {
|
2022-08-01 06:22:17 +03:00
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2023-01-05 15:27:42 +03:00
|
|
|
log.Infof("Reading %s failed. Starting with builtin defaults.", config)
|
2021-06-08 16:22:14 +03:00
|
|
|
}
|
2023-01-05 15:27:42 +03:00
|
|
|
// I'd like to add something like this here: log.Debug("Active config: %s", cfg.toJson())
|
2021-06-08 16:22:14 +03:00
|
|
|
a, err := app.NewApp(cfg)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
addr := fmt.Sprintf("%s:%d", cfg.Server.Host, cfg.Server.Port)
|
|
|
|
log.Printf("Local server: http://%s", addr)
|
|
|
|
err = a.Run()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|