forked from go-aah/aah
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
123 lines (100 loc) · 3.57 KB
/
config.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// Copyright (c) Jeevanandam M. (https://github.com/jeevatkm)
// go-aah/aah source code and usage is governed by a MIT style
// license that can be found in the LICENSE file.
package aah
import (
"os"
"os/signal"
"path/filepath"
"syscall"
"aahframework.org/config.v0"
)
//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// app methods
//______________________________________________________________________________
func (a *app) Config() *config.Config {
return a.cfg
}
//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// app Unexported methods
//______________________________________________________________________________
func (a *app) initConfig() error {
aahConf := filepath.Join(a.configDir(), "aah.conf")
cfg, err := config.LoadFile(aahConf)
if err != nil {
return err
}
a.cfg = cfg
a.sc = make(chan os.Signal, 2)
return nil
}
func (a *app) listenForHotConfigReload() {
signal.Notify(a.sc, syscall.SIGHUP)
for {
<-a.sc
a.Log().Warn("Hangup signal (SIGHUP) received")
if a.IsProfile(defaultEnvProfile) {
a.Log().Info("Currently active environment profile is 'dev', config hot-reload is not applicable")
continue
}
a.hotReloadConfig()
}
}
func (a *app) hotReloadConfig() {
a.hotReload = true
defer func() { a.hotReload = false }()
a.Log().Info("Configuration hot-reload and application reinitialization starts ...")
var err error
if err = a.initConfig(); err != nil {
a.Log().Errorf("Unable to reload aah.conf: %v", err)
return
}
if err = a.initConfigValues(); err != nil {
a.Log().Errorf("Unable to reinitialize aah application variables: %v", err)
return
}
if err = a.initLog(); err != nil {
a.Log().Errorf("Unable to reinitialize application logger: %v", err)
return
}
if err = a.initI18n(); err != nil {
a.Log().Errorf("Unable to reinitialize application i18n: %v", err)
return
}
if err = a.initRouter(); err != nil {
a.Log().Errorf("Unable to reinitialize application %v", err)
return
}
if err = a.initView(); err != nil {
a.Log().Errorf("Unable to reinitialize application views: %v", err)
return
}
if err = a.initSecurity(); err != nil {
a.Log().Errorf("Unable to reinitialize application security manager: %v", err)
return
}
if a.accessLogEnabled {
if err = a.initAccessLog(); err != nil {
a.Log().Errorf("Unable to reinitialize application access log: %v", err)
return
}
}
if a.dumpLogEnabled {
if err = a.initDumpLog(); err != nil {
a.Log().Errorf("Unable to reinitialize application dump log: %v", err)
return
}
}
a.Log().Info("Configuration hot-reload and application reinitialization was successful")
}
//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// View Template methods
//______________________________________________________________________________
// tmplConfig method provides access to application config on templates.
func (vm *viewManager) tmplConfig(key string) interface{} {
if value, found := vm.a.Config().Get(key); found {
return sanatizeValue(value)
}
vm.a.Log().Warnf("app config key not found: %s", key)
return ""
}