about summary refs log tree commit diff stats
path: root/cmd/server/main.go
blob: b6817d80a8e7842ec03bec575ac49b0b7f74827a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main

import (
	"fmt"
	"log"
	"log/slog"
	"os"
	cfg "website/internal/config"

	"github.com/ardanlabs/conf/v3"
	"github.com/pkg/errors"
)

var (
	CommitSHA string
	ShortSHA  string
)

type Config struct {
	Production             bool    `conf:"default:false"`
	ListenAddress          string  `conf:"default:localhost"`
	Port                   uint16  `conf:"default:3000,short:p"`
	BaseURL                cfg.URL `conf:"default:http://localhost:3000,short:b"`
	RedirectOtherHostnames bool    `conf:"default:false"`
}

func main() {
	if os.Getenv("DEBUG") != "" {
		slog.SetLogLoggerLevel(slog.LevelDebug)
	}

	runtimeConfig := Config{}
	help, err := conf.Parse("", &runtimeConfig)
	if err != nil {
		if errors.Is(err, conf.ErrHelpWanted) {
			fmt.Println(help)
			os.Exit(1)
		}
		log.Panicf("parsing runtime configuration: %v", err)
	}

	startServer(&runtimeConfig)
}