-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpostman.go
62 lines (55 loc) · 1.32 KB
/
postman.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package restify
import (
"gorm.io/gorm/schema"
"reflect"
"strings"
)
type AuthType string
const (
AuthTypeNone AuthType = "none"
AuthTypeBasic AuthType = "basic"
AuthTypeBearer AuthType = "bearer"
AuthTypeDigest AuthType = "digest"
AuthTypeEdgeGrid AuthType = "edgegrid"
AuthTypeHawk AuthType = "hawk"
AuthTypeOAuth1 AuthType = "oauth1"
AuthTypeOAuth2 AuthType = "oauth2"
AuthTypeNTLM AuthType = "ntlm"
AuthTypeHeader AuthType = "header"
)
var postmanRegistered = false
var postmanAuthType = AuthTypeNone
var postmanHeaders = make(map[string]string)
func EnablePostman() {
postmanRegistered = true
}
func ModelDataFaker(schema *schema.Schema) interface{} {
var m = make(map[string]interface{})
for idx, _ := range schema.Fields {
field := schema.Fields[idx]
if field.AutoIncrement {
continue
}
var clone = reflect.New(field.FieldType)
var jsonField = field.Tag.Get("json")
if jsonField == "-" {
continue
}
fieldName := strings.Split(jsonField, ",")[0]
if fieldName == "" {
fieldName = field.DBName
}
m[fieldName] = clone.Interface()
}
return m
}
func SetPostmanAuthorization(_type AuthType, _value ...string) {
if _type == AuthTypeHeader {
postmanAuthType = "none"
for _, item := range _value {
postmanHeaders[item] = ""
}
return
}
postmanAuthType = _type
}