forked from golang/hotime
增加上传接口
This commit is contained in:
parent
efb6cb980e
commit
05c8159601
@ -49,7 +49,7 @@ type ColumnShow struct {
|
|||||||
Info bool
|
Info bool
|
||||||
Must bool
|
Must bool
|
||||||
Type string //空字符串表示
|
Type string //空字符串表示
|
||||||
Strict bool
|
Strict bool //name严格匹配必须是这个词才行
|
||||||
}
|
}
|
||||||
|
|
||||||
var ColumnNameType = []ColumnShow{
|
var ColumnNameType = []ColumnShow{
|
||||||
@ -86,6 +86,6 @@ var ColumnNameType = []ColumnShow{
|
|||||||
{"file", false, true, true, false, "file", false},
|
{"file", false, true, true, false, "file", false},
|
||||||
{"age", false, true, true, false, "", false},
|
{"age", false, true, true, false, "", false},
|
||||||
{"email", false, true, true, false, "", false},
|
{"email", false, true, true, false, "", false},
|
||||||
|
{"time", true, false, false, false, "", false},
|
||||||
{"level", false, false, true, false, "", false},
|
{"level", false, false, true, false, "", false},
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,8 @@
|
|||||||
"crossDomain": "auto",
|
"crossDomain": "auto",
|
||||||
"db": {
|
"db": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"host": "192.168.6.250",
|
"host": "192.168.6.253",
|
||||||
"name": "reg_gqt",
|
"name": "hotimego",
|
||||||
"password": "root",
|
"password": "root",
|
||||||
"port": "3306",
|
"port": "3306",
|
||||||
"prefix": "",
|
"prefix": "",
|
||||||
|
@ -2,10 +2,14 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"../../hotime"
|
"../../hotime"
|
||||||
|
"../../hotime/common"
|
||||||
"./admin"
|
"./admin"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"golang.org/x/net/websocket"
|
"golang.org/x/net/websocket"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -14,6 +18,46 @@ func main() {
|
|||||||
appIns := hotime.Init("config/config.json")
|
appIns := hotime.Init("config/config.json")
|
||||||
//RESTfull接口适配
|
//RESTfull接口适配
|
||||||
appIns.SetConnectListener(func(context *hotime.Context) bool {
|
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 ||
|
if len(context.RouterString) < 2 || len(context.RouterString) > 3 ||
|
||||||
!(context.Router[context.RouterString[0]] != nil &&
|
!(context.Router[context.RouterString[0]] != nil &&
|
||||||
context.Router[context.RouterString[0]][context.RouterString[1]] != nil) {
|
context.Router[context.RouterString[0]][context.RouterString[1]] != nil) {
|
||||||
|
Loading…
Reference in New Issue
Block a user