-
Notifications
You must be signed in to change notification settings - Fork 4
/
init.go
68 lines (55 loc) · 1.85 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
package config
import (
"github.com/ottemo/commerce/api"
"github.com/ottemo/commerce/db"
"github.com/ottemo/commerce/env"
"github.com/ottemo/commerce/impex"
)
// init makes package self-initialization routine
func init() {
instance := &DefaultConfig{
configValues: make(map[string]interface{}),
configTypes: make(map[string]string),
configValidators: make(map[string]env.FuncConfigValueValidator)}
db.RegisterOnDatabaseStart(setupDB)
db.RegisterOnDatabaseStart(instance.Load)
api.RegisterOnRestServiceStart(setupAPI)
if err := env.RegisterConfig(instance); err != nil {
_ = env.ErrorDispatch(err)
}
if err := impex.RegisterImpexModel("Config", instance); err != nil {
_ = env.ErrorDispatch(err)
}
}
// setupDB prepares system database for package usage
func setupDB() error {
collection, err := db.GetCollection(ConstCollectionNameConfig)
if err != nil {
return env.ErrorDispatch(err)
}
if err := collection.AddColumn("path", db.ConstTypeVarchar, true); err != nil {
return env.ErrorDispatch(err)
}
if err := collection.AddColumn("value", db.ConstTypeText, false); err != nil {
return env.ErrorDispatch(err)
}
if err := collection.AddColumn("type", db.ConstTypeVarchar, false); err != nil {
return env.ErrorDispatch(err)
}
if err := collection.AddColumn("editor", db.ConstTypeVarchar, false); err != nil {
return env.ErrorDispatch(err)
}
if err := collection.AddColumn("options", db.ConstTypeText, false); err != nil {
return env.ErrorDispatch(err)
}
if err := collection.AddColumn("label", db.ConstTypeVarchar, false); err != nil {
return env.ErrorDispatch(err)
}
if err := collection.AddColumn("description", db.ConstTypeText, false); err != nil {
return env.ErrorDispatch(err)
}
if err := collection.AddColumn("image", db.ConstTypeVarchar, false); err != nil {
return env.ErrorDispatch(err)
}
return nil
}