/
configs.go
93 lines (83 loc) · 2.14 KB
/
configs.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
// Copyright 2016 orivil Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package orivil
import (
"gopkg.in/orivil/config.v0"
"gopkg.in/orivil/helper.v0"
"gopkg.in/orivil/session.v0"
"os"
"os/exec"
"path/filepath"
)
// server config
var CfgApp = &struct {
Debug bool
Key string
View_file_ext string
Memory_session_key string
Memory_session_max_age int // minute
Memory_GC_check_num int
Permanent_session_key string
Permanent_session_max_age int // minute
Permanent_GC_check_num int
Timeout int // second
}{
// default config
Debug: true,
Key: "--------------------------------------",
View_file_ext: ".tmpl",
Memory_session_key: "orivil-memory-session",
Permanent_session_key: "orivil-permanent-session",
Memory_GC_check_num: 3,
Memory_session_max_age: 45,
Permanent_session_max_age: 45,
Permanent_GC_check_num: 3,
Timeout: 10,
}
// dirs
var (
DirBase = getBaseDir()
DirStaticFile = filepath.Join(DirBase, "public")
DirBundle = filepath.Join(DirBase, "bundle")
DirConfig = filepath.Join(DirBase, "config")
DirCache = filepath.Join(DirBase, "cache")
)
var Cfg = config.NewConfig(DirConfig)
func init() {
err := Cfg.ReadStruct("app.yml", CfgApp)
if err != nil {
Errf("%v\nread 'app.yml' got error, use default value instead.", err)
}
Key = CfgApp.Key
session.ConfigMemory(
CfgApp.Memory_session_max_age,
CfgApp.Memory_GC_check_num,
CfgApp.Memory_session_key,
)
session.ConfigPermanent(
CfgApp.Permanent_session_max_age,
CfgApp.Permanent_GC_check_num,
CfgApp.Permanent_session_key,
)
}
func getBaseDir() string {
dir, err := os.Getwd()
if err != nil {
panic(err)
}
if helper.IsExist(filepath.Join(dir, "bundle")) {
return dir
} else {
file, err := exec.LookPath(os.Args[0])
if err != nil {
panic(err)
}
path, err := filepath.Abs(file)
if err != nil {
panic(err)
}
dir = filepath.Dir(path)
return dir
}
}