-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
55 lines (43 loc) · 1.17 KB
/
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
//go:generate hugo --minify -s site -d ../public
import (
"embed"
"flag"
"fmt"
"io/fs"
"log/slog"
"os"
"github.com/jnsgruk/gosherve/pkg/logging"
"github.com/jnsgruk/gosherve/pkg/server"
)
var (
commit string = "dev"
logLevel = flag.String("log-level", "info", "log level of the application")
redirectsURL = "https://gist.githubusercontent.com/jnsgruk/b590f114af1b041eeeab3e7f6e9851b7/raw"
//go:embed public
publicFS embed.FS
)
func main() {
flag.Parse()
logging.SetupLogger(*logLevel)
// Create an fs.FS from the embedded filesystem
fsys, err := fs.Sub(publicFS, "public")
if err != nil {
slog.Error(err.Error())
os.Exit(1)
}
// Instantiate a new Gosherve server
s := server.NewServer(&fsys, redirectsURL)
slog.Info("jnsgruk", "commit", commit)
// Hydrate the redirects map
err = s.RefreshRedirects()
if err != nil {
// Since this is the first hydration, exit if unable to fetch redirects.
// At this point, without the redirects to begin with the server is
// quite useless.
slog.Error("unable to fetch redirect map", "error", err.Error())
os.Exit(1)
}
slog.Info(fmt.Sprintf("fetched %d redirects", s.NumRedirects()))
s.Start()
}