-
Notifications
You must be signed in to change notification settings - Fork 461
/
main.go
64 lines (48 loc) · 1.45 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
package main
import (
"flag"
"log"
"os"
"strings"
"github.com/labstack/echo/v5"
"github.com/labstack/echo/v5/middleware"
"github.com/pocketbase/pocketbase/core"
"github.com/pocketbase/pocketbase/plugins/migratecmd"
_ "github.com/usual2970/certimate/migrations"
"github.com/usual2970/certimate/internal/routes"
"github.com/usual2970/certimate/internal/scheduler"
"github.com/usual2970/certimate/internal/utils/app"
"github.com/usual2970/certimate/internal/workflow"
"github.com/usual2970/certimate/ui"
_ "time/tzdata"
)
func main() {
app := app.GetApp()
isGoRun := strings.HasPrefix(os.Args[0], os.TempDir())
// 获取启动命令中的http参数
var httpFlag string
flag.StringVar(&httpFlag, "http", "127.0.0.1:8090", "HTTP server address")
// "serve"影响解析
_ = flag.CommandLine.Parse(os.Args[2:])
migratecmd.MustRegister(app, app.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: isGoRun,
})
workflow.AddEvent()
app.OnBeforeServe().Add(func(e *core.ServeEvent) error {
routes.Register(e.Router)
scheduler.Register()
e.Router.GET(
"/*",
echo.StaticDirectoryHandler(ui.DistDirFS, false),
middleware.Gzip(),
)
return nil
})
defer log.Println("Exit!")
log.Printf("Visit the website: http://%s", httpFlag)
if err := app.Start(); err != nil {
log.Fatal(err)
}
}