wings/wings.go

75 lines
1.8 KiB
Go
Raw Normal View History

package wings
import (
"flag"
"fmt"
"go.uber.org/zap"
)
// Entrypoint for the Wings application. Configures the logger and checks any
// flags that were passed through in the boot arguments.
func main() {
2019-03-24 22:59:37 +00:00
var configPath = *flag.String("config", "config.yml", "set the location for the configuration file")
var debug = *flag.Bool("debug", false, "pass in order to run wings in debug mode")
flag.Parse()
2019-03-24 22:59:37 +00:00
zap.S().Infof("using configuration file: %s", configPath)
c, err := ReadConfiguration(configPath)
if err != nil {
panic(err)
2019-03-24 22:59:37 +00:00
return
}
if debug {
2019-03-24 22:59:37 +00:00
c.Debug = true
}
printLogo()
if err := configureLogging(c.Debug); err != nil {
panic(err)
}
if c.Debug {
zap.S().Debugw("running in debug mode")
}
2019-03-24 22:59:37 +00:00
zap.S().Infow("configuration initalized", zap.Any("config", c))
}
// Configures the global logger for Zap so that we can call it from any location
// in the code without having to pass around a logger instance.
2019-03-24 22:59:37 +00:00
func configureLogging(debug bool) error {
cfg := zap.NewProductionConfig()
if debug {
cfg = zap.NewDevelopmentConfig()
}
cfg.Encoding = "console"
cfg.OutputPaths = []string{
"stdout",
}
logger, err := cfg.Build()
if err != nil {
return err
}
zap.ReplaceGlobals(logger)
return nil
}
// Prints the wings logo, nothing special here!
func printLogo() {
fmt.Println()
fmt.Println(` ____`)
fmt.Println(`__ Pterodactyl _____/___/_______ _______ ______`)
fmt.Println(`\_____\ \/\/ / / / __ / ___/`)
fmt.Println(` \___\ / / / / /_/ /___ /`)
fmt.Println(` \___/\___/___/___/___/___ /______/`)
fmt.Println(` /_______/ v` + Version)
fmt.Println()
}