-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
44 lines (35 loc) · 986 Bytes
/
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
package main
import (
"log"
"net/http"
"os"
"stockmark/model"
"github.com/pocketbase/pocketbase"
"github.com/pocketbase/pocketbase/apis"
"github.com/pocketbase/pocketbase/core"
)
// go build -o main.exe . && main serve
func main() {
app := pocketbase.New()
model.Initialize(app)
app.OnServe().BindFunc(func(se *core.ServeEvent) error {
// serves static files from the provided public dir (if exists)
se.Router.GET("/{path...}", apis.Static(os.DirFS("./pb_public"), false))
se.Router.POST("/register", OnPostRegister)
se.Router.POST("/login", OnPostLogin)
se.Router.GET("/portfolio", OnGetPortfolio)
se.Router.GET("/trade", OnGetTrade)
se.Router.GET("/transact", OnGetTransact)
se.Router.GET("/deposit", OnGetDeposit)
return se.Next()
})
if err := app.Start(); err != nil {
log.Fatal(err)
}
}
func failure(e *core.RequestEvent, err error) error {
return e.JSON(http.StatusOK, map[string]any{
"success": false,
"message": err.Error(),
})
}