-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
40 lines (32 loc) · 771 Bytes
/
main.go
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
package main
import (
"fmt"
"github.com/codemicro/palmatum/palmatum/internal/config"
"github.com/codemicro/palmatum/palmatum/internal/httpsrv"
"golang.org/x/exp/slog"
"net/http"
"os"
)
func main() {
if err := run(); err != nil {
return
}
}
func run() error {
conf, err := config.Load()
if err != nil {
return fmt.Errorf("load config on startup: %w", err)
}
_ = os.MkdirAll(conf.Platform.SitesDirectory, 0777)
handler, err := httpsrv.New(conf)
if err != nil {
return fmt.Errorf("creating HTTP handler: %w", err)
}
host := fmt.Sprintf("%s:%d", conf.HTTP.Host, conf.HTTP.Port)
slog.Info("http server alive", "host", host)
err = http.ListenAndServe(host, handler)
if err != nil {
return fmt.Errorf("serving HTTP: %w", err)
}
return nil
}