-
-
Notifications
You must be signed in to change notification settings - Fork 815
Expand file tree
/
Copy pathmain.go
More file actions
79 lines (66 loc) · 2.21 KB
/
main.go
File metadata and controls
79 lines (66 loc) · 2.21 KB
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
75
76
77
78
79
package main
import (
"log/slog"
"os"
"strings"
_ "time/tzdata"
"github.com/pocketbase/pocketbase"
"github.com/pocketbase/pocketbase/apis"
"github.com/pocketbase/pocketbase/core"
"github.com/pocketbase/pocketbase/plugins/migratecmd"
"github.com/pocketbase/pocketbase/tools/hook"
"github.com/spf13/pflag"
"github.com/certimate-go/certimate/cmd"
"github.com/certimate-go/certimate/internal/app"
"github.com/certimate-go/certimate/internal/rest/routes"
"github.com/certimate-go/certimate/internal/scheduler"
"github.com/certimate-go/certimate/internal/workflow"
"github.com/certimate-go/certimate/ui"
_ "github.com/certimate-go/certimate/migrations"
)
func main() {
pb := app.GetApp().(*pocketbase.PocketBase)
if len(os.Args) < 2 {
slog.Error("[CERTIMATE] missing exec args, maybe you forget the 'serve' command?")
os.Exit(1)
return
}
var flagHttp string
pflag.CommandLine = pflag.NewFlagSet(os.Args[0], pflag.ContinueOnError)
pflag.CommandLine.Parse(os.Args[2:]) // skip the first two arguments: "main.go serve"
pflag.StringVar(&flagHttp, "http", "127.0.0.1:8090", "HTTP server address")
pflag.Parse()
migratecmd.MustRegister(pb, pb.RootCmd, migratecmd.Config{
// enable auto creation of migration files when making collection changes in the Admin UI
// (the isGoRun check is to enable it only during development)
Automigrate: strings.HasPrefix(os.Args[0], os.TempDir()),
})
pb.RootCmd.AddCommand(cmd.NewInternalCommand(pb))
pb.RootCmd.AddCommand(cmd.NewWinscCommand(pb))
pb.OnServe().BindFunc(func(e *core.ServeEvent) error {
scheduler.Setup()
workflow.Setup()
routes.BindRouter(e.Router)
return e.Next()
})
pb.OnServe().Bind(&hook.Handler[*core.ServeEvent]{
Func: func(e *core.ServeEvent) error {
e.Router.
GET("/{path...}", apis.Static(ui.DistDirFS, false)).
Bind(apis.Gzip())
return e.Next()
},
Priority: 999,
})
pb.OnServe().BindFunc(func(e *core.ServeEvent) error {
slog.Info("[CERTIMATE] Visit the website: http://" + flagHttp)
return e.Next()
})
pb.OnTerminate().BindFunc(func(e *core.TerminateEvent) error {
workflow.Teardown()
return e.Next()
})
if err := cmd.Serve(pb); err != nil {
slog.Error("[CERTIMATE] Start failed.", slog.Any("error", err))
}
}