2023-11-16 15:06:59 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
roadsign "code.smartsheep.studio/goatworks/roadsign/pkg"
|
2023-11-17 16:23:40 +00:00
|
|
|
"code.smartsheep.studio/goatworks/roadsign/pkg/administration"
|
2023-11-16 15:06:59 +00:00
|
|
|
"code.smartsheep.studio/goatworks/roadsign/pkg/hypertext"
|
2023-11-17 17:42:04 +00:00
|
|
|
"code.smartsheep.studio/goatworks/roadsign/pkg/sign"
|
2023-11-16 15:06:59 +00:00
|
|
|
"github.com/rs/zerolog"
|
|
|
|
"github.com/rs/zerolog/log"
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"syscall"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
|
|
|
|
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stdout})
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
// Configure settings
|
|
|
|
viper.AddConfigPath(".")
|
|
|
|
viper.AddConfigPath("..")
|
|
|
|
viper.SetConfigName("settings")
|
|
|
|
viper.SetConfigType("yaml")
|
|
|
|
|
|
|
|
// Load settings
|
|
|
|
if err := viper.ReadInConfig(); err != nil {
|
|
|
|
log.Panic().Err(err).Msg("An error occurred when loading settings.")
|
|
|
|
}
|
|
|
|
|
2023-11-17 17:42:04 +00:00
|
|
|
// Load & init sign
|
|
|
|
if err := sign.ReadInConfig(viper.GetString("paths.configs")); err != nil {
|
2023-11-16 15:06:59 +00:00
|
|
|
log.Panic().Err(err).Msg("An error occurred when loading configurations.")
|
|
|
|
} else {
|
2023-11-17 17:42:04 +00:00
|
|
|
log.Debug().Any("sites", sign.C).Msg("All configuration has been loaded.")
|
2023-11-16 15:06:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Init hypertext server
|
2023-11-17 16:23:40 +00:00
|
|
|
hypertext.RunServer(
|
|
|
|
hypertext.InitServer(),
|
|
|
|
viper.GetStringSlice("hypertext.ports"),
|
|
|
|
viper.GetStringSlice("hypertext.secured_ports"),
|
|
|
|
viper.GetString("hypertext.certificate.pem"),
|
|
|
|
viper.GetString("hypertext.certificate.key"),
|
|
|
|
)
|
|
|
|
|
|
|
|
// Init administration server
|
|
|
|
hypertext.RunServer(
|
|
|
|
administration.InitAdministration(),
|
|
|
|
viper.GetStringSlice("hypertext.administration_ports"),
|
|
|
|
viper.GetStringSlice("hypertext.administration_secured_ports"),
|
|
|
|
viper.GetString("hypertext.certificate.administration_pem"),
|
|
|
|
viper.GetString("hypertext.certificate.administration_key"),
|
|
|
|
)
|
2023-11-16 15:06:59 +00:00
|
|
|
|
|
|
|
log.Info().Msgf("RoadSign v%s is started...", roadsign.AppVersion)
|
|
|
|
|
|
|
|
quit := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
|
|
|
|
<-quit
|
|
|
|
|
|
|
|
log.Info().Msgf("RoadSign v%s is quitting...", roadsign.AppVersion)
|
|
|
|
}
|