Uh oh!
There was an error while loading. Please reload this page.
This repository was archived by the owner on Mar 19, 2025. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.go
More file actions
Latest commit
91 lines (79 loc) · 1.92 KB
/
Copy pathutil.go
File metadata and controls
91 lines (79 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package httpserver
import (
"encoding/json"
"github.com/gobestsdk/log"
"github.com/gobestsdk/types"
"io/ioutil"
"regexp"
"strings"
"time"
"net/http"
"strconv"
)
funcGetfilter(req*http.Request) (filtermap[string]interface{}) {
filter=make(map[string]interface{})
fork, vs:=rangereq.URL.Query() {
iflen(vs) >1||len(vs) <1 {
log.Warn(log.Fields{
"req.URL.Query()": "len(vs)>1",
"values": vs,
})
continue
}
v:=strings.TrimSpace(vs[0])
intv, err:=strconv.Atoi(v)
iferr==nil {
filter[k] =intv
continue
}
boolv, er:=strconv.ParseBool(v)
ifer==nil {
filter[k] =boolv
continue
}
t, te:=types.MustParseDate(v)
ifte==nil {
filter[k] =t
continue
}
ct, cte:=time.ParseInLocation(types.CommonDatetime, v, time.Now().Location())
ifcte==nil {
filter[k] =ct
continue
}
ifm, _:=regexp.MatchString(`^(-?)\d+\.(\d+)$`, v); m {
floatv, e:=strconv.ParseFloat(v, 64)
ife!=nil {
filter[k] =v
continue
}
filter[k] =floatv
continue
}
filter[k] =v
}
return
}
funcOptions(req*http.Request, resp http.ResponseWriter, contenttype, server, methodsstring) {
Header(resp, contenttype, server, methods)
resp.Write([]byte(""))
}
funcHeader(resp http.ResponseWriter, contenttype, server, methodsstring) {
resp.Header().Set("Access-Control-Allow-Origin", "*") //允许访问所有域
resp.Header().Add("Access-Control-Allow-Headers", "Content-Type,token") //header的类型
resp.Header().Set("content-type", contenttype)
resp.Header().Set("HttpServer", server)
resp.Header().Set("Access-Control-Allow-Methods", methods)
resp.Header().Set("Access-Control-Allow-Credentials", "true")
}
funcTo(req*http.Request, sinterface{}) (errerror) {
body, err:=ioutil.ReadAll(req.Body)
iferr!=nil {
returnerr
}
err=json.Unmarshal(body, s)
iferr!=nil {
returnerr
}
return
}