|
|
@@ -4,12 +4,14 @@ import (
|
|
|
l4g "github.com/alecthomas/log4go"
|
|
|
"github.com/spf13/viper"
|
|
|
"os"
|
|
|
+ "path"
|
|
|
)
|
|
|
|
|
|
var cfg = Config{}
|
|
|
|
|
|
type Config struct {
|
|
|
Database Database `mapstructure:"database"` // 数据库配置
|
|
|
+ Report Report `mapstructure:"report"` // 报表
|
|
|
}
|
|
|
|
|
|
type Database struct {
|
|
|
@@ -21,6 +23,11 @@ type Database struct {
|
|
|
Charset string `mapstructure:"charset"`
|
|
|
}
|
|
|
|
|
|
+type Report struct {
|
|
|
+ Template string `mapstructure:"template"`
|
|
|
+ Out string `mapstructure:"out"`
|
|
|
+}
|
|
|
+
|
|
|
func LoadConfig(logger *l4g.Logger) {
|
|
|
path, err := os.Getwd()
|
|
|
if err != nil {
|
|
|
@@ -44,5 +51,21 @@ func LoadConfig(logger *l4g.Logger) {
|
|
|
|
|
|
// GetInfo 获取配置文件
|
|
|
func GetInfo() Config {
|
|
|
+ templateFile := cfg.Report.Template
|
|
|
+ if !isExist(templateFile) {
|
|
|
+ cfg.Report.Template = path.Base(templateFile)
|
|
|
+ }
|
|
|
return cfg
|
|
|
}
|
|
|
+
|
|
|
+// 文件是否存在
|
|
|
+func isExist(fileAddr string) bool {
|
|
|
+ _, err := os.Stat(fileAddr)
|
|
|
+ if err != nil {
|
|
|
+ if os.IsExist(err) {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ return true
|
|
|
+}
|