This commit is contained in:
hoteas 2019-07-01 04:35:04 +00:00
parent 5f2128f2ce
commit 03194f0f8e
3 changed files with 45 additions and 29 deletions

View File

@ -12,6 +12,7 @@ import (
"os"
"path/filepath"
"strconv"
"log"
"strings"
)
@ -86,7 +87,7 @@ func (this *Application) Run(router Router) {
defer func() {
if err := recover(); err != nil {
this.SetError(errors.New(fmt.Sprint(err)), LOG_FMT)
//fmt.Println(err)
//log.Println(err)
this.Run(router)
}
}()
@ -96,39 +97,49 @@ func (this *Application) Run(router Router) {
IsRun = true
}
ch := make(chan int)
if ObjToCeilInt(this.Port)!=0{
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)
log.Println(err)
ch <-1
}
}()
}else if ObjToCeilInt(this.TLSPort)!=0{
go func() {
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
}
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"))
log.Println(err)
ch <-2
}()
}()
}else{
log.Println("没有端口启用")
return
}
value := <- ch
fmt.Println("启动服务失败 : ", value)
log.Println("启动服务失败 : ", value)
}
//启动实例
@ -210,7 +221,7 @@ func (this *Application) SetConfig(configPath ...string) {
Config.Put(k, v) //系统配置
}
}else {
fmt.Println("配置文件不存在,或者配置出错,使用缺省默认配置")
log.Println("配置文件不存在,或者配置出错,使用缺省默认配置")
}
//else {
@ -229,7 +240,11 @@ func (this *Application) SetConfig(configPath ...string) {
var out bytes.Buffer
err = json.Indent(&out, []byte(this.Config.ToJsonString()), "", "\t")
//判断配置文件是否序列有变化有则修改配置,五则不变
//fmt.Println(len(btes))
if len(btes)!=0&&out.String()==string(btes){
return
}
err = ioutil.WriteFile(this.configPath, out.Bytes(), os.ModeAppend)
if err != nil {
@ -282,7 +297,7 @@ func (this *Application) urlSer(url string) (string, []string) {
func (this *Application) handler(w http.ResponseWriter, req *http.Request) {
o, s := this.urlSer(req.RequestURI)
_, s := this.urlSer(req.RequestURI)
//获取cookie
// 如果cookie存在直接将sessionId赋值为cookie.Value
// 如果cookie不存在就查找传入的参数中是否有token
@ -364,7 +379,7 @@ func (this *Application) handler(w http.ResponseWriter, req *http.Request) {
}
//url赋值
path := this.Config.GetString("tpt") + o
path := this.Config.GetString("tpt") + tempHandlerStr
//判断是否为默认
if path[len(path)-1] == '/' {

12
db.go
View File

@ -141,16 +141,16 @@ func (this *HoTimeDB) Row(resl *sql.Rows) []Map {
//
// stdout, err := cmd.StdoutPipe()
// if err != nil {
// log.Fatal(err)
// log.Println(err)
// }
//
// if err := cmd.Start(); err != nil {
// log.Fatal(err)
// log.Println(err)
// }
//
// bytes, err := ioutil.ReadAll(stdout)
// if err != nil {
// log.Fatal(err)
// log.Println(err)
// }
// err = ioutil.WriteFile(path, bytes, 0644)
// if err != nil {
@ -849,7 +849,7 @@ func (this *HoTimeDB) Update(table string, data Map, where Map) int64 {
res, err := this.Exec(query, qs...)
rows:=int64(0)
if err.GetError() == nil {
if err.GetError() == nil &&res!=nil{
rows, _ = res.RowsAffected()
}
@ -872,7 +872,7 @@ func (this *HoTimeDB) Delete(table string, data map[string]interface{}) int64 {
res, err := this.Exec(query, resWhere...)
rows:=int64(0)
if err.GetError() == nil {
if err.GetError() == nil &&res!=nil{
rows, _ = res.RowsAffected()
}
@ -913,7 +913,7 @@ func (this *HoTimeDB) Insert(table string, data map[string]interface{}) int64 {
res, err := this.Exec(query, values...)
id:=int64(0)
if err.GetError() == nil {
if err.GetError() == nil &&res!=nil{
id, this.LastErr.err = res.LastInsertId()
}

View File

@ -1,7 +1,8 @@
package hotime
import (
"fmt"
"log"
)
//框架层处理错误
@ -31,10 +32,10 @@ func(this *Error)SetError(err error,loglevel ...int){
}
if lev==LOG_FMT{
fmt.Println(err)
log.Println(err)
}
if lev==LOG_FILE{
fmt.Println(err)
log.Println(err)
}
this.err=err
return