本文整理汇总了Golang中github.com/google/martian/parse.NewResult函数的典型用法代码示例。如果您正苦于以下问题:Golang NewResult函数的具体用法?Golang NewResult怎么用?Golang NewResult使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewResult函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: filterFromJSON
// filterFromJSON takes a JSON message as a byte slice and returns a
// parse.Result that contains a URLFilter and a bitmask that represents the
// type of modifier.
//
// Example JSON configuration message:
// {
// "scheme": "https",
// "host": "example.com",
// "path": "/foo/bar",
// "rawQuery": "q=value",
// "scope": ["request", "response"],
// "modifier": { ... }
// }
func filterFromJSON(b []byte) (*parse.Result, error) {
msg := &filterJSON{}
if err := json.Unmarshal(b, msg); err != nil {
return nil, err
}
filter := NewFilter(&url.URL{
Scheme: msg.Scheme,
Host: msg.Host,
Path: msg.Path,
RawQuery: msg.Query,
})
r, err := parse.FromJSON(msg.Modifier)
if err != nil {
return nil, err
}
reqmod := r.RequestModifier()
if err != nil {
return nil, err
}
if reqmod != nil {
filter.SetRequestModifier(reqmod)
}
resmod := r.ResponseModifier()
if resmod != nil {
filter.SetResponseModifier(resmod)
}
return parse.NewResult(filter, msg.Scope)
}
示例2: groupFromJSON
// groupFromJSON builds a priority.Group from JSON.
//
// Example JSON:
// {
// "priority.Group": {
// "scope": ["request", "response"],
// "modifiers": [
// {
// "priority": 100, // Will run first.
// "modifier": { ... },
// },
// {
// "priority": 0, // Will run last.
// "modifier": { ... },
// }
// ]
// }
// }
func groupFromJSON(b []byte) (*parse.Result, error) {
msg := &groupJSON{}
if err := json.Unmarshal(b, msg); err != nil {
return nil, err
}
pg := NewGroup()
for _, m := range msg.Modifiers {
r, err := parse.FromJSON(m.Modifier)
if err != nil {
return nil, err
}
reqmod := r.RequestModifier()
if reqmod != nil {
pg.AddRequestModifier(reqmod, m.Priority)
}
resmod := r.ResponseModifier()
if resmod != nil {
pg.AddResponseModifier(resmod, m.Priority)
}
}
return parse.NewResult(pg, msg.Scope)
}
示例3: filterFromJSON
// filterFromJSON takes a JSON message and returns a querystring.Filter.
//
// Example JSON:
// {
// "name": "param",
// "value": "example",
// "scope": ["request", "response"],
// "modifier": { ... }
// }
func filterFromJSON(b []byte) (*parse.Result, error) {
msg := &filterJSON{}
if err := json.Unmarshal(b, msg); err != nil {
return nil, err
}
nameMatcher, err := regexp.Compile(msg.Name)
if err != nil {
return nil, err
}
valueMatcher, err := regexp.Compile(msg.Value)
if err != nil {
return nil, err
}
filter, err := NewFilter(nameMatcher, valueMatcher)
if err != nil {
return nil, err
}
r, err := parse.FromJSON(msg.Modifier)
if err != nil {
return nil, err
}
reqmod := r.RequestModifier()
filter.SetRequestModifier(reqmod)
resmod := r.ResponseModifier()
filter.SetResponseModifier(resmod)
return parse.NewResult(filter, msg.Scope)
}
示例4: verifierFromJSON
// verifierFromJSON builds a header.Verifier from JSON.
//
// Example JSON:
// {
// "name": "header.Verifier",
// "scope": ["request", "result"],
// "modifier": {
// "name": "Martian-Testing",
// "value": "true"
// }
// }
func verifierFromJSON(b []byte) (*parse.Result, error) {
msg := &verifierJSON{}
if err := json.Unmarshal(b, msg); err != nil {
return nil, err
}
return parse.NewResult(NewVerifier(msg.Name, msg.Value), msg.Scope)
}
示例5: loggerFromJSON
// loggerFromJSON builds a logger from JSON.
//
// Example JSON:
// {
// "log.Logger": {
// "scope": ["request", "response"]
// }
// }
func loggerFromJSON(b []byte) (*parse.Result, error) {
msg := &loggerJSON{}
if err := json.Unmarshal(b, msg); err != nil {
return nil, err
}
return parse.NewResult(NewLogger(), msg.Scope)
}
示例6: copyModifierFromJSON
// copyModifierFromJSON builds a copy modifier from JSON.
//
// Example JSON:
// {
// "header.Copy": {
// "scope": ["request", "response"],
// "from": "Original-Header",
// "to": "Copy-Header"
// }
// }
func copyModifierFromJSON(b []byte) (*parse.Result, error) {
msg := ©ModifierJSON{}
if err := json.Unmarshal(b, msg); err != nil {
return nil, err
}
return parse.NewResult(NewCopyModifier(msg.From, msg.To), msg.Scope)
}
示例7: modifierFromJSON
// modifierFromJSON builds a status.Modifier from JSON.
//
// Example JSON:
// {
// "status.Modifier": {
// "scope": ["response"],
// "statusCode": 401
// }
// }
func modifierFromJSON(b []byte) (*parse.Result, error) {
msg := &statusJSON{}
if err := json.Unmarshal(b, msg); err != nil {
return nil, err
}
return parse.NewResult(NewModifier(msg.StatusCode), msg.Scope)
}
示例8: blacklistModifierFromJSON
// blacklistModifierFromJSON takes a JSON message as a byte slice and returns
// a blacklistModifier and an error.
//
// Example JSON configuration message:
// {
// "names": ["X-Header", "Y-Header"],
// "scope": ["request", "result"]
// }
func blacklistModifierFromJSON(b []byte) (*parse.Result, error) {
msg := &blacklistModifierJSON{}
if err := json.Unmarshal(b, msg); err != nil {
return nil, err
}
return parse.NewResult(NewBlacklistModifier(msg.Names...), msg.Scope)
}
示例9: modifierFromJSON
// modifierFromJSON takes a JSON message as a byte slice and returns a
// body.Modifier and an error.
//
// Example JSON Configuration message:
// {
// "scope": ["request", "response"],
// "contentType": "text/plain",
// "body": "c29tZSBkYXRhIHdpdGggACBhbmQg77u/" // Base64 encoded body
// }
func modifierFromJSON(b []byte) (*parse.Result, error) {
msg := &modifierJSON{}
if err := json.Unmarshal(b, msg); err != nil {
return nil, err
}
mod := NewModifier(msg.Body, msg.ContentType)
return parse.NewResult(mod, msg.Scope)
}
示例10: modifierFromJSON
// modifierFromJSON takes a JSON message as a byte slice and returns
// a headerModifier and an error.
//
// Example JSON configuration message:
// {
// "scope": ["request", "result"],
// "name": "X-Martian",
// "value": "true"
// }
func modifierFromJSON(b []byte) (*parse.Result, error) {
msg := &modifierJSON{}
if err := json.Unmarshal(b, msg); err != nil {
return nil, err
}
modifier := NewModifier(msg.Name, msg.Value)
return parse.NewResult(modifier, msg.Scope)
}
示例11: loggerFromJSON
// loggerFromJSON builds a logger from JSON.
//
// Example JSON:
// {
// "log.Logger": {
// "scope": ["request", "response"],
// "includeBody": true
// }
// }
func loggerFromJSON(b []byte) (*parse.Result, error) {
msg := &loggerJSON{}
if err := json.Unmarshal(b, msg); err != nil {
return nil, err
}
l := NewLogger()
l.IncludeBody(msg.IncludeBody)
return parse.NewResult(l, msg.Scope)
}
示例12: loggerFromJSON
// loggerFromJSON builds a logger from JSON.
//
// Example JSON:
// {
// "log.Logger": {
// "scope": ["request", "response"],
// "headersOnly": true,
// "decode": true
// }
// }
func loggerFromJSON(b []byte) (*parse.Result, error) {
msg := &loggerJSON{}
if err := json.Unmarshal(b, msg); err != nil {
return nil, err
}
l := NewLogger()
l.SetHeadersOnly(msg.HeadersOnly)
l.SetDecode(msg.Decode)
return parse.NewResult(l, msg.Scope)
}
示例13: verifierFromJSON
// verifierFromJSON builds a method.Verifier from JSON.
//
// Example JSON:
// {
// "method.Verifier": {
// "scope": ["request"],
// "method": "POST"
// }
// }
func verifierFromJSON(b []byte) (*parse.Result, error) {
msg := &verifierJSON{}
if err := json.Unmarshal(b, msg); err != nil {
return nil, err
}
v, err := NewVerifier(msg.Method)
if err != nil {
return nil, err
}
return parse.NewResult(v, msg.Scope)
}
示例14: verifierFromJSON
// verifierFromJSON builds a martianurl.Verifier from JSON.
//
// Example modifier JSON:
// {
// "martianurl.Verifier": {
// "scope": ["request"],
// "scheme": "https",
// "host": "www.google.com",
// "path": "/proxy",
// "query": "testing=true"
// }
// }
func verifierFromJSON(b []byte) (*parse.Result, error) {
msg := &verifierJSON{}
if err := json.Unmarshal(b, msg); err != nil {
return nil, err
}
v := NewVerifier(&url.URL{
Scheme: msg.Scheme,
Host: msg.Host,
Path: msg.Path,
RawQuery: msg.Query,
})
return parse.NewResult(v, msg.Scope)
}
示例15: filterFromJSON
// filterFromJSON takes a JSON message and returns a querystring.Filter.
//
// Example JSON:
// {
// "name": "param",
// "value": "example",
// "scope": ["request", "response"],
// "modifier": { ... }
// }
func filterFromJSON(b []byte) (*parse.Result, error) {
msg := &filterJSON{}
if err := json.Unmarshal(b, msg); err != nil {
return nil, err
}
f := NewFilter(msg.Name, msg.Value)
r, err := parse.FromJSON(msg.Modifier)
if err != nil {
return nil, err
}
f.SetRequestModifier(r.RequestModifier())
f.SetResponseModifier(r.ResponseModifier())
return parse.NewResult(f, msg.Scope)
}