Core

/app/services.go (2.1 KB)

 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
// Package app - $PF_GENERATE_ONCE$
package app // import {{{ .Package }}}

import (
"context"{{{ if .HasModule "migration" }}}

"github.com/pkg/errors"

"{{{ .Package }}}/app/lib/database/migrate"{{{ end}}}{{{ if.HasModule "process" }}}
"{{{ .Package }}}/app/lib/exec"{{{ end }}}{{{ if .HasModule "help" }}}
"{{{ .Package }}}/app/lib/help"{{{ end }}}{{{ if.HasModule "scripting" }}}
"{{{ .Package }}}/app/lib/scripting"{{{ end }}}{{{ if.HasModule "websocket" }}}
"{{{ .Package }}}/app/lib/websocket"{{{ end }}}{{{ if .HasModule "migration" }}}
"{{{ .Package }}}/queries/migrations"{{{ end }}}{{{ if.HasUser }}}
"{{{ .Package }}}/app/user"{{{ end }}}
"{{{ .Package }}}/app/util"
)

type Services struct {
{{{ if.HasModule "export" }}}// $PF_INJECT_START(services)$
// $PF_INJECT_END(services)${{{ end }}}{{{ if.HasModule "process" }}}
Exec *exec.Service{{{ end }}}{{{ if.HasModule "scripting" }}}
Script *scripting.Service{{{ end }}}{{{ if.HasModule "websocket" }}}
Socket *websocket.Service{{{ end }}}{{{ if.HasUser }}}
User *user.Service{{{ end }}}{{{ if.HasModule "help" }}}
Help *help.Service{{{ end }}}
// add your dependencies here
}

func NewServices(ctx context.Context, st *State, logger util.Logger) (*Services, error) {
{{{ if .HasModule "migration" }}}migrations.LoadMigrations(st.Debug)
err := migrate.Migrate(ctx, st.DB, logger)
if err != nil {
return nil, errors.Wrap(err, "unable to run database migrations")
}
{{{ end }}}return &Services{
{{{ if.HasModule "process" }}}Exec: exec.NewService(),
{{{ end }}}{{{ if.HasModule "scripting" }}}Script: scripting.NewService(st.FS, "scripts"),
{{{ end }}}{{{ if.HasModule "websocket" }}}Socket: websocket.NewService(nil, nil, nil),
{{{ end }}}{{{ if.HasUser }}}User: user.NewService(st.Files, logger),
{{{ end}}}{{{ if.HasModule "help" }}}Help: help.NewService(logger),
{{{ end}}}{{{ if.HasModule "export" }}}// $PF_INJECT_START(refs)$
// $PF_INJECT_END(refs)${{{ end }}}
}, nil
}

func (s *Services) Close(_ context.Context, _ util.Logger) error {
return nil
}