-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.go
52 lines (42 loc) · 1.31 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
package main
import (
"log"
"os"
"strings"
_ "github.com/ahmethakanbesel/finance-api/migrations"
"github.com/ahmethakanbesel/finance-api/tefas"
"github.com/ahmethakanbesel/finance-api/yahoo"
"github.com/pocketbase/pocketbase"
"github.com/pocketbase/pocketbase/core"
"github.com/pocketbase/pocketbase/plugins/migratecmd"
)
func main() {
app := pocketbase.New()
// loosely check if it was executed using "go run"
isGoRun := strings.HasPrefix(os.Args[0], os.TempDir())
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,
})
// Setup tefas service
tefasScraper := tefas.NewScraper(
tefas.WithWorkers(5),
)
tefasService := tefas.NewService(app, tefasScraper)
tefasApi := tefas.NewApi(tefasService, app)
// Setup yahoo finance service
yahooScraper := yahoo.NewScraper(
yahoo.WithWorkers(5),
)
yahooService := yahoo.NewService(app, yahooScraper)
yahooApi := yahoo.NewApi(yahooService, app)
app.OnBeforeServe().Add(func(e *core.ServeEvent) error {
tefasApi.SetupRoutes(e.Router.Group("/api/v1"))
yahooApi.SetupRoutes(e.Router.Group("/api/v1"))
return nil
})
if err := app.Start(); err != nil {
log.Fatal(err)
}
}