-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
54 lines (42 loc) · 1.16 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
package main
import (
"embed"
"fmt"
"os"
"github.com/go-goyave/websocket-example/http/route"
"github.com/go-goyave/websocket-example/service/static"
"goyave.dev/goyave/v5"
"goyave.dev/goyave/v5/util/errors"
"goyave.dev/goyave/v5/util/fsutil"
)
//go:embed resources
var resources embed.FS
func main() {
resourcesEmbed := fsutil.NewEmbed(resources)
server, err := goyave.New(goyave.Options{})
if err != nil {
fmt.Fprintln(os.Stderr, err.(*errors.Error).String())
os.Exit(1)
}
server.Logger.Info("Registering hooks")
server.RegisterSignalHook()
server.RegisterStartupHook(func(s *goyave.Server) {
server.Logger.Info("Server is listening", "host", s.Host())
})
server.RegisterShutdownHook(func(s *goyave.Server) {
s.Logger.Info("Server is shutting down")
})
server.Logger.Info("Registering services")
staticResources, err := resourcesEmbed.Sub("resources/template")
if err != nil {
server.Logger.Error(err)
os.Exit(1)
}
server.RegisterService(static.NewService(staticResources))
server.Logger.Info("Registering routes")
server.RegisterRoutes(route.Register)
if err := server.Start(); err != nil {
server.Logger.Error(err)
os.Exit(3)
}
}