123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- package mokuai
- import (
- "fmt"
- "github.com/go-ini/ini"
- "log"
- "runtime"
- "time"
- )
- type App struct {
- GinLog int
- Proxyapi string
- Proxyapi_data string
- }
- type Server struct {
- RunMode string
- HttpPort int
- ReadTimeout time.Duration
- WriteTimeout time.Duration
- }
- type Database struct {
- Type string
- Host string
- User string
- Password string
- DbName string
- RmHost string
- }
- var ServerConfig = &Server{}
- var AppConfig = &App{}
- var DatabaseConfig = &Database{}
- var (
- Cfg *ini.File
- )
- // 初始化配置文件
- func InitConfigFile() {
- // 修改此处初始化的配置文件内容
- var lin = "[UserCookies]\n#MT bbs Cookies (格式<有反单引号> : `cookies值`)\nMtCookies = \nMtProxy ="
- dirpath := File_Get_Current_Directory()
- if runtime.GOOS == "linux" {
- Dir_Create(dirpath + "/conf")
- File_WriteStr(dirpath+"/conf/app.ini", lin)
- } else if runtime.GOOS == "windows" {
- Dir_Create(dirpath + "\\conf")
- File_WriteStr(dirpath+"\\conf\\app.ini", lin)
- }
- }
- func IniSetup() {
- var err error
- dirpath := File_Get_Current_Directory()
- filePath := ""
- if runtime.GOOS == "linux" {
- _, reBool := File_IsExists(dirpath + "/conf/app.ini")
- if reBool == false {
- filePath = ""
- } else {
- filePath = dirpath + "/conf/app.ini"
- }
- } else if runtime.GOOS == "windows" {
- _, reBool := File_IsExists(dirpath + "\\conf\\app.ini")
- if reBool == false {
- filePath = ""
- } else {
- filePath = dirpath + "\\conf\\app.ini"
- }
- }
- if filePath == "" {
- if runtime.GOOS == "linux" {
- _, reBool := File_IsExists("conf/app.ini")
- if reBool == false {
- filePath = ""
- } else {
- filePath = "conf/app.ini"
- }
- } else if runtime.GOOS == "windows" {
- _, reBool := File_IsExists("conf\\app.ini")
- if reBool == false {
- filePath = ""
- } else {
- filePath = "conf\\app.ini"
- }
- }
- }
- if filePath == "" {
- InitConfigFile()
- log.Fatalf("fail to parse " + dirpath + "\\conf\\app.ini" + " <已创建初始化配置文件,请打开 conf/app.ini 配入信息>后 运行")
- return
- }
- Cfg, err = ini.Load(filePath)
- fmt.Println("配置文件 >> " + filePath)
- if err != nil {
- InitConfigFile()
- log.Fatalf("fail to parse " + dirpath + "\\conf\\app.ini" + " <已创建初始化配置文件,请打开 conf/app.ini 配入信息>后 运行")
- return
- }
- }
- func SaveConfig() {
- dirpath := File_Get_Current_Directory()
- if runtime.GOOS == "linux" {
- _ = Cfg.SaveTo(dirpath + "/conf/app.ini")
- } else if runtime.GOOS == "windows" {
- _ = Cfg.SaveTo(dirpath + "\\conf\\app.ini")
- }
- IniSetup()
- }
|