package main
import (
"flag"
"fmt"
"github.com/sirupsen/logrus"
starkingdoms_api "gitlab.com/starkingdoms.tk/starkingdoms.tk/starkingdoms-api"
"net/http"
"os"
)
func main() {
configPath := flag.String("config", "config.yml", "File to load configuration file from")
printUsage := flag.Bool("help", false, "Show command line usage")
flag.Parse()
if *printUsage {
flag.Usage()
os.Exit(0)
}
c, err := starkingdoms_api.LoadConfig(*configPath)
if err != nil {
fmt.Printf("failed to load config: %s", err)
os.Exit(1)
}
if c.Logging.Format == "json" {
logrus.SetFormatter(&logrus.JSONFormatter{})
}
logrus.SetLevel(c.Logging.Level)
logrus.WithFields(logrus.Fields{
"host": c.Server.Host,
"port": c.Server.Port,
}).Info("starting http listener")
http.HandleFunc("/ping", func(w http.ResponseWriter, r *http.Request) {
logrus.WithFields(logrus.Fields{
"remote": r.RemoteAddr,
}).Info("GET /ping")
_, err := fmt.Fprintf(w, "pong")
if err != nil {
logrus.Error(err)
}
})
logrus.Error(http.ListenAndServe(c.Server.Host+":"+c.Server.Port, nil))
}