-
Notifications
You must be signed in to change notification settings - Fork 4
/
init.go
72 lines (62 loc) · 1.91 KB
/
init.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Package controller $PF_IGNORE$
package controller
import (
"context"
"strings"
"github.com/pkg/errors"
"projectforge.dev/projectforge/app"
"projectforge.dev/projectforge/app/controller/cutil"
"projectforge.dev/projectforge/app/module"
"projectforge.dev/projectforge/app/project"
"projectforge.dev/projectforge/app/util"
)
// Initialize app-specific system dependencies.
func initApp(*app.State, util.Logger) {
}
// Configure app-specific data for each request.
func initAppRequest(as *app.State, ps *cutil.PageState) error {
if err := initProjects(ps.Context, as, ps.Logger); err != nil {
return errors.Wrap(err, "unable to initialize projects")
}
root := as.Services.Projects.ByPath(".")
if root.Info == nil && !strings.HasSuffix(ps.URI.String(), "/about") {
ps.ForceRedirect = "/welcome"
}
return nil
}
// Initialize system dependencies for the marketing site.
func initSite(as *app.State, logger util.Logger) {
as.Services = &app.Services{
Modules: module.NewService(context.Background(), as.Files, logger),
}
}
// Configure marketing site data for each request.
func initSiteRequest(*app.State, *cutil.PageState) error {
return nil
}
func initProjects(ctx context.Context, as *app.State, logger util.Logger) error {
prjs, err := as.Services.Projects.Refresh(logger)
if err != nil {
return errors.Wrap(err, "can't load projects")
}
for _, prj := range prjs {
var mods project.ModuleDefs
if prj.Info != nil {
mods = prj.Info.ModuleDefs
}
var keys []string
for _, mod := range mods {
k, err := as.Services.Modules.Register(ctx, prj.Path, mod.Key, mod.Path, mod.URL, logger)
if err != nil {
return errors.Wrapf(err, "unable to register module definition for module [%s]", mod.Key)
}
keys = append(keys, k...)
}
if len(keys) > 0 {
if len(keys) != 1 && keys[0] != "*" {
logger.Debugf("Loaded modules for [%s]: %s", prj.Key, strings.Join(keys, ", "))
}
}
}
return nil
}