forked from golang/hotime
This commit is contained in:
parent
a3d3155e9b
commit
374e0ab2ac
@ -20,6 +20,7 @@ type Application struct {
|
||||
Router
|
||||
contextBase
|
||||
Port string //端口号
|
||||
TLSPort string //ssl访问端口号
|
||||
connectListener []func(this *Context) bool //所有的访问监听,true按原计划继续使用,false表示有监听器处理
|
||||
connectDbFunc func(err ...*Error) *sql.DB
|
||||
configPath string
|
||||
@ -71,6 +72,7 @@ func (this *Application) Run(router Router) {
|
||||
|
||||
//this.Port = port
|
||||
this.Port = this.Config.GetString("port")
|
||||
this.TLSPort = this.Config.GetString("tlsPort")
|
||||
|
||||
if this.connectDbFunc != nil && (this.Db.DB == nil || this.Db.DB.Ping() != nil) {
|
||||
this.Db.SetConnect(this.connectDbFunc)
|
||||
@ -93,11 +95,39 @@ func (this *Application) Run(router Router) {
|
||||
if !IsRun {
|
||||
IsRun = true
|
||||
}
|
||||
|
||||
ch := make(chan int)
|
||||
go func() {
|
||||
|
||||
if ObjToCeilInt(this.Port)!=0{
|
||||
App[this.Port] = this
|
||||
this.Server.Handler = this
|
||||
//启动服务
|
||||
this.Server.Addr = ":" + this.Port
|
||||
this.Server.ListenAndServe()
|
||||
err:=this.Server.ListenAndServe()
|
||||
fmt.Println(err)
|
||||
ch <-1
|
||||
}
|
||||
|
||||
|
||||
}()
|
||||
|
||||
go func() {
|
||||
if ObjToCeilInt(this.TLSPort)!=0{
|
||||
App[this.TLSPort] = this
|
||||
this.Server.Handler = this
|
||||
//启动服务
|
||||
this.Server.Addr = ":" + this.TLSPort
|
||||
err:=this.Server.ListenAndServeTLS(this.Config.GetString("tlsCert"),this.Config.GetString("tlsKey"))
|
||||
fmt.Println(err)
|
||||
ch <-2
|
||||
}
|
||||
|
||||
|
||||
}()
|
||||
|
||||
value := <- ch
|
||||
fmt.Println("启动服务失败 : ", value)
|
||||
|
||||
}
|
||||
|
||||
@ -167,6 +197,9 @@ func (this *Application) SetConfig(configPath ...string) {
|
||||
this.Config.Put(k, v) //程序配置
|
||||
Config.Put(k, v) //系统配置
|
||||
}
|
||||
}else {
|
||||
fmt.Println("配置文件不存在,或者配置出错,使用缺省默认配置")
|
||||
|
||||
}
|
||||
//else {
|
||||
// //文件不存在则写入文件,存在不做处理
|
||||
|
5
var.go
5
var.go
@ -16,11 +16,14 @@ var Config = Map{
|
||||
"dbUser": "root",
|
||||
"dbPwd": "root",
|
||||
"dbPort": "3306",
|
||||
"port": "80",
|
||||
"port": "0",
|
||||
"cacheShortTime": 60 * 60 * 2,
|
||||
"cacheLongTime": 60 * 60 * 24 * 30,
|
||||
"sessionName": "HOTIME",
|
||||
"error": Map{},
|
||||
"debug":1,//debug 0关闭1开启
|
||||
"modeRouterStrict":false,//路由严格模式/a/b/c
|
||||
"tlsPort":"0",
|
||||
"tlsKey":"",
|
||||
"tlsCert":"",
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user