2019-06-26 22:02:31 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2019-06-27 23:09:17 +03:00
|
|
|
"fmt"
|
|
|
|
"os"
|
2019-06-26 22:02:31 +03:00
|
|
|
|
2020-03-21 01:31:24 +03:00
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
flag "github.com/spf13/pflag"
|
2020-03-21 02:55:06 +03:00
|
|
|
"github.com/wybiral/tube/app"
|
2019-06-26 22:02:31 +03:00
|
|
|
)
|
|
|
|
|
2020-03-21 01:31:24 +03:00
|
|
|
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")
|
|
|
|
}
|
|
|
|
|
2019-06-26 22:02:31 +03:00
|
|
|
func main() {
|
2020-03-21 01:31:24 +03:00
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
if debug {
|
|
|
|
log.SetLevel(log.DebugLevel)
|
|
|
|
} else {
|
|
|
|
log.SetLevel(log.InfoLevel)
|
|
|
|
}
|
|
|
|
|
|
|
|
if version {
|
2020-03-21 15:58:14 +03:00
|
|
|
fmt.Printf("tube version %s", FullVersion())
|
2020-03-21 01:31:24 +03:00
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
|
2019-06-27 23:09:17 +03:00
|
|
|
cfg := app.DefaultConfig()
|
2020-03-21 01:31:24 +03:00
|
|
|
err := cfg.ReadFile(config)
|
2019-06-27 23:09:17 +03:00
|
|
|
if err != nil && !os.IsNotExist(err) {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
a, err := app.NewApp(cfg)
|
2019-06-26 22:02:31 +03:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2019-06-27 23:09:17 +03:00
|
|
|
addr := fmt.Sprintf("%s:%d", cfg.Server.Host, cfg.Server.Port)
|
2019-07-04 00:46:59 +03:00
|
|
|
log.Printf("Local server: http://%s", addr)
|
2019-06-27 23:09:17 +03:00
|
|
|
err = a.Run()
|
2019-06-27 22:22:47 +03:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
2019-06-26 22:02:31 +03:00
|
|
|
}
|
|
|
|
}
|