mirror of
https://github.com/usual2970/certimate.git
synced 2025-06-08 13:39:53 +00:00
feat: support configuring pb-data-dir on app launch
This commit is contained in:
parent
d1dbbae101
commit
087fd81879
@ -14,7 +14,7 @@ import (
|
|||||||
|
|
||||||
const tableName = "workflow"
|
const tableName = "workflow"
|
||||||
|
|
||||||
func RegisterEvents() error {
|
func Register() {
|
||||||
app := app.GetApp()
|
app := app.GetApp()
|
||||||
|
|
||||||
app.OnRecordAfterCreateRequest(tableName).Add(func(e *core.RecordCreateEvent) error {
|
app.OnRecordAfterCreateRequest(tableName).Add(func(e *core.RecordCreateEvent) error {
|
||||||
@ -28,8 +28,6 @@ func RegisterEvents() error {
|
|||||||
app.OnRecordAfterDeleteRequest(tableName).Add(func(e *core.RecordDeleteEvent) error {
|
app.OnRecordAfterDeleteRequest(tableName).Add(func(e *core.RecordDeleteEvent) error {
|
||||||
return delete(e.HttpContext.Request().Context(), e.Record)
|
return delete(e.HttpContext.Request().Context(), e.Record)
|
||||||
})
|
})
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func update(ctx context.Context, record *models.Record) error {
|
func update(ctx context.Context, record *models.Record) error {
|
||||||
|
25
main.go
25
main.go
@ -25,27 +25,24 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
app := app.GetApp()
|
app := app.GetApp()
|
||||||
|
|
||||||
isGoRun := strings.HasPrefix(os.Args[0], os.TempDir())
|
var flagHttp string
|
||||||
|
var flagDir string
|
||||||
// 获取启动命令中的http参数
|
flag.StringVar(&flagHttp, "http", "127.0.0.1:8090", "HTTP server address")
|
||||||
var httpFlag string
|
flag.StringVar(&flagDir, "dir", "/pb_data/database", "Pocketbase data directory")
|
||||||
flag.StringVar(&httpFlag, "http", "127.0.0.1:8090", "HTTP server address")
|
_ = flag.CommandLine.Parse(os.Args[2:]) // skip the first two arguments: "main.go serve"
|
||||||
// "serve"影响解析
|
|
||||||
_ = flag.CommandLine.Parse(os.Args[2:])
|
|
||||||
|
|
||||||
migratecmd.MustRegister(app, app.RootCmd, migratecmd.Config{
|
migratecmd.MustRegister(app, app.RootCmd, migratecmd.Config{
|
||||||
// enable auto creation of migration files when making collection changes in the Admin UI
|
// enable auto creation of migration files when making collection changes in the Admin UI
|
||||||
// (the isGoRun check is to enable it only during development)
|
// (the isGoRun check is to enable it only during development)
|
||||||
Automigrate: isGoRun,
|
Automigrate: strings.HasPrefix(os.Args[0], os.TempDir()),
|
||||||
})
|
})
|
||||||
|
|
||||||
workflow.RegisterEvents()
|
|
||||||
|
|
||||||
app.OnBeforeServe().Add(func(e *core.ServeEvent) error {
|
app.OnBeforeServe().Add(func(e *core.ServeEvent) error {
|
||||||
routes.Register(e.Router)
|
|
||||||
|
|
||||||
scheduler.Register()
|
scheduler.Register()
|
||||||
|
|
||||||
|
workflow.Register()
|
||||||
|
|
||||||
|
routes.Register(e.Router)
|
||||||
e.Router.GET(
|
e.Router.GET(
|
||||||
"/*",
|
"/*",
|
||||||
echo.StaticDirectoryHandler(ui.DistDirFS, false),
|
echo.StaticDirectoryHandler(ui.DistDirFS, false),
|
||||||
@ -57,11 +54,13 @@ func main() {
|
|||||||
|
|
||||||
app.OnTerminate().Add(func(e *core.TerminateEvent) error {
|
app.OnTerminate().Add(func(e *core.TerminateEvent) error {
|
||||||
routes.Unregister()
|
routes.Unregister()
|
||||||
|
|
||||||
log.Println("Exit!")
|
log.Println("Exit!")
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
log.Printf("Visit the website: http://%s", httpFlag)
|
log.Printf("Visit the website: http://%s", flagHttp)
|
||||||
|
|
||||||
if err := app.Start(); err != nil {
|
if err := app.Start(); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user