about summary refs log tree commit diff stats
path: root/server.go
diff options
context:
space:
mode:
Diffstat (limited to 'server.go')
-rw-r--r--server.go25
1 files changed, 20 insertions, 5 deletions
diff --git a/server.go b/server.go
index 9238c73..b34c933 100644
--- a/server.go
+++ b/server.go
@@ -2,15 +2,18 @@ package main
 
 import (
 	"embed"
+	"errors"
 	"fmt"
 	"io"
 	"log"
 	"net/http"
 	"os"
 	"time"
-	"website/internal/config"
+
+	cfg "website/internal/config"
 
 	"github.com/ansrivas/fiberprometheus/v2"
+	"github.com/ardanlabs/conf/v3"
 	"github.com/getsentry/sentry-go"
 	"github.com/gofiber/contrib/fibersentry"
 	"github.com/gofiber/fiber/v2"
@@ -26,6 +29,13 @@ import (
 	"github.com/shengyanli1982/law"
 )
 
+type Config struct {
+	Production             bool    `conf:"default:false"`
+	Port                   uint16  `conf:"default:3000,short:p"`
+	BaseURL                cfg.URL `conf:"default:http://localhost:3000,short:b"`
+	RedirectOtherHostnames bool    `conf:"default:false"`
+}
+
 // TODO purge CSS
 // TODO HTTP2 https://github.com/dgrr/http2
 
@@ -37,6 +47,15 @@ type Host struct {
 var fs embed.FS
 
 func main() {
+	config := Config{}
+	if help, err := conf.Parse("", &config); err != nil {
+		if errors.Is(err, conf.ErrHelpWanted) {
+			fmt.Println(help)
+			os.Exit(1)
+		}
+		log.Panicf("parsing config: %v", err)
+	}
+
 	err := sentry.Init(sentry.ClientOptions{
 		Dsn:         os.Getenv("SENTRY_DSN"),
 		Release:     os.Getenv("FLY_MACHINE_VERSION"),
@@ -58,10 +77,6 @@ func main() {
 	prometheus.RegisterAt(metricServer, "/metrics")
 
 	hosts := map[string]*Host{}
-	config, err := config.GetConfig()
-	if err != nil {
-		log.Panic("config error", err)
-	}
 
 	internal := fiber.New(fiber.Config{
 		GETOnly:       true,