-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
55 lines (43 loc) · 1.43 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
package main
import (
"log"
"net/http"
"os"
"strings"
"github.com/labstack/echo/v5"
"github.com/pocketbase/pocketbase"
"github.com/pocketbase/pocketbase/apis"
"github.com/pocketbase/pocketbase/core"
"github.com/pocketbase/pocketbase/plugins/migratecmd"
// register the migration files from the migrations package
_ "talishar/data-doll/migrations"
)
var devMode bool
func main() {
// pocketbase, the most important bit of the app.
app := pocketbase.New()
log.Println("🚀 Running the server")
// Define a flag for dev mode, eagerly parse the arguments. In dev mode automigrate is enabled.
// enable auto creation of migration files when making collection changes in the Admin UI
app.RootCmd.PersistentFlags().BoolVar(&devMode, "dev", false, "run in dev mode")
app.RootCmd.ParseFlags(os.Args[1:])
// check if it was executed using "go run"
isGoRun := strings.HasPrefix(os.Args[0], os.TempDir())
if devMode || isGoRun {
log.Println("🖥️ Running in dev mode")
migratecmd.MustRegister(app, app.RootCmd, migratecmd.Config{
Automigrate: true,
})
}
// add a route to say 'hello world'
app.OnBeforeServe().Add(func(e *core.ServeEvent) error {
e.Router.GET("/hello", func(c echo.Context) error {
return c.String(http.StatusOK, "Hello world!")
}, apis.ActivityLogger(app), apis.RequireAdminAuth())
return nil
})
log.Println("🤖 Data Doll is online")
if err := app.Start(); err != nil {
log.Fatal(err)
}
}