diff --git a/code/config.go b/code/config.go index 05482fc..f461426 100644 --- a/code/config.go +++ b/code/config.go @@ -49,7 +49,7 @@ type ColumnShow struct { Info bool Must bool Type string //空字符串表示 - Strict bool + Strict bool //name严格匹配必须是这个词才行 } var ColumnNameType = []ColumnShow{ @@ -86,6 +86,6 @@ var ColumnNameType = []ColumnShow{ {"file", false, true, true, false, "file", false}, {"age", false, true, true, false, "", false}, {"email", false, true, true, false, "", false}, - + {"time", true, false, false, false, "", false}, {"level", false, false, true, false, "", false}, } diff --git a/example/config/config.json b/example/config/config.json index 7d9edf8..5437206 100644 --- a/example/config/config.json +++ b/example/config/config.json @@ -12,8 +12,8 @@ "crossDomain": "auto", "db": { "mysql": { - "host": "192.168.6.250", - "name": "reg_gqt", + "host": "192.168.6.253", + "name": "hotimego", "password": "root", "port": "3306", "prefix": "", diff --git a/example/main.go b/example/main.go index 32c7ba0..94cf62d 100644 --- a/example/main.go +++ b/example/main.go @@ -2,10 +2,14 @@ package main import ( "../../hotime" + "../../hotime/common" "./admin" "errors" "fmt" "golang.org/x/net/websocket" + "io" + "os" + "strings" "time" ) @@ -14,6 +18,46 @@ func main() { appIns := hotime.Init("config/config.json") //RESTfull接口适配 appIns.SetConnectListener(func(context *hotime.Context) bool { + //文件上传接口 + if len(context.RouterString) == 1 && context.RouterString[0] == "file" && context.Req.Method == "POST" { + + //读取网络文件 + fi, fheader, err := context.Req.FormFile("file") + if err != nil { + context.Display(3, err) + return false + + } + filePath := context.Config.GetString("filePath") + if filePath == "" { + filePath = "file/2006/01/02/" + } + + path := time.Now().Format(filePath) + e := os.MkdirAll(context.Config.GetString("tpt")+"/"+path, os.ModeDir) + if e != nil { + context.Display(3, e) + return false + } + filePath = path + common.Md5(common.ObjToStr(common.RandX(100000, 9999999))) + fheader.Filename[strings.LastIndex(fheader.Filename, "."):] + newFile, e := os.Create(context.Config.GetString("tpt") + "/" + filePath) + + if e != nil { + context.Display(3, e) + return false + } + + _, e = io.Copy(newFile, fi) + + if e != nil { + context.Display(3, e) + return false + } + + context.Display(0, filePath) + return false + } + if len(context.RouterString) < 2 || len(context.RouterString) > 3 || !(context.Router[context.RouterString[0]] != nil && context.Router[context.RouterString[0]][context.RouterString[1]] != nil) {