-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
74 lines (58 loc) · 1.81 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"embed"
"fmt"
"os"
"goyave.dev/template/http/route"
"goyave.dev/goyave/v5"
"goyave.dev/goyave/v5/util/errors"
"goyave.dev/goyave/v5/util/fsutil"
// Import the appropriate GORM dialect for the database you're using.
// _ "goyave.dev/goyave/v5/database/dialect/mysql"
// _ "goyave.dev/goyave/v5/database/dialect/postgres"
// _ "goyave.dev/goyave/v5/database/dialect/sqlite"
// _ "goyave.dev/goyave/v5/database/dialect/mssql"
// _ "goyave.dev/goyave/v5/database/dialect/clickhouse"
)
//go:embed resources
var resources embed.FS
func main() {
resources := fsutil.NewEmbed(resources)
langFS, err := resources.Sub("resources/lang")
if err != nil {
fmt.Fprintln(os.Stderr, err.(*errors.Error).String())
os.Exit(1)
}
opts := goyave.Options{
LangFS: langFS,
}
server, err := goyave.New(opts)
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")
})
registerServices(server)
server.Logger.Info("Registering routes")
server.RegisterRoutes(route.Register)
if err := server.Start(); err != nil {
server.Logger.Error(err)
os.Exit(2)
}
}
func registerServices(server *goyave.Server) {
server.Logger.Info("Registering services")
// Services represent the Domain/Business layer.
// This is where the core logic and value of your application resides.
// This function is where you will register your services in the server's
// service container to make them accessible to dependents.
// https://goyave.dev/basics/services.html#service-container
// TODO register services
}