2020-11-27 14:56:16 +07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-11-30 14:15:27 +07:00
|
|
|
"net/http"
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"github.com/sirupsen/logrus"
|
2020-11-30 15:29:44 +07:00
|
|
|
|
|
|
|
"gitea.teamortix.com/Team-Ortix/blgo/handler"
|
2020-11-27 14:56:16 +07:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2020-11-30 14:15:27 +07:00
|
|
|
created, err := createDefaultConfig()
|
2020-11-30 15:29:44 +07:00
|
|
|
switch {
|
|
|
|
case err != nil:
|
|
|
|
logrus.Fatalf("Error while reading config file: %v", err)
|
|
|
|
case created:
|
2020-11-30 14:15:27 +07:00
|
|
|
logrus.Info("The default config file has been created. Please edit it and re-run the program.")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
cfg, err := parseConfig()
|
|
|
|
if err != nil {
|
2020-11-30 15:29:44 +07:00
|
|
|
logrus.Fatalf("Error while parsing the config: %v", err)
|
2020-11-30 14:15:27 +07:00
|
|
|
}
|
|
|
|
|
2020-11-30 15:29:44 +07:00
|
|
|
logrus.Info("Parsing template theme \"", cfg.ThemeName, "\"...")
|
|
|
|
err = handler.SetTheme(cfg.ThemeName)
|
|
|
|
if err != nil {
|
|
|
|
logrus.Fatalf("Error while parsing templates: %v", err)
|
|
|
|
}
|
|
|
|
logrus.Info("Completed template parsing.")
|
|
|
|
|
|
|
|
http.HandleFunc("/", handler.Handler)
|
|
|
|
|
2020-11-30 14:15:27 +07:00
|
|
|
portStr := strconv.Itoa(cfg.Port)
|
2020-11-30 15:29:44 +07:00
|
|
|
logrus.Info("Listening on port " + portStr + "...")
|
2020-11-30 14:15:27 +07:00
|
|
|
err = http.ListenAndServe(":"+portStr, nil)
|
|
|
|
if err != nil {
|
|
|
|
logrus.Fatalf("error while listen and serving: %v", err)
|
|
|
|
}
|
2020-11-27 14:56:16 +07:00
|
|
|
}
|