yoake/cmd/server/server.go

48 lines
1.1 KiB
Go
Raw Permalink Normal View History

2022-11-07 04:45:02 -06:00
package main
import (
"flag"
"log"
"github.com/eternal-flame-AD/yoake/config"
2022-11-11 16:15:22 -06:00
"github.com/eternal-flame-AD/yoake/internal/comm"
"github.com/eternal-flame-AD/yoake/internal/db"
2022-11-07 04:45:02 -06:00
"github.com/eternal-flame-AD/yoake/server"
"github.com/eternal-flame-AD/yoake/server/vault"
"github.com/eternal-flame-AD/yoake/server/webroot"
)
var (
flagConfig = flag.String("c", "config.yml", "config file")
)
func init() {
flag.Parse()
config.ParseConfig(*flagConfig)
2022-11-11 16:15:22 -06:00
comm := comm.InitializeCommProvider()
db, err := db.New(config.Config())
if err != nil {
log.Panicf("failed to initialize database: %v", err)
}
2022-11-07 04:45:02 -06:00
conf := config.Config()
for host, handler := range conf.Hosts {
switch handler {
case "vault":
vault.Init(host)
case "webroot":
2022-11-11 16:15:22 -06:00
webroot.Init(host, comm, db)
2022-11-07 04:45:02 -06:00
default:
log.Panicf("unknown handler for %s: %s", host, handler)
}
}
}
func main() {
listen := config.Config().Listen
if listen.Ssl.Use {
log.Fatalln(server.Server.StartTLS(listen.Addr, listen.Ssl.Cert, listen.Ssl.Key))
} else {
log.Fatalln(server.Server.Start(listen.Addr))
}
}