-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
context.go
58 lines (50 loc) · 930 Bytes
/
context.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
package libwth
import (
"errors"
"fmt"
"github.com/mrusme/libwth/cfg"
"github.com/mrusme/libwth/theme"
"go.uber.org/zap"
)
type Ctx struct {
config *cfg.Cfg
moduleID string
Module *cfg.CfgModule
Log *zap.SugaredLogger
}
func NewCtx(
config *cfg.Cfg,
id string,
log *zap.SugaredLogger,
) (*Ctx, error) {
ctx := new(Ctx)
ctx.config = config
ctx.moduleID = id
ctx.Module = nil
ctx.Log = log
for i := 0; i < len(ctx.config.Modules); i++ {
if ctx.config.Modules[i].ID == id {
ctx.Module = &ctx.config.Modules[i]
break
}
}
if ctx.Module == nil {
return nil, errors.New(
fmt.Sprintf(
"No module configuration with ID %s available!",
id,
),
)
}
ctx.moduleID = id
return ctx, nil
}
func (ctx *Ctx) ConfigValue(key string) string {
if val, ok := ctx.Module.Config[key]; ok {
return val
}
return ""
}
func (ctx *Ctx) Theme() *theme.Theme {
return &ctx.config.Theme
}