diff --git a/application.go b/application.go index 2142190..acc140d 100644 --- a/application.go +++ b/application.go @@ -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 } - App[this.Port] = this - this.Server.Handler = this - //启动服务 - this.Server.Addr = ":" + this.Port - this.Server.ListenAndServe() + + ch := make(chan int) + go func() { + + if ObjToCeilInt(this.Port)!=0{ + App[this.Port] = this + this.Server.Handler = this + //启动服务 + this.Server.Addr = ":" + this.Port + 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 { // //文件不存在则写入文件,存在不做处理 diff --git a/var.go b/var.go index 9a1df9b..08bb0a1 100644 --- a/var.go +++ b/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":"", }