forked from astaxie/bat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilter.go
40 lines (37 loc) · 804 Bytes
/
filter.go
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
package main
import (
"log"
"strings"
)
var methodList = []string{"GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"}
func filter(args []string) []string {
var i int
if inSlice(strings.ToUpper(args[i]), methodList) {
*method = strings.ToUpper(args[i])
i++
} else if len(args) > 0 && *method == "GET" {
for _, v := range args[1:] {
// defaults to either GET (with no request data) or POST (with request data).
// Params
strs := strings.Split(v, "=")
if len(strs) == 2 {
*method = "POST"
break
}
// files
strs = strings.Split(v, "@")
if len(strs) == 2 {
*method = "POST"
break
}
}
} else if *method == "GET" && body != "" {
*method = "POST"
}
if len(args) <= i {
log.Fatal("Miss the URL")
}
*URL = args[i]
i++
return args[i:]
}