Watch 2 Star 0 Fork 0

fotomxq / sttw-pmGoApache-2.0

Create your Gitee Account
Explore and code with more than 5 million developers,Free private repositories !:)
Sign up
山投集团团委人员信息管理平台,该项目之前采用商用授权,但由于后来更进一步完善,现开放旧版本源代码,并采用Apache2.0协议商业友好授权。 spread retract

Clone or download
sttw-pm.go 3.94 KB
Copy Edit Web IDE Raw Blame History
package main
import (
"gopkg.in/mgo.v2"
"strconv"
"fotomxq/sttw-pm/core"
"fotomxq/sttw-pm/router"
"fotomxq/sttw-pm/sttw"
)
//全局APP名称
var AppName string
//全局APP标识
var AppMark string
//全局数据库操作模块
var DB *mgo.Database
//全局Session句柄
var SessionOperate core.SessionOperate
//全局验证处理句柄
var MatchString core.MatchString
//全局日志数据库操作
var LogOperate core.LogOperate
//全局用户操作句柄
var UserOperate core.User
//IP黑名单处理器
var IPAddrOperate core.IPAddrBan
//控制器主程序
//该函数用于启动整个项目
func main() {
//读取配置文件信息
var configSrc string
configSrc = "config" + core.PathSeparator + "config.json"
var configData map[string]interface{}
var b bool
configData, b = core.LoadConfig(configSrc)
if b == false {
core.SendLog("无法读取config.json配置数据。")
return
}
//读取APP名称
AppName = configData["app-name"].(string)
AppMark = configData["app-mark"].(string)
//连接数据库
var session *mgo.Session
var err error
session, err = mgo.Dial(configData["mgo-host"].(string))
if err != nil {
core.SendLog("无法连接到数据库,错误 : " + err.Error())
return
}
core.SendLog("数据库连接成功 : " + configData["mgo-host"].(string))
defer session.Close()
session.SetMode(mgo.Monotonic, true)
DB = session.DB(configData["mgo-db"].(string))
//初始化日志操作句柄
LogOperate.Init(DB, AppMark)
//将日志句柄赋予给core
core.Log = &LogOperate
//创建SESSION
var sessionIPBind bool
sessionIPBind = configData["session-ip-bind"].(string) == "true"
var sessionTimeout int
sessionTimeout, err = strconv.Atoi(configData["session-timeout"].(string))
if err != nil {
core.SendLog(err.Error())
return
}
SessionOperate.Create(AppMark, DB, sessionIPBind, sessionTimeout, &MatchString)
//构建用户处理器var userLoginTimeout int64
var userLoginTimeout int64
userLoginTimeout, err = strconv.ParseInt(configData["user-login-timeout"].(string), 10, 64)
if err != nil {
core.SendLog(err.Error())
return
}
var userOneStatus bool
userOneStatus = configData["user-one"].(string) == "true"
UserOperate.Init(&core.UserParams{
DB, &MatchString,
&SessionOperate,
&LogOperate,
AppMark,
AppMark,
userLoginTimeout,
userOneStatus,
configData["user-username"].(string),
configData["user-password"].(string),
[]string{"admin", "normal"},
map[string]map[string]interface{}{
"admin": {
"name": "管理员",
"page": []string{"*"},
},
"normal": {
"name": "普通用户",
"page": []string{"center","user-self","new"},
},
},
})
//创建IP名单处理器
var ipBanOn bool
ipBanOn = configData["ip-ban-on"].(string) == "true"
var ipWriteOn bool
ipWriteOn = configData["ip-white-on"].(string) == "true"
IPAddrOperate.Init(DB, ipBanOn, ipWriteOn)
//将本机IP添加到白名单内,用于开发工作
//IPAddrOperate.SaveToList("[::1]",false)
//获取sttw设定数据
sttwConfig,b := core.LoadConfig("config" + core.PathSeparator + "sttw.json")
//启动自动备份模块
core.BackupDB = DB
core.BackupLog = &LogOperate
go core.BackupAuto()
//初始化路由
var debug bool
debug = configData["debug"].(string) == "true"
var sttw sttw.SttwOperate
sttw.Init(DB,&LogOperate,&MatchString)
sttw.Encryption = configData["data-encryption"].(string)
sttw.SttwRetired = sttwConfig["sttwRetired"].(string)
router.Init(&router.GlobOperate{
debug,
DB,
&SessionOperate,
&LogOperate,
&IPAddrOperate,
configData["app-name"].(string),
configData["app-des"].(string),
configData["app-copyright"].(string),
&UserOperate,
&MatchString,
&sttw,
sttwConfig["sttwNewOn"].(string) == "on",
sttwConfig["sttwOffDes"].(string),
sttwConfig["sttwRetired"].(string),
configData["bind-on"].(string) == "true",
configData["bind-host"].(string),
configData["bind-host-f"].(string),
})
//启动服务器
router.RunSever(configData["server-host"].(string))
}

Comment ( 0 )

Sign in for post a comment

Go
1
https://gitee.com/fotomxq/sttw-pm.git
git@gitee.com:fotomxq/sttw-pm.git
fotomxq
sttw-pm
sttw-pm
master

Search