-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
57 lines (42 loc) · 1.07 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
56
57
package main
import (
"context"
"embed"
"io/fs"
"net/http"
"sync"
"github.com/gofiber/template/html/v2"
log "github.com/sirupsen/logrus"
"github.com/medium.rip/api"
"github.com/medium.rip/internal/config"
"github.com/medium.rip/internal/lifecycle"
)
//go:embed frontend
var frontend embed.FS
//go:embed frontend/dist/assets
var static embed.FS
func main() {
// load config
config.Load()
// create template engine
tmplFs, err := fs.Sub(frontend, "frontend/dist")
if err != nil {
log.Fatalf("error loading template: %v\n", err)
}
engine := html.NewFileSystem(http.FS(tmplFs), ".html")
// create static file server
staticFs, err := fs.Sub(static, "frontend/dist/assets")
if err != nil {
log.Fatalf("error loading static assets: %v\n", err)
}
staticHttp := http.FS(staticFs)
// cancellable context
wg := sync.WaitGroup{}
ctx, cancelFunc := context.WithCancel(context.Background())
wg.Add(1)
go api.RegisterRoutes(ctx, &wg, engine, staticHttp)
wg.Add(1)
go lifecycle.ShutdownListener(&wg, &cancelFunc)
wg.Wait()
log.Info("Graceful shutdown complete")
}