This repository has been archived by the owner on Oct 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconf.go
131 lines (113 loc) · 3.66 KB
/
conf.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
124
125
126
127
128
129
130
131
package kwiscale
// Config structure that holds configuration
type Config struct {
// Root directory where TemplateEngine will get files
TemplateDir string
// Port to listen
Port string
// Number of handler to prepare
NbHandlerCache int
// TemplateEngine to use (default, pango2...)
TemplateEngine string
// Template engine options (some addons need options)
TemplateEngineOptions TplOptions
// SessionEngine (default is a file storage)
SessionEngine string
// SessionName is the name of session, eg. Cookie name, default is "kwiscale-session"
SessionName string
// A secret string to encrypt cookie
SessionSecret []byte
// Configuration for SessionEngine
SessionEngineOptions SessionEngineOptions
// Static directory (to put css, images, and so on...)
StaticDir string
// Activate static in memory cache
StaticCacheEnabled bool
// StrictSlash allows to match route that have trailing slashes
StrictSlash bool
// Datastrore
//DB string
//DBOptions DBOptions
}
// Initialize config default values if some are not defined
func initConfig(config *Config) *Config {
if config == nil {
config = new(Config)
}
if config.Port == "" {
config.Port = ":8000"
}
if config.NbHandlerCache == 0 {
config.NbHandlerCache = 5
}
if config.TemplateEngine == "" {
config.TemplateEngine = "basic"
}
if config.TemplateEngineOptions == nil {
config.TemplateEngineOptions = make(TplOptions)
}
if config.SessionEngine == "" {
config.SessionEngine = "default"
}
if config.SessionName == "" {
config.SessionName = "kwiscale-session"
}
if config.SessionSecret == nil {
config.SessionSecret = []byte("A very long secret string you should change")
}
if config.SessionEngineOptions == nil {
config.SessionEngineOptions = make(SessionEngineOptions)
}
return config
}
/*
type ymlDB struct {
Engine string `yml:"engine"`
Options DBOptions `yml:"options"`
}
*/
type ymlSession struct {
Name string `yaml:"name,omitempty"`
Engine string `yaml:"engine,omitempty"`
Secret []byte `yaml:"secret,omitempty"`
Options SessionEngineOptions `yaml:"options,omitempty"`
}
type ymlTemplate struct {
Dir string `yaml:"dir,omitempty"`
Engine string `yaml:"engine,omitempty"`
Options TplOptions `yaml:"options,omitempty"`
}
type ymlRoute struct {
Handler string `yaml:"handler"`
Alias string `yaml:"alias"`
}
// yamlConf is used to make yaml configuration easiest to write.
type yamlConf struct {
Port string `yaml:"listen,omitempty"`
NbHandlerCache int `yaml:"nbhandler,omitempty"`
StaticDir string `yaml:"staticdir,omitempty"`
StaticCacheEnabled bool `yaml:"staticcache,omitempty"`
StrictSlash bool `yaml:"strictslash,omitempty"`
Template ymlTemplate `yaml:"template,omitempty"`
Session ymlSession `yaml:"session,omitempty"`
Routes map[string]ymlRoute `yaml:"routes"`
//DB ymlDB `yaml:"db,omitempty"`
}
// parse returns the *Config from yaml struct.
func (y yamlConf) parse() *Config {
return &Config{
Port: y.Port,
NbHandlerCache: y.NbHandlerCache,
StaticDir: y.StaticDir,
StrictSlash: y.StrictSlash,
SessionEngine: y.Session.Engine,
SessionName: y.Session.Name,
SessionSecret: y.Session.Secret,
SessionEngineOptions: y.Session.Options,
TemplateDir: y.Template.Dir,
TemplateEngine: y.Template.Engine,
TemplateEngineOptions: y.Template.Options,
//DB: y.DB.Engine,
//DBOptions: y.DB.Options,
}
}