-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebconfig.go
69 lines (56 loc) · 1.4 KB
/
webconfig.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
//Copyright
//go mvc web framework
//mvc server config
package gomvc
import (
//"fmt"
"os"
"path"
)
const (
DefaultAddress string = "0.0.0.0:8080" //default listen address
pubicDir = "public"
)
//mvc server config
type WebConfig struct {
ServerKey string //TODO: used to session & cache
Address string //listen address, default is 0.0.0.0:8000
RootDir string //root dir, default is current work path
EnableProfile bool //enable http profile or not
Timeout int //server execute time out (in second)
publicDir string //static files path
}
//static files path
func (w *WebConfig) PublicPath() string {
return path.Join(w.RootDir, "public")
}
//check config
func (w *WebConfig) Check() (err error) {
if w.Address == "" {
w.Address = DefaultAddress
}
if w.RootDir == "" {
wd, _ := os.Getwd()
w.RootDir = wd
}
f := path.Join(w.RootDir, pubicDir)
info, err := os.Stat(f)
if err == nil && info.IsDir() {
w.publicDir = f
} else {
w.publicDir = w.RootDir
}
return nil
}
//TODO: create config from file
func (w WebConfig) FromFile(file string) (c *WebConfig, err error) {
panic("not implemented")
}
//TODO: create config from json string
func (w WebConfig) FromJson(s string) (c *WebConfig, err error) {
panic("not implemented")
}
//TODO: create config from xml
func (w WebConfig) FromXml(s string) (c *WebConfig, err error) {
panic("not implemented")
}