id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
sequence
docstring
stringlengths
6
2.61k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
85
252
166,800
goadesign/goa
middleware/security/jwt/resolver.go
SelectKeys
func (kr *GroupResolver) SelectKeys(req *http.Request) []Key { keyName := req.Header.Get(kr.keyHeader) kr.RLock() defer kr.RUnlock() if keyName != "" { return kr.keyMap[keyName] } var keys []Key for _, ks := range kr.keyMap { keys = append(keys, ks...) } return keys }
go
func (kr *GroupResolver) SelectKeys(req *http.Request) []Key { keyName := req.Header.Get(kr.keyHeader) kr.RLock() defer kr.RUnlock() if keyName != "" { return kr.keyMap[keyName] } var keys []Key for _, ks := range kr.keyMap { keys = append(keys, ks...) } return keys }
[ "func", "(", "kr", "*", "GroupResolver", ")", "SelectKeys", "(", "req", "*", "http", ".", "Request", ")", "[", "]", "Key", "{", "keyName", ":=", "req", ".", "Header", ".", "Get", "(", "kr", ".", "keyHeader", ")", "\n", "kr", ".", "RLock", "(", ")", "\n", "defer", "kr", ".", "RUnlock", "(", ")", "\n", "if", "keyName", "!=", "\"", "\"", "{", "return", "kr", ".", "keyMap", "[", "keyName", "]", "\n", "}", "\n", "var", "keys", "[", "]", "Key", "\n", "for", "_", ",", "ks", ":=", "range", "kr", ".", "keyMap", "{", "keys", "=", "append", "(", "keys", ",", "ks", "...", ")", "\n", "}", "\n", "return", "keys", "\n", "}" ]
// SelectKeys returns the keys in the group with the name identified by the request key selection // header. If the header does value does not match a specific group then all keys are returned.
[ "SelectKeys", "returns", "the", "keys", "in", "the", "group", "with", "the", "name", "identified", "by", "the", "request", "key", "selection", "header", ".", "If", "the", "header", "does", "value", "does", "not", "match", "a", "specific", "group", "then", "all", "keys", "are", "returned", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/middleware/security/jwt/resolver.go#L173-L185
166,801
goadesign/goa
design/dup.go
newDupper
func newDupper() *dupper { return &dupper{ dts: make(map[string]*UserTypeDefinition), dmts: make(map[string]*MediaTypeDefinition), } }
go
func newDupper() *dupper { return &dupper{ dts: make(map[string]*UserTypeDefinition), dmts: make(map[string]*MediaTypeDefinition), } }
[ "func", "newDupper", "(", ")", "*", "dupper", "{", "return", "&", "dupper", "{", "dts", ":", "make", "(", "map", "[", "string", "]", "*", "UserTypeDefinition", ")", ",", "dmts", ":", "make", "(", "map", "[", "string", "]", "*", "MediaTypeDefinition", ")", ",", "}", "\n", "}" ]
// newDupper returns a new initialized dupper.
[ "newDupper", "returns", "a", "new", "initialized", "dupper", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/dup.go#L22-L27
166,802
goadesign/goa
design/dup.go
DupUserType
func (d *dupper) DupUserType(ut *UserTypeDefinition) *UserTypeDefinition { return &UserTypeDefinition{ AttributeDefinition: d.DupAttribute(ut.AttributeDefinition), TypeName: ut.TypeName, } }
go
func (d *dupper) DupUserType(ut *UserTypeDefinition) *UserTypeDefinition { return &UserTypeDefinition{ AttributeDefinition: d.DupAttribute(ut.AttributeDefinition), TypeName: ut.TypeName, } }
[ "func", "(", "d", "*", "dupper", ")", "DupUserType", "(", "ut", "*", "UserTypeDefinition", ")", "*", "UserTypeDefinition", "{", "return", "&", "UserTypeDefinition", "{", "AttributeDefinition", ":", "d", ".", "DupAttribute", "(", "ut", ".", "AttributeDefinition", ")", ",", "TypeName", ":", "ut", ".", "TypeName", ",", "}", "\n", "}" ]
// DupUserType creates a copy of the given user type.
[ "DupUserType", "creates", "a", "copy", "of", "the", "given", "user", "type", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/dup.go#L30-L35
166,803
goadesign/goa
design/dup.go
DupAttribute
func (d *dupper) DupAttribute(att *AttributeDefinition) *AttributeDefinition { var valDup *dslengine.ValidationDefinition if att.Validation != nil { valDup = att.Validation.Dup() } dup := AttributeDefinition{ Type: att.Type, Description: att.Description, Validation: valDup, Metadata: att.Metadata, DefaultValue: att.DefaultValue, NonZeroAttributes: att.NonZeroAttributes, View: att.View, DSLFunc: att.DSLFunc, Example: att.Example, } return &dup }
go
func (d *dupper) DupAttribute(att *AttributeDefinition) *AttributeDefinition { var valDup *dslengine.ValidationDefinition if att.Validation != nil { valDup = att.Validation.Dup() } dup := AttributeDefinition{ Type: att.Type, Description: att.Description, Validation: valDup, Metadata: att.Metadata, DefaultValue: att.DefaultValue, NonZeroAttributes: att.NonZeroAttributes, View: att.View, DSLFunc: att.DSLFunc, Example: att.Example, } return &dup }
[ "func", "(", "d", "*", "dupper", ")", "DupAttribute", "(", "att", "*", "AttributeDefinition", ")", "*", "AttributeDefinition", "{", "var", "valDup", "*", "dslengine", ".", "ValidationDefinition", "\n", "if", "att", ".", "Validation", "!=", "nil", "{", "valDup", "=", "att", ".", "Validation", ".", "Dup", "(", ")", "\n", "}", "\n", "dup", ":=", "AttributeDefinition", "{", "Type", ":", "att", ".", "Type", ",", "Description", ":", "att", ".", "Description", ",", "Validation", ":", "valDup", ",", "Metadata", ":", "att", ".", "Metadata", ",", "DefaultValue", ":", "att", ".", "DefaultValue", ",", "NonZeroAttributes", ":", "att", ".", "NonZeroAttributes", ",", "View", ":", "att", ".", "View", ",", "DSLFunc", ":", "att", ".", "DSLFunc", ",", "Example", ":", "att", ".", "Example", ",", "}", "\n", "return", "&", "dup", "\n", "}" ]
// DupAttribute creates a copy of the given attribute.
[ "DupAttribute", "creates", "a", "copy", "of", "the", "given", "attribute", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/dup.go#L38-L55
166,804
goadesign/goa
design/dup.go
DupType
func (d *dupper) DupType(t DataType) DataType { switch actual := t.(type) { case Primitive: return t case *Array: return &Array{ElemType: d.DupAttribute(actual.ElemType)} case Object: res := make(Object, len(actual)) for n, att := range actual { res[n] = d.DupAttribute(att) } return res case *Hash: return &Hash{ KeyType: d.DupAttribute(actual.KeyType), ElemType: d.DupAttribute(actual.ElemType), } case *UserTypeDefinition: if u, ok := d.dts[actual.TypeName]; ok { return u } u := &UserTypeDefinition{ TypeName: actual.TypeName, } d.dts[u.TypeName] = u u.AttributeDefinition = d.DupAttribute(actual.AttributeDefinition) return u case *MediaTypeDefinition: if m, ok := d.dmts[actual.Identifier]; ok { return m } m := &MediaTypeDefinition{ Identifier: actual.Identifier, Links: actual.Links, Views: actual.Views, Resource: actual.Resource, } d.dmts[actual.Identifier] = m m.UserTypeDefinition = d.DupUserType(actual.UserTypeDefinition) return m } panic("unknown type " + t.Name()) }
go
func (d *dupper) DupType(t DataType) DataType { switch actual := t.(type) { case Primitive: return t case *Array: return &Array{ElemType: d.DupAttribute(actual.ElemType)} case Object: res := make(Object, len(actual)) for n, att := range actual { res[n] = d.DupAttribute(att) } return res case *Hash: return &Hash{ KeyType: d.DupAttribute(actual.KeyType), ElemType: d.DupAttribute(actual.ElemType), } case *UserTypeDefinition: if u, ok := d.dts[actual.TypeName]; ok { return u } u := &UserTypeDefinition{ TypeName: actual.TypeName, } d.dts[u.TypeName] = u u.AttributeDefinition = d.DupAttribute(actual.AttributeDefinition) return u case *MediaTypeDefinition: if m, ok := d.dmts[actual.Identifier]; ok { return m } m := &MediaTypeDefinition{ Identifier: actual.Identifier, Links: actual.Links, Views: actual.Views, Resource: actual.Resource, } d.dmts[actual.Identifier] = m m.UserTypeDefinition = d.DupUserType(actual.UserTypeDefinition) return m } panic("unknown type " + t.Name()) }
[ "func", "(", "d", "*", "dupper", ")", "DupType", "(", "t", "DataType", ")", "DataType", "{", "switch", "actual", ":=", "t", ".", "(", "type", ")", "{", "case", "Primitive", ":", "return", "t", "\n", "case", "*", "Array", ":", "return", "&", "Array", "{", "ElemType", ":", "d", ".", "DupAttribute", "(", "actual", ".", "ElemType", ")", "}", "\n", "case", "Object", ":", "res", ":=", "make", "(", "Object", ",", "len", "(", "actual", ")", ")", "\n", "for", "n", ",", "att", ":=", "range", "actual", "{", "res", "[", "n", "]", "=", "d", ".", "DupAttribute", "(", "att", ")", "\n", "}", "\n", "return", "res", "\n", "case", "*", "Hash", ":", "return", "&", "Hash", "{", "KeyType", ":", "d", ".", "DupAttribute", "(", "actual", ".", "KeyType", ")", ",", "ElemType", ":", "d", ".", "DupAttribute", "(", "actual", ".", "ElemType", ")", ",", "}", "\n", "case", "*", "UserTypeDefinition", ":", "if", "u", ",", "ok", ":=", "d", ".", "dts", "[", "actual", ".", "TypeName", "]", ";", "ok", "{", "return", "u", "\n", "}", "\n", "u", ":=", "&", "UserTypeDefinition", "{", "TypeName", ":", "actual", ".", "TypeName", ",", "}", "\n", "d", ".", "dts", "[", "u", ".", "TypeName", "]", "=", "u", "\n", "u", ".", "AttributeDefinition", "=", "d", ".", "DupAttribute", "(", "actual", ".", "AttributeDefinition", ")", "\n", "return", "u", "\n", "case", "*", "MediaTypeDefinition", ":", "if", "m", ",", "ok", ":=", "d", ".", "dmts", "[", "actual", ".", "Identifier", "]", ";", "ok", "{", "return", "m", "\n", "}", "\n", "m", ":=", "&", "MediaTypeDefinition", "{", "Identifier", ":", "actual", ".", "Identifier", ",", "Links", ":", "actual", ".", "Links", ",", "Views", ":", "actual", ".", "Views", ",", "Resource", ":", "actual", ".", "Resource", ",", "}", "\n", "d", ".", "dmts", "[", "actual", ".", "Identifier", "]", "=", "m", "\n", "m", ".", "UserTypeDefinition", "=", "d", ".", "DupUserType", "(", "actual", ".", "UserTypeDefinition", ")", "\n", "return", "m", "\n", "}", "\n", "panic", "(", "\"", "\"", "+", "t", ".", "Name", "(", ")", ")", "\n", "}" ]
// DupType creates a copy of the given data type.
[ "DupType", "creates", "a", "copy", "of", "the", "given", "data", "type", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/dup.go#L58-L100
166,805
goadesign/goa
goagen/gen_swagger/swagger.go
MarshalJSON
func (i Info) MarshalJSON() ([]byte, error) { return marshalJSON(_Info(i), i.Extensions) }
go
func (i Info) MarshalJSON() ([]byte, error) { return marshalJSON(_Info(i), i.Extensions) }
[ "func", "(", "i", "Info", ")", "MarshalJSON", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "return", "marshalJSON", "(", "_Info", "(", "i", ")", ",", "i", ".", "Extensions", ")", "\n", "}" ]
// MarshalJSON returns the JSON encoding of i.
[ "MarshalJSON", "returns", "the", "JSON", "encoding", "of", "i", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/goagen/gen_swagger/swagger.go#L327-L329
166,806
goadesign/goa
goagen/gen_swagger/swagger.go
MarshalJSON
func (o Operation) MarshalJSON() ([]byte, error) { return marshalJSON(_Operation(o), o.Extensions) }
go
func (o Operation) MarshalJSON() ([]byte, error) { return marshalJSON(_Operation(o), o.Extensions) }
[ "func", "(", "o", "Operation", ")", "MarshalJSON", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "return", "marshalJSON", "(", "_Operation", "(", "o", ")", ",", "o", ".", "Extensions", ")", "\n", "}" ]
// MarshalJSON returns the JSON encoding of o.
[ "MarshalJSON", "returns", "the", "JSON", "encoding", "of", "o", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/goagen/gen_swagger/swagger.go#L337-L339
166,807
goadesign/goa
goagen/gen_swagger/swagger.go
MarshalJSON
func (r Response) MarshalJSON() ([]byte, error) { return marshalJSON(_Response(r), r.Extensions) }
go
func (r Response) MarshalJSON() ([]byte, error) { return marshalJSON(_Response(r), r.Extensions) }
[ "func", "(", "r", "Response", ")", "MarshalJSON", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "return", "marshalJSON", "(", "_Response", "(", "r", ")", ",", "r", ".", "Extensions", ")", "\n", "}" ]
// MarshalJSON returns the JSON encoding of r.
[ "MarshalJSON", "returns", "the", "JSON", "encoding", "of", "r", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/goagen/gen_swagger/swagger.go#L347-L349
166,808
goadesign/goa
goagen/gen_swagger/swagger.go
MarshalJSON
func (s SecurityDefinition) MarshalJSON() ([]byte, error) { return marshalJSON(_SecurityDefinition(s), s.Extensions) }
go
func (s SecurityDefinition) MarshalJSON() ([]byte, error) { return marshalJSON(_SecurityDefinition(s), s.Extensions) }
[ "func", "(", "s", "SecurityDefinition", ")", "MarshalJSON", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "return", "marshalJSON", "(", "_SecurityDefinition", "(", "s", ")", ",", "s", ".", "Extensions", ")", "\n", "}" ]
// MarshalJSON returns the JSON encoding of s.
[ "MarshalJSON", "returns", "the", "JSON", "encoding", "of", "s", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/goagen/gen_swagger/swagger.go#L352-L354
166,809
goadesign/goa
goagen/gen_swagger/swagger.go
mustGenerate
func mustGenerate(meta dslengine.MetadataDefinition) bool { if m, ok := meta["swagger:generate"]; ok { if len(m) > 0 && m[0] == "false" { return false } } return true }
go
func mustGenerate(meta dslengine.MetadataDefinition) bool { if m, ok := meta["swagger:generate"]; ok { if len(m) > 0 && m[0] == "false" { return false } } return true }
[ "func", "mustGenerate", "(", "meta", "dslengine", ".", "MetadataDefinition", ")", "bool", "{", "if", "m", ",", "ok", ":=", "meta", "[", "\"", "\"", "]", ";", "ok", "{", "if", "len", "(", "m", ")", ">", "0", "&&", "m", "[", "0", "]", "==", "\"", "\"", "{", "return", "false", "\n", "}", "\n", "}", "\n", "return", "true", "\n", "}" ]
// mustGenerate returns true if the metadata indicates that a Swagger specification should be // generated, false otherwise.
[ "mustGenerate", "returns", "true", "if", "the", "metadata", "indicates", "that", "a", "Swagger", "specification", "should", "be", "generated", "false", "otherwise", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/goagen/gen_swagger/swagger.go#L469-L476
166,810
goadesign/goa
goagen/gen_swagger/swagger.go
toString
func toString(val interface{}) string { switch actual := val.(type) { case string: return actual case int: return strconv.Itoa(actual) case float64: return strconv.FormatFloat(actual, 'f', -1, 64) case bool: return strconv.FormatBool(actual) default: panic("unexpected key type") } }
go
func toString(val interface{}) string { switch actual := val.(type) { case string: return actual case int: return strconv.Itoa(actual) case float64: return strconv.FormatFloat(actual, 'f', -1, 64) case bool: return strconv.FormatBool(actual) default: panic("unexpected key type") } }
[ "func", "toString", "(", "val", "interface", "{", "}", ")", "string", "{", "switch", "actual", ":=", "val", ".", "(", "type", ")", "{", "case", "string", ":", "return", "actual", "\n", "case", "int", ":", "return", "strconv", ".", "Itoa", "(", "actual", ")", "\n", "case", "float64", ":", "return", "strconv", ".", "FormatFloat", "(", "actual", ",", "'f'", ",", "-", "1", ",", "64", ")", "\n", "case", "bool", ":", "return", "strconv", ".", "FormatBool", "(", "actual", ")", "\n", "default", ":", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "}" ]
// toString returns the string representation of the given type.
[ "toString", "returns", "the", "string", "representation", "of", "the", "given", "type", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/goagen/gen_swagger/swagger.go#L753-L766
166,811
goadesign/goa
goagen/codegen/validation.go
init
func init() { var err error fm := template.FuncMap{ "tabs": Tabs, "slice": toSlice, "oneof": oneof, "constant": constant, "goifyAtt": GoifyAtt, "add": Add, } if enumValT, err = template.New("enum").Funcs(fm).Parse(enumValTmpl); err != nil { panic(err) } if formatValT, err = template.New("format").Funcs(fm).Parse(formatValTmpl); err != nil { panic(err) } if patternValT, err = template.New("pattern").Funcs(fm).Parse(patternValTmpl); err != nil { panic(err) } if minMaxValT, err = template.New("minMax").Funcs(fm).Parse(minMaxValTmpl); err != nil { panic(err) } if lengthValT, err = template.New("length").Funcs(fm).Parse(lengthValTmpl); err != nil { panic(err) } if requiredValT, err = template.New("required").Funcs(fm).Parse(requiredValTmpl); err != nil { panic(err) } }
go
func init() { var err error fm := template.FuncMap{ "tabs": Tabs, "slice": toSlice, "oneof": oneof, "constant": constant, "goifyAtt": GoifyAtt, "add": Add, } if enumValT, err = template.New("enum").Funcs(fm).Parse(enumValTmpl); err != nil { panic(err) } if formatValT, err = template.New("format").Funcs(fm).Parse(formatValTmpl); err != nil { panic(err) } if patternValT, err = template.New("pattern").Funcs(fm).Parse(patternValTmpl); err != nil { panic(err) } if minMaxValT, err = template.New("minMax").Funcs(fm).Parse(minMaxValTmpl); err != nil { panic(err) } if lengthValT, err = template.New("length").Funcs(fm).Parse(lengthValTmpl); err != nil { panic(err) } if requiredValT, err = template.New("required").Funcs(fm).Parse(requiredValTmpl); err != nil { panic(err) } }
[ "func", "init", "(", ")", "{", "var", "err", "error", "\n", "fm", ":=", "template", ".", "FuncMap", "{", "\"", "\"", ":", "Tabs", ",", "\"", "\"", ":", "toSlice", ",", "\"", "\"", ":", "oneof", ",", "\"", "\"", ":", "constant", ",", "\"", "\"", ":", "GoifyAtt", ",", "\"", "\"", ":", "Add", ",", "}", "\n", "if", "enumValT", ",", "err", "=", "template", ".", "New", "(", "\"", "\"", ")", ".", "Funcs", "(", "fm", ")", ".", "Parse", "(", "enumValTmpl", ")", ";", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "if", "formatValT", ",", "err", "=", "template", ".", "New", "(", "\"", "\"", ")", ".", "Funcs", "(", "fm", ")", ".", "Parse", "(", "formatValTmpl", ")", ";", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "if", "patternValT", ",", "err", "=", "template", ".", "New", "(", "\"", "\"", ")", ".", "Funcs", "(", "fm", ")", ".", "Parse", "(", "patternValTmpl", ")", ";", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "if", "minMaxValT", ",", "err", "=", "template", ".", "New", "(", "\"", "\"", ")", ".", "Funcs", "(", "fm", ")", ".", "Parse", "(", "minMaxValTmpl", ")", ";", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "if", "lengthValT", ",", "err", "=", "template", ".", "New", "(", "\"", "\"", ")", ".", "Funcs", "(", "fm", ")", ".", "Parse", "(", "lengthValTmpl", ")", ";", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "if", "requiredValT", ",", "err", "=", "template", ".", "New", "(", "\"", "\"", ")", ".", "Funcs", "(", "fm", ")", ".", "Parse", "(", "requiredValTmpl", ")", ";", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "}" ]
// init instantiates the templates.
[ "init", "instantiates", "the", "templates", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/goagen/codegen/validation.go#L24-L52
166,812
goadesign/goa
goagen/codegen/validation.go
NewValidator
func NewValidator() *Validator { var ( v = &Validator{seen: make(map[string]*bytes.Buffer)} err error ) fm := template.FuncMap{ "tabs": Tabs, "slice": toSlice, "oneof": oneof, "constant": constant, "goifyAtt": GoifyAtt, "add": Add, "recurseAttribute": v.recurseAttribute, } v.arrayValT, err = template.New("array").Funcs(fm).Parse(arrayValTmpl) if err != nil { panic(err) } v.hashValT, err = template.New("hash").Funcs(fm).Parse(hashValTmpl) if err != nil { panic(err) } v.userValT, err = template.New("user").Funcs(fm).Parse(userValTmpl) if err != nil { panic(err) } return v }
go
func NewValidator() *Validator { var ( v = &Validator{seen: make(map[string]*bytes.Buffer)} err error ) fm := template.FuncMap{ "tabs": Tabs, "slice": toSlice, "oneof": oneof, "constant": constant, "goifyAtt": GoifyAtt, "add": Add, "recurseAttribute": v.recurseAttribute, } v.arrayValT, err = template.New("array").Funcs(fm).Parse(arrayValTmpl) if err != nil { panic(err) } v.hashValT, err = template.New("hash").Funcs(fm).Parse(hashValTmpl) if err != nil { panic(err) } v.userValT, err = template.New("user").Funcs(fm).Parse(userValTmpl) if err != nil { panic(err) } return v }
[ "func", "NewValidator", "(", ")", "*", "Validator", "{", "var", "(", "v", "=", "&", "Validator", "{", "seen", ":", "make", "(", "map", "[", "string", "]", "*", "bytes", ".", "Buffer", ")", "}", "\n", "err", "error", "\n", ")", "\n", "fm", ":=", "template", ".", "FuncMap", "{", "\"", "\"", ":", "Tabs", ",", "\"", "\"", ":", "toSlice", ",", "\"", "\"", ":", "oneof", ",", "\"", "\"", ":", "constant", ",", "\"", "\"", ":", "GoifyAtt", ",", "\"", "\"", ":", "Add", ",", "\"", "\"", ":", "v", ".", "recurseAttribute", ",", "}", "\n", "v", ".", "arrayValT", ",", "err", "=", "template", ".", "New", "(", "\"", "\"", ")", ".", "Funcs", "(", "fm", ")", ".", "Parse", "(", "arrayValTmpl", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "v", ".", "hashValT", ",", "err", "=", "template", ".", "New", "(", "\"", "\"", ")", ".", "Funcs", "(", "fm", ")", ".", "Parse", "(", "hashValTmpl", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "v", ".", "userValT", ",", "err", "=", "template", ".", "New", "(", "\"", "\"", ")", ".", "Funcs", "(", "fm", ")", ".", "Parse", "(", "userValTmpl", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "return", "v", "\n", "}" ]
// NewValidator instantiates a validate code generator.
[ "NewValidator", "instantiates", "a", "validate", "code", "generator", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/goagen/codegen/validation.go#L63-L90
166,813
goadesign/goa
goagen/codegen/validation.go
Code
func (v *Validator) Code(att *design.AttributeDefinition, nonzero, required, hasDefault bool, target, context string, depth int, private bool) string { if _, ok := att.Metadata["struct:field:type"]; ok { // Skip validation generation for attributes with custom types return "" } buf := v.recurse(att, nonzero, required, hasDefault, target, context, depth, private) return buf.String() }
go
func (v *Validator) Code(att *design.AttributeDefinition, nonzero, required, hasDefault bool, target, context string, depth int, private bool) string { if _, ok := att.Metadata["struct:field:type"]; ok { // Skip validation generation for attributes with custom types return "" } buf := v.recurse(att, nonzero, required, hasDefault, target, context, depth, private) return buf.String() }
[ "func", "(", "v", "*", "Validator", ")", "Code", "(", "att", "*", "design", ".", "AttributeDefinition", ",", "nonzero", ",", "required", ",", "hasDefault", "bool", ",", "target", ",", "context", "string", ",", "depth", "int", ",", "private", "bool", ")", "string", "{", "if", "_", ",", "ok", ":=", "att", ".", "Metadata", "[", "\"", "\"", "]", ";", "ok", "{", "// Skip validation generation for attributes with custom types", "return", "\"", "\"", "\n", "}", "\n", "buf", ":=", "v", ".", "recurse", "(", "att", ",", "nonzero", ",", "required", ",", "hasDefault", ",", "target", ",", "context", ",", "depth", ",", "private", ")", "\n", "return", "buf", ".", "String", "(", ")", "\n", "}" ]
// Code produces Go code that runs the validation checks recursively over the given attribute.
[ "Code", "produces", "Go", "code", "that", "runs", "the", "validation", "checks", "recursively", "over", "the", "given", "attribute", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/goagen/codegen/validation.go#L93-L100
166,814
goadesign/goa
goagen/codegen/validation.go
renderInteger
func renderInteger(f float64) string { if f > math.Nextafter(float64(math.MaxInt64), 0) { return fmt.Sprintf("%d", int64(math.MaxInt64)) } if f < math.Nextafter(float64(math.MinInt64), 0) { return fmt.Sprintf("%d", int64(math.MinInt64)) } return fmt.Sprintf("%d", int64(f)) }
go
func renderInteger(f float64) string { if f > math.Nextafter(float64(math.MaxInt64), 0) { return fmt.Sprintf("%d", int64(math.MaxInt64)) } if f < math.Nextafter(float64(math.MinInt64), 0) { return fmt.Sprintf("%d", int64(math.MinInt64)) } return fmt.Sprintf("%d", int64(f)) }
[ "func", "renderInteger", "(", "f", "float64", ")", "string", "{", "if", "f", ">", "math", ".", "Nextafter", "(", "float64", "(", "math", ".", "MaxInt64", ")", ",", "0", ")", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "int64", "(", "math", ".", "MaxInt64", ")", ")", "\n", "}", "\n", "if", "f", "<", "math", ".", "Nextafter", "(", "float64", "(", "math", ".", "MinInt64", ")", ",", "0", ")", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "int64", "(", "math", ".", "MinInt64", ")", ")", "\n", "}", "\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "int64", "(", "f", ")", ")", "\n", "}" ]
// renderInteger renders a max or min value properly, taking into account // overflows due to casting from a float value.
[ "renderInteger", "renders", "a", "max", "or", "min", "value", "properly", "taking", "into", "account", "overflows", "due", "to", "casting", "from", "a", "float", "value", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/goagen/codegen/validation.go#L432-L440
166,815
goadesign/goa
mux.go
NewMux
func NewMux() ServeMux { r := httptreemux.New() r.EscapeAddedRoutes = true return &mux{ router: r, handles: make(map[string]MuxHandler), } }
go
func NewMux() ServeMux { r := httptreemux.New() r.EscapeAddedRoutes = true return &mux{ router: r, handles: make(map[string]MuxHandler), } }
[ "func", "NewMux", "(", ")", "ServeMux", "{", "r", ":=", "httptreemux", ".", "New", "(", ")", "\n", "r", ".", "EscapeAddedRoutes", "=", "true", "\n", "return", "&", "mux", "{", "router", ":", "r", ",", "handles", ":", "make", "(", "map", "[", "string", "]", "MuxHandler", ")", ",", "}", "\n", "}" ]
// NewMux returns a Mux.
[ "NewMux", "returns", "a", "Mux", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/mux.go#L53-L60
166,816
goadesign/goa
mux.go
Handle
func (m *mux) Handle(method, path string, handle MuxHandler) { hthandle := func(rw http.ResponseWriter, req *http.Request, htparams map[string]string) { params := req.URL.Query() for n, p := range htparams { params.Set(n, p) } handle(rw, req, params) } m.handles[method+path] = handle m.router.Handle(method, path, hthandle) }
go
func (m *mux) Handle(method, path string, handle MuxHandler) { hthandle := func(rw http.ResponseWriter, req *http.Request, htparams map[string]string) { params := req.URL.Query() for n, p := range htparams { params.Set(n, p) } handle(rw, req, params) } m.handles[method+path] = handle m.router.Handle(method, path, hthandle) }
[ "func", "(", "m", "*", "mux", ")", "Handle", "(", "method", ",", "path", "string", ",", "handle", "MuxHandler", ")", "{", "hthandle", ":=", "func", "(", "rw", "http", ".", "ResponseWriter", ",", "req", "*", "http", ".", "Request", ",", "htparams", "map", "[", "string", "]", "string", ")", "{", "params", ":=", "req", ".", "URL", ".", "Query", "(", ")", "\n", "for", "n", ",", "p", ":=", "range", "htparams", "{", "params", ".", "Set", "(", "n", ",", "p", ")", "\n", "}", "\n", "handle", "(", "rw", ",", "req", ",", "params", ")", "\n", "}", "\n", "m", ".", "handles", "[", "method", "+", "path", "]", "=", "handle", "\n", "m", ".", "router", ".", "Handle", "(", "method", ",", "path", ",", "hthandle", ")", "\n", "}" ]
// Handle sets the handler for the given verb and path.
[ "Handle", "sets", "the", "handler", "for", "the", "given", "verb", "and", "path", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/mux.go#L63-L73
166,817
goadesign/goa
mux.go
HandleNotFound
func (m *mux) HandleNotFound(handle MuxHandler) { nfh := func(rw http.ResponseWriter, req *http.Request) { handle(rw, req, nil) } m.router.NotFoundHandler = nfh }
go
func (m *mux) HandleNotFound(handle MuxHandler) { nfh := func(rw http.ResponseWriter, req *http.Request) { handle(rw, req, nil) } m.router.NotFoundHandler = nfh }
[ "func", "(", "m", "*", "mux", ")", "HandleNotFound", "(", "handle", "MuxHandler", ")", "{", "nfh", ":=", "func", "(", "rw", "http", ".", "ResponseWriter", ",", "req", "*", "http", ".", "Request", ")", "{", "handle", "(", "rw", ",", "req", ",", "nil", ")", "\n", "}", "\n", "m", ".", "router", ".", "NotFoundHandler", "=", "nfh", "\n", "}" ]
// HandleNotFound sets the MuxHandler invoked for requests that don't match any // handler registered with Handle.
[ "HandleNotFound", "sets", "the", "MuxHandler", "invoked", "for", "requests", "that", "don", "t", "match", "any", "handler", "registered", "with", "Handle", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/mux.go#L77-L82
166,818
goadesign/goa
mux.go
HandleMethodNotAllowed
func (m *mux) HandleMethodNotAllowed(handle MethodNotAllowedHandler) { mna := func(rw http.ResponseWriter, req *http.Request, methods map[string]httptreemux.HandlerFunc) { handle(rw, req, nil, methods) } m.router.MethodNotAllowedHandler = mna }
go
func (m *mux) HandleMethodNotAllowed(handle MethodNotAllowedHandler) { mna := func(rw http.ResponseWriter, req *http.Request, methods map[string]httptreemux.HandlerFunc) { handle(rw, req, nil, methods) } m.router.MethodNotAllowedHandler = mna }
[ "func", "(", "m", "*", "mux", ")", "HandleMethodNotAllowed", "(", "handle", "MethodNotAllowedHandler", ")", "{", "mna", ":=", "func", "(", "rw", "http", ".", "ResponseWriter", ",", "req", "*", "http", ".", "Request", ",", "methods", "map", "[", "string", "]", "httptreemux", ".", "HandlerFunc", ")", "{", "handle", "(", "rw", ",", "req", ",", "nil", ",", "methods", ")", "\n", "}", "\n", "m", ".", "router", ".", "MethodNotAllowedHandler", "=", "mna", "\n", "}" ]
// HandleMethodNotAllowed sets the MuxHandler invoked for requests that match // the path of a handler but not its HTTP method.
[ "HandleMethodNotAllowed", "sets", "the", "MuxHandler", "invoked", "for", "requests", "that", "match", "the", "path", "of", "a", "handler", "but", "not", "its", "HTTP", "method", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/mux.go#L86-L91
166,819
goadesign/goa
mux.go
Lookup
func (m *mux) Lookup(method, path string) MuxHandler { return m.handles[method+path] }
go
func (m *mux) Lookup(method, path string) MuxHandler { return m.handles[method+path] }
[ "func", "(", "m", "*", "mux", ")", "Lookup", "(", "method", ",", "path", "string", ")", "MuxHandler", "{", "return", "m", ".", "handles", "[", "method", "+", "path", "]", "\n", "}" ]
// Lookup returns the MuxHandler associated with the given method and path.
[ "Lookup", "returns", "the", "MuxHandler", "associated", "with", "the", "given", "method", "and", "path", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/mux.go#L94-L96
166,820
goadesign/goa
mux.go
ServeHTTP
func (m *mux) ServeHTTP(rw http.ResponseWriter, req *http.Request) { m.router.ServeHTTP(rw, req) }
go
func (m *mux) ServeHTTP(rw http.ResponseWriter, req *http.Request) { m.router.ServeHTTP(rw, req) }
[ "func", "(", "m", "*", "mux", ")", "ServeHTTP", "(", "rw", "http", ".", "ResponseWriter", ",", "req", "*", "http", ".", "Request", ")", "{", "m", ".", "router", ".", "ServeHTTP", "(", "rw", ",", "req", ")", "\n", "}" ]
// ServeHTTP is the function called back by the underlying HTTP server to handle incoming requests.
[ "ServeHTTP", "is", "the", "function", "called", "back", "by", "the", "underlying", "HTTP", "server", "to", "handle", "incoming", "requests", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/mux.go#L99-L101
166,821
goadesign/goa
middleware/xray/segment.go
NewSegment
func NewSegment(name, traceID, spanID string, conn net.Conn) *Segment { return &Segment{ Mutex: &sync.Mutex{}, Name: name, TraceID: traceID, ID: spanID, StartTime: now(), InProgress: true, conn: conn, } }
go
func NewSegment(name, traceID, spanID string, conn net.Conn) *Segment { return &Segment{ Mutex: &sync.Mutex{}, Name: name, TraceID: traceID, ID: spanID, StartTime: now(), InProgress: true, conn: conn, } }
[ "func", "NewSegment", "(", "name", ",", "traceID", ",", "spanID", "string", ",", "conn", "net", ".", "Conn", ")", "*", "Segment", "{", "return", "&", "Segment", "{", "Mutex", ":", "&", "sync", ".", "Mutex", "{", "}", ",", "Name", ":", "name", ",", "TraceID", ":", "traceID", ",", "ID", ":", "spanID", ",", "StartTime", ":", "now", "(", ")", ",", "InProgress", ":", "true", ",", "conn", ":", "conn", ",", "}", "\n", "}" ]
// NewSegment creates a new segment that gets written to the given connection // on close.
[ "NewSegment", "creates", "a", "new", "segment", "that", "gets", "written", "to", "the", "given", "connection", "on", "close", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/middleware/xray/segment.go#L153-L163
166,822
goadesign/goa
middleware/xray/segment.go
RecordResponse
func (s *Segment) RecordResponse(resp *http.Response) { s.Lock() defer s.Unlock() if s.HTTP == nil { s.HTTP = &HTTP{} } s.recordStatusCode(resp.StatusCode) s.HTTP.Response = responseData(resp) }
go
func (s *Segment) RecordResponse(resp *http.Response) { s.Lock() defer s.Unlock() if s.HTTP == nil { s.HTTP = &HTTP{} } s.recordStatusCode(resp.StatusCode) s.HTTP.Response = responseData(resp) }
[ "func", "(", "s", "*", "Segment", ")", "RecordResponse", "(", "resp", "*", "http", ".", "Response", ")", "{", "s", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "Unlock", "(", ")", "\n\n", "if", "s", ".", "HTTP", "==", "nil", "{", "s", ".", "HTTP", "=", "&", "HTTP", "{", "}", "\n", "}", "\n\n", "s", ".", "recordStatusCode", "(", "resp", ".", "StatusCode", ")", "\n\n", "s", ".", "HTTP", ".", "Response", "=", "responseData", "(", "resp", ")", "\n", "}" ]
// RecordResponse traces a response. // // It sets Throttle, Fault, Error and HTTP.Response
[ "RecordResponse", "traces", "a", "response", ".", "It", "sets", "Throttle", "Fault", "Error", "and", "HTTP", ".", "Response" ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/middleware/xray/segment.go#L183-L194
166,823
goadesign/goa
middleware/xray/segment.go
RecordContextResponse
func (s *Segment) RecordContextResponse(ctx context.Context) { resp := goa.ContextResponse(ctx) if resp == nil { return } s.Lock() defer s.Unlock() if s.HTTP == nil { s.HTTP = &HTTP{} } s.recordStatusCode(resp.Status) s.HTTP.Response = &Response{resp.Status, int64(resp.Length)} }
go
func (s *Segment) RecordContextResponse(ctx context.Context) { resp := goa.ContextResponse(ctx) if resp == nil { return } s.Lock() defer s.Unlock() if s.HTTP == nil { s.HTTP = &HTTP{} } s.recordStatusCode(resp.Status) s.HTTP.Response = &Response{resp.Status, int64(resp.Length)} }
[ "func", "(", "s", "*", "Segment", ")", "RecordContextResponse", "(", "ctx", "context", ".", "Context", ")", "{", "resp", ":=", "goa", ".", "ContextResponse", "(", "ctx", ")", "\n", "if", "resp", "==", "nil", "{", "return", "\n", "}", "\n\n", "s", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "Unlock", "(", ")", "\n\n", "if", "s", ".", "HTTP", "==", "nil", "{", "s", ".", "HTTP", "=", "&", "HTTP", "{", "}", "\n", "}", "\n\n", "s", ".", "recordStatusCode", "(", "resp", ".", "Status", ")", "\n", "s", ".", "HTTP", ".", "Response", "=", "&", "Response", "{", "resp", ".", "Status", ",", "int64", "(", "resp", ".", "Length", ")", "}", "\n", "}" ]
// RecordContextResponse traces a context response if present in the context // // It sets Throttle, Fault, Error and HTTP.Response
[ "RecordContextResponse", "traces", "a", "context", "response", "if", "present", "in", "the", "context", "It", "sets", "Throttle", "Fault", "Error", "and", "HTTP", ".", "Response" ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/middleware/xray/segment.go#L199-L214
166,824
goadesign/goa
middleware/xray/segment.go
NewSubsegment
func (s *Segment) NewSubsegment(name string) *Segment { s.Lock() defer s.Unlock() sub := &Segment{ Mutex: &sync.Mutex{}, ID: NewID(), TraceID: s.TraceID, ParentID: s.ID, Type: "subsegment", Name: name, StartTime: now(), InProgress: true, Parent: s, conn: s.conn, } s.Subsegments = append(s.Subsegments, sub) s.counter++ return sub }
go
func (s *Segment) NewSubsegment(name string) *Segment { s.Lock() defer s.Unlock() sub := &Segment{ Mutex: &sync.Mutex{}, ID: NewID(), TraceID: s.TraceID, ParentID: s.ID, Type: "subsegment", Name: name, StartTime: now(), InProgress: true, Parent: s, conn: s.conn, } s.Subsegments = append(s.Subsegments, sub) s.counter++ return sub }
[ "func", "(", "s", "*", "Segment", ")", "NewSubsegment", "(", "name", "string", ")", "*", "Segment", "{", "s", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "Unlock", "(", ")", "\n\n", "sub", ":=", "&", "Segment", "{", "Mutex", ":", "&", "sync", ".", "Mutex", "{", "}", ",", "ID", ":", "NewID", "(", ")", ",", "TraceID", ":", "s", ".", "TraceID", ",", "ParentID", ":", "s", ".", "ID", ",", "Type", ":", "\"", "\"", ",", "Name", ":", "name", ",", "StartTime", ":", "now", "(", ")", ",", "InProgress", ":", "true", ",", "Parent", ":", "s", ",", "conn", ":", "s", ".", "conn", ",", "}", "\n", "s", ".", "Subsegments", "=", "append", "(", "s", ".", "Subsegments", ",", "sub", ")", "\n", "s", ".", "counter", "++", "\n", "return", "sub", "\n", "}" ]
// NewSubsegment creates a subsegment of s.
[ "NewSubsegment", "creates", "a", "subsegment", "of", "s", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/middleware/xray/segment.go#L251-L270
166,825
goadesign/goa
middleware/xray/segment.go
AddAnnotation
func (s *Segment) AddAnnotation(key string, value string) { s.addAnnotation(key, value) }
go
func (s *Segment) AddAnnotation(key string, value string) { s.addAnnotation(key, value) }
[ "func", "(", "s", "*", "Segment", ")", "AddAnnotation", "(", "key", "string", ",", "value", "string", ")", "{", "s", ".", "addAnnotation", "(", "key", ",", "value", ")", "\n", "}" ]
// AddAnnotation adds a key-value pair that can be queried by AWS X-Ray.
[ "AddAnnotation", "adds", "a", "key", "-", "value", "pair", "that", "can", "be", "queried", "by", "AWS", "X", "-", "Ray", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/middleware/xray/segment.go#L287-L289
166,826
goadesign/goa
middleware/xray/segment.go
AddInt64Annotation
func (s *Segment) AddInt64Annotation(key string, value int64) { s.addAnnotation(key, value) }
go
func (s *Segment) AddInt64Annotation(key string, value int64) { s.addAnnotation(key, value) }
[ "func", "(", "s", "*", "Segment", ")", "AddInt64Annotation", "(", "key", "string", ",", "value", "int64", ")", "{", "s", ".", "addAnnotation", "(", "key", ",", "value", ")", "\n", "}" ]
// AddInt64Annotation adds a key-value pair that can be queried by AWS X-Ray.
[ "AddInt64Annotation", "adds", "a", "key", "-", "value", "pair", "that", "can", "be", "queried", "by", "AWS", "X", "-", "Ray", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/middleware/xray/segment.go#L292-L294
166,827
goadesign/goa
middleware/xray/segment.go
AddBoolAnnotation
func (s *Segment) AddBoolAnnotation(key string, value bool) { s.addAnnotation(key, value) }
go
func (s *Segment) AddBoolAnnotation(key string, value bool) { s.addAnnotation(key, value) }
[ "func", "(", "s", "*", "Segment", ")", "AddBoolAnnotation", "(", "key", "string", ",", "value", "bool", ")", "{", "s", ".", "addAnnotation", "(", "key", ",", "value", ")", "\n", "}" ]
// AddBoolAnnotation adds a key-value pair that can be queried by AWS X-Ray.
[ "AddBoolAnnotation", "adds", "a", "key", "-", "value", "pair", "that", "can", "be", "queried", "by", "AWS", "X", "-", "Ray", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/middleware/xray/segment.go#L297-L299
166,828
goadesign/goa
middleware/xray/segment.go
addAnnotation
func (s *Segment) addAnnotation(key string, value interface{}) { s.Lock() defer s.Unlock() if s.Annotations == nil { s.Annotations = make(map[string]interface{}) } s.Annotations[key] = value }
go
func (s *Segment) addAnnotation(key string, value interface{}) { s.Lock() defer s.Unlock() if s.Annotations == nil { s.Annotations = make(map[string]interface{}) } s.Annotations[key] = value }
[ "func", "(", "s", "*", "Segment", ")", "addAnnotation", "(", "key", "string", ",", "value", "interface", "{", "}", ")", "{", "s", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "Unlock", "(", ")", "\n\n", "if", "s", ".", "Annotations", "==", "nil", "{", "s", ".", "Annotations", "=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "}", "\n", "s", ".", "Annotations", "[", "key", "]", "=", "value", "\n", "}" ]
// addAnnotation adds a key-value pair that can be queried by AWS X-Ray. // AWS X-Ray only supports annotations of type string, integer or boolean.
[ "addAnnotation", "adds", "a", "key", "-", "value", "pair", "that", "can", "be", "queried", "by", "AWS", "X", "-", "Ray", ".", "AWS", "X", "-", "Ray", "only", "supports", "annotations", "of", "type", "string", "integer", "or", "boolean", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/middleware/xray/segment.go#L303-L311
166,829
goadesign/goa
middleware/xray/segment.go
AddMetadata
func (s *Segment) AddMetadata(key string, value string) { s.addMetadata(key, value) }
go
func (s *Segment) AddMetadata(key string, value string) { s.addMetadata(key, value) }
[ "func", "(", "s", "*", "Segment", ")", "AddMetadata", "(", "key", "string", ",", "value", "string", ")", "{", "s", ".", "addMetadata", "(", "key", ",", "value", ")", "\n", "}" ]
// AddMetadata adds a key-value pair to the metadata.default attribute. // Metadata is not queryable, but is recorded.
[ "AddMetadata", "adds", "a", "key", "-", "value", "pair", "to", "the", "metadata", ".", "default", "attribute", ".", "Metadata", "is", "not", "queryable", "but", "is", "recorded", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/middleware/xray/segment.go#L315-L317
166,830
goadesign/goa
middleware/xray/segment.go
AddInt64Metadata
func (s *Segment) AddInt64Metadata(key string, value int64) { s.addMetadata(key, value) }
go
func (s *Segment) AddInt64Metadata(key string, value int64) { s.addMetadata(key, value) }
[ "func", "(", "s", "*", "Segment", ")", "AddInt64Metadata", "(", "key", "string", ",", "value", "int64", ")", "{", "s", ".", "addMetadata", "(", "key", ",", "value", ")", "\n", "}" ]
// AddInt64Metadata adds a key-value pair that can be queried by AWS X-Ray.
[ "AddInt64Metadata", "adds", "a", "key", "-", "value", "pair", "that", "can", "be", "queried", "by", "AWS", "X", "-", "Ray", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/middleware/xray/segment.go#L320-L322
166,831
goadesign/goa
middleware/xray/segment.go
AddBoolMetadata
func (s *Segment) AddBoolMetadata(key string, value bool) { s.addMetadata(key, value) }
go
func (s *Segment) AddBoolMetadata(key string, value bool) { s.addMetadata(key, value) }
[ "func", "(", "s", "*", "Segment", ")", "AddBoolMetadata", "(", "key", "string", ",", "value", "bool", ")", "{", "s", ".", "addMetadata", "(", "key", ",", "value", ")", "\n", "}" ]
// AddBoolMetadata adds a key-value pair that can be queried by AWS X-Ray.
[ "AddBoolMetadata", "adds", "a", "key", "-", "value", "pair", "that", "can", "be", "queried", "by", "AWS", "X", "-", "Ray", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/middleware/xray/segment.go#L325-L327
166,832
goadesign/goa
middleware/xray/segment.go
addMetadata
func (s *Segment) addMetadata(key string, value interface{}) { s.Lock() defer s.Unlock() if s.Metadata == nil { s.Metadata = make(map[string]map[string]interface{}) s.Metadata["default"] = make(map[string]interface{}) } s.Metadata["default"][key] = value }
go
func (s *Segment) addMetadata(key string, value interface{}) { s.Lock() defer s.Unlock() if s.Metadata == nil { s.Metadata = make(map[string]map[string]interface{}) s.Metadata["default"] = make(map[string]interface{}) } s.Metadata["default"][key] = value }
[ "func", "(", "s", "*", "Segment", ")", "addMetadata", "(", "key", "string", ",", "value", "interface", "{", "}", ")", "{", "s", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "Unlock", "(", ")", "\n\n", "if", "s", ".", "Metadata", "==", "nil", "{", "s", ".", "Metadata", "=", "make", "(", "map", "[", "string", "]", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "s", ".", "Metadata", "[", "\"", "\"", "]", "=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "}", "\n", "s", ".", "Metadata", "[", "\"", "\"", "]", "[", "key", "]", "=", "value", "\n", "}" ]
// addMetadata adds a key-value pair that can be queried by AWS X-Ray. // AWS X-Ray only supports annotations of type string, integer or boolean.
[ "addMetadata", "adds", "a", "key", "-", "value", "pair", "that", "can", "be", "queried", "by", "AWS", "X", "-", "Ray", ".", "AWS", "X", "-", "Ray", "only", "supports", "annotations", "of", "type", "string", "integer", "or", "boolean", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/middleware/xray/segment.go#L331-L340
166,833
goadesign/goa
middleware/xray/segment.go
Close
func (s *Segment) Close() { s.Lock() defer s.Unlock() s.EndTime = now() s.InProgress = false if s.Parent != nil { s.Parent.decrementCounter() } if s.counter <= 0 { s.flush() } }
go
func (s *Segment) Close() { s.Lock() defer s.Unlock() s.EndTime = now() s.InProgress = false if s.Parent != nil { s.Parent.decrementCounter() } if s.counter <= 0 { s.flush() } }
[ "func", "(", "s", "*", "Segment", ")", "Close", "(", ")", "{", "s", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "Unlock", "(", ")", "\n\n", "s", ".", "EndTime", "=", "now", "(", ")", "\n", "s", ".", "InProgress", "=", "false", "\n", "if", "s", ".", "Parent", "!=", "nil", "{", "s", ".", "Parent", ".", "decrementCounter", "(", ")", "\n", "}", "\n", "if", "s", ".", "counter", "<=", "0", "{", "s", ".", "flush", "(", ")", "\n", "}", "\n", "}" ]
// Close closes the segment by setting its EndTime.
[ "Close", "closes", "the", "segment", "by", "setting", "its", "EndTime", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/middleware/xray/segment.go#L343-L355
166,834
goadesign/goa
middleware/xray/segment.go
flush
func (s *Segment) flush() { b, _ := json.Marshal(s) // append so we make only one call to Write to be goroutine-safe s.conn.Write(append([]byte(udpHeader), b...)) }
go
func (s *Segment) flush() { b, _ := json.Marshal(s) // append so we make only one call to Write to be goroutine-safe s.conn.Write(append([]byte(udpHeader), b...)) }
[ "func", "(", "s", "*", "Segment", ")", "flush", "(", ")", "{", "b", ",", "_", ":=", "json", ".", "Marshal", "(", "s", ")", "\n", "// append so we make only one call to Write to be goroutine-safe", "s", ".", "conn", ".", "Write", "(", "append", "(", "[", "]", "byte", "(", "udpHeader", ")", ",", "b", "...", ")", ")", "\n", "}" ]
// flush sends the segment to the AWS X-Ray daemon.
[ "flush", "sends", "the", "segment", "to", "the", "AWS", "X", "-", "Ray", "daemon", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/middleware/xray/segment.go#L358-L362
166,835
goadesign/goa
middleware/xray/segment.go
recordStatusCode
func (s *Segment) recordStatusCode(statusCode int) { switch { case statusCode == http.StatusTooManyRequests: s.Throttle = true case statusCode >= 400 && statusCode < 500: s.Fault = true case statusCode >= 500: s.Error = true } }
go
func (s *Segment) recordStatusCode(statusCode int) { switch { case statusCode == http.StatusTooManyRequests: s.Throttle = true case statusCode >= 400 && statusCode < 500: s.Fault = true case statusCode >= 500: s.Error = true } }
[ "func", "(", "s", "*", "Segment", ")", "recordStatusCode", "(", "statusCode", "int", ")", "{", "switch", "{", "case", "statusCode", "==", "http", ".", "StatusTooManyRequests", ":", "s", ".", "Throttle", "=", "true", "\n", "case", "statusCode", ">=", "400", "&&", "statusCode", "<", "500", ":", "s", ".", "Fault", "=", "true", "\n", "case", "statusCode", ">=", "500", ":", "s", ".", "Error", "=", "true", "\n", "}", "\n", "}" ]
// recordStatusCode sets Throttle, Fault, Error // // It is expected that the mutex has already been locked when calling this method.
[ "recordStatusCode", "sets", "Throttle", "Fault", "Error", "It", "is", "expected", "that", "the", "mutex", "has", "already", "been", "locked", "when", "calling", "this", "method", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/middleware/xray/segment.go#L367-L376
166,836
goadesign/goa
middleware/xray/segment.go
decrementCounter
func (s *Segment) decrementCounter() { s.Lock() defer s.Unlock() s.counter-- if s.counter <= 0 && s.EndTime != 0 { // Segment is closed and last subsegment closed, flush it s.flush() } }
go
func (s *Segment) decrementCounter() { s.Lock() defer s.Unlock() s.counter-- if s.counter <= 0 && s.EndTime != 0 { // Segment is closed and last subsegment closed, flush it s.flush() } }
[ "func", "(", "s", "*", "Segment", ")", "decrementCounter", "(", ")", "{", "s", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "Unlock", "(", ")", "\n\n", "s", ".", "counter", "--", "\n", "if", "s", ".", "counter", "<=", "0", "&&", "s", ".", "EndTime", "!=", "0", "{", "// Segment is closed and last subsegment closed, flush it", "s", ".", "flush", "(", ")", "\n", "}", "\n", "}" ]
// decrementCounter decrements the segment counter and flushes it if it's 0.
[ "decrementCounter", "decrements", "the", "segment", "counter", "and", "flushes", "it", "if", "it", "s", "0", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/middleware/xray/segment.go#L379-L388
166,837
goadesign/goa
middleware/xray/segment.go
exceptionData
func exceptionData(e error) *Exception { var xerr *Exception if c, ok := e.(causer); ok { xerr = &Exception{Message: c.Cause().Error()} } else { xerr = &Exception{Message: e.Error()} } if s, ok := e.(stackTracer); ok { st := s.StackTrace() ln := len(st) if ln > maxStackDepth { ln = maxStackDepth } frames := make([]*StackEntry, ln) for i := 0; i < ln; i++ { f := st[i] line, _ := strconv.Atoi(fmt.Sprintf("%d", f)) frames[i] = &StackEntry{ Path: fmt.Sprintf("%s", f), Line: line, Label: fmt.Sprintf("%n", f), } } xerr.Stack = frames } return xerr }
go
func exceptionData(e error) *Exception { var xerr *Exception if c, ok := e.(causer); ok { xerr = &Exception{Message: c.Cause().Error()} } else { xerr = &Exception{Message: e.Error()} } if s, ok := e.(stackTracer); ok { st := s.StackTrace() ln := len(st) if ln > maxStackDepth { ln = maxStackDepth } frames := make([]*StackEntry, ln) for i := 0; i < ln; i++ { f := st[i] line, _ := strconv.Atoi(fmt.Sprintf("%d", f)) frames[i] = &StackEntry{ Path: fmt.Sprintf("%s", f), Line: line, Label: fmt.Sprintf("%n", f), } } xerr.Stack = frames } return xerr }
[ "func", "exceptionData", "(", "e", "error", ")", "*", "Exception", "{", "var", "xerr", "*", "Exception", "\n", "if", "c", ",", "ok", ":=", "e", ".", "(", "causer", ")", ";", "ok", "{", "xerr", "=", "&", "Exception", "{", "Message", ":", "c", ".", "Cause", "(", ")", ".", "Error", "(", ")", "}", "\n", "}", "else", "{", "xerr", "=", "&", "Exception", "{", "Message", ":", "e", ".", "Error", "(", ")", "}", "\n", "}", "\n", "if", "s", ",", "ok", ":=", "e", ".", "(", "stackTracer", ")", ";", "ok", "{", "st", ":=", "s", ".", "StackTrace", "(", ")", "\n", "ln", ":=", "len", "(", "st", ")", "\n", "if", "ln", ">", "maxStackDepth", "{", "ln", "=", "maxStackDepth", "\n", "}", "\n", "frames", ":=", "make", "(", "[", "]", "*", "StackEntry", ",", "ln", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "ln", ";", "i", "++", "{", "f", ":=", "st", "[", "i", "]", "\n", "line", ",", "_", ":=", "strconv", ".", "Atoi", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "f", ")", ")", "\n", "frames", "[", "i", "]", "=", "&", "StackEntry", "{", "Path", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "f", ")", ",", "Line", ":", "line", ",", "Label", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "f", ")", ",", "}", "\n", "}", "\n", "xerr", ".", "Stack", "=", "frames", "\n", "}", "\n\n", "return", "xerr", "\n", "}" ]
// exceptionData creates an Exception from an error.
[ "exceptionData", "creates", "an", "Exception", "from", "an", "error", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/middleware/xray/segment.go#L391-L418
166,838
goadesign/goa
middleware/xray/segment.go
requestData
func requestData(req *http.Request) *Request { var ( scheme = "http" host = req.Host ) if len(req.URL.Scheme) > 0 { scheme = req.URL.Scheme } if len(req.URL.Host) > 0 { host = req.URL.Host } return &Request{ Method: req.Method, URL: fmt.Sprintf("%s://%s%s", scheme, host, req.URL.Path), ClientIP: getIP(req), UserAgent: req.UserAgent(), ContentLength: req.ContentLength, } }
go
func requestData(req *http.Request) *Request { var ( scheme = "http" host = req.Host ) if len(req.URL.Scheme) > 0 { scheme = req.URL.Scheme } if len(req.URL.Host) > 0 { host = req.URL.Host } return &Request{ Method: req.Method, URL: fmt.Sprintf("%s://%s%s", scheme, host, req.URL.Path), ClientIP: getIP(req), UserAgent: req.UserAgent(), ContentLength: req.ContentLength, } }
[ "func", "requestData", "(", "req", "*", "http", ".", "Request", ")", "*", "Request", "{", "var", "(", "scheme", "=", "\"", "\"", "\n", "host", "=", "req", ".", "Host", "\n", ")", "\n", "if", "len", "(", "req", ".", "URL", ".", "Scheme", ")", ">", "0", "{", "scheme", "=", "req", ".", "URL", ".", "Scheme", "\n", "}", "\n", "if", "len", "(", "req", ".", "URL", ".", "Host", ")", ">", "0", "{", "host", "=", "req", ".", "URL", ".", "Host", "\n", "}", "\n\n", "return", "&", "Request", "{", "Method", ":", "req", ".", "Method", ",", "URL", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "scheme", ",", "host", ",", "req", ".", "URL", ".", "Path", ")", ",", "ClientIP", ":", "getIP", "(", "req", ")", ",", "UserAgent", ":", "req", ".", "UserAgent", "(", ")", ",", "ContentLength", ":", "req", ".", "ContentLength", ",", "}", "\n", "}" ]
// requestData creates a Request from a http.Request.
[ "requestData", "creates", "a", "Request", "from", "a", "http", ".", "Request", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/middleware/xray/segment.go#L421-L440
166,839
goadesign/goa
middleware/xray/segment.go
responseData
func responseData(resp *http.Response) *Response { return &Response{ Status: resp.StatusCode, ContentLength: resp.ContentLength, } }
go
func responseData(resp *http.Response) *Response { return &Response{ Status: resp.StatusCode, ContentLength: resp.ContentLength, } }
[ "func", "responseData", "(", "resp", "*", "http", ".", "Response", ")", "*", "Response", "{", "return", "&", "Response", "{", "Status", ":", "resp", ".", "StatusCode", ",", "ContentLength", ":", "resp", ".", "ContentLength", ",", "}", "\n", "}" ]
// responseData creates a Response from a http.Response.
[ "responseData", "creates", "a", "Response", "from", "a", "http", ".", "Response", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/middleware/xray/segment.go#L443-L448
166,840
goadesign/goa
goagen/gen_client/cli_generator.go
defaultRouteParams
func defaultRouteParams(a *design.ActionDefinition) *design.AttributeDefinition { r := a.Routes[0] params := r.Params() o := make(design.Object, len(params)) nz := make(map[string]bool, len(params)) pparams := a.PathParams() for _, p := range params { o[p] = pparams.Type.ToObject()[p] nz[p] = true } return &design.AttributeDefinition{Type: o, NonZeroAttributes: nz} }
go
func defaultRouteParams(a *design.ActionDefinition) *design.AttributeDefinition { r := a.Routes[0] params := r.Params() o := make(design.Object, len(params)) nz := make(map[string]bool, len(params)) pparams := a.PathParams() for _, p := range params { o[p] = pparams.Type.ToObject()[p] nz[p] = true } return &design.AttributeDefinition{Type: o, NonZeroAttributes: nz} }
[ "func", "defaultRouteParams", "(", "a", "*", "design", ".", "ActionDefinition", ")", "*", "design", ".", "AttributeDefinition", "{", "r", ":=", "a", ".", "Routes", "[", "0", "]", "\n", "params", ":=", "r", ".", "Params", "(", ")", "\n", "o", ":=", "make", "(", "design", ".", "Object", ",", "len", "(", "params", ")", ")", "\n", "nz", ":=", "make", "(", "map", "[", "string", "]", "bool", ",", "len", "(", "params", ")", ")", "\n", "pparams", ":=", "a", ".", "PathParams", "(", ")", "\n", "for", "_", ",", "p", ":=", "range", "params", "{", "o", "[", "p", "]", "=", "pparams", ".", "Type", ".", "ToObject", "(", ")", "[", "p", "]", "\n", "nz", "[", "p", "]", "=", "true", "\n", "}", "\n", "return", "&", "design", ".", "AttributeDefinition", "{", "Type", ":", "o", ",", "NonZeroAttributes", ":", "nz", "}", "\n", "}" ]
// defaultRouteParams returns the parameters needed to build the first route of the given action.
[ "defaultRouteParams", "returns", "the", "parameters", "needed", "to", "build", "the", "first", "route", "of", "the", "given", "action", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/goagen/gen_client/cli_generator.go#L262-L273
166,841
goadesign/goa
goagen/gen_client/cli_generator.go
defaultRouteTemplate
func defaultRouteTemplate(a *design.ActionDefinition) string { return design.WildcardRegex.ReplaceAllLiteralString(a.Routes[0].FullPath(), "/%v") }
go
func defaultRouteTemplate(a *design.ActionDefinition) string { return design.WildcardRegex.ReplaceAllLiteralString(a.Routes[0].FullPath(), "/%v") }
[ "func", "defaultRouteTemplate", "(", "a", "*", "design", ".", "ActionDefinition", ")", "string", "{", "return", "design", ".", "WildcardRegex", ".", "ReplaceAllLiteralString", "(", "a", ".", "Routes", "[", "0", "]", ".", "FullPath", "(", ")", ",", "\"", "\"", ")", "\n", "}" ]
// produces a fmt template to render the first route of action.
[ "produces", "a", "fmt", "template", "to", "render", "the", "first", "route", "of", "action", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/goagen/gen_client/cli_generator.go#L276-L278
166,842
goadesign/goa
goagen/gen_client/cli_generator.go
joinRouteParams
func joinRouteParams(action *design.ActionDefinition, att *design.AttributeDefinition) string { var ( params = action.Routes[0].Params() elems = make([]string, len(params)) ) for i, p := range params { patt, ok := att.Type.ToObject()[p] if !ok { continue } pf := "cmd.%s" if patt.Type.Kind() == design.StringKind { pf = "url.QueryEscape(cmd.%s)" } field := fmt.Sprintf(pf, codegen.Goify(p, true)) elems[i] = field } return strings.Join(elems, ", ") }
go
func joinRouteParams(action *design.ActionDefinition, att *design.AttributeDefinition) string { var ( params = action.Routes[0].Params() elems = make([]string, len(params)) ) for i, p := range params { patt, ok := att.Type.ToObject()[p] if !ok { continue } pf := "cmd.%s" if patt.Type.Kind() == design.StringKind { pf = "url.QueryEscape(cmd.%s)" } field := fmt.Sprintf(pf, codegen.Goify(p, true)) elems[i] = field } return strings.Join(elems, ", ") }
[ "func", "joinRouteParams", "(", "action", "*", "design", ".", "ActionDefinition", ",", "att", "*", "design", ".", "AttributeDefinition", ")", "string", "{", "var", "(", "params", "=", "action", ".", "Routes", "[", "0", "]", ".", "Params", "(", ")", "\n", "elems", "=", "make", "(", "[", "]", "string", ",", "len", "(", "params", ")", ")", "\n", ")", "\n", "for", "i", ",", "p", ":=", "range", "params", "{", "patt", ",", "ok", ":=", "att", ".", "Type", ".", "ToObject", "(", ")", "[", "p", "]", "\n", "if", "!", "ok", "{", "continue", "\n", "}", "\n", "pf", ":=", "\"", "\"", "\n", "if", "patt", ".", "Type", ".", "Kind", "(", ")", "==", "design", ".", "StringKind", "{", "pf", "=", "\"", "\"", "\n", "}", "\n", "field", ":=", "fmt", ".", "Sprintf", "(", "pf", ",", "codegen", ".", "Goify", "(", "p", ",", "true", ")", ")", "\n", "elems", "[", "i", "]", "=", "field", "\n", "}", "\n", "return", "strings", ".", "Join", "(", "elems", ",", "\"", "\"", ")", "\n", "}" ]
// return a ',' joined list of Params as a reference to cmd.XFieldName // ordered by the required first rules.
[ "return", "a", "joined", "list", "of", "Params", "as", "a", "reference", "to", "cmd", ".", "XFieldName", "ordered", "by", "the", "required", "first", "rules", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/goagen/gen_client/cli_generator.go#L282-L300
166,843
goadesign/goa
goagen/gen_client/cli_generator.go
routes
func routes(action *design.ActionDefinition) string { var buf bytes.Buffer routes := action.Routes buf.WriteRune('[') if len(routes) > 1 { buf.WriteRune('(') } paths := make([]string, len(routes)) for i, r := range routes { path := r.FullPath() matches := design.WildcardRegex.FindAllStringSubmatch(path, -1) for _, match := range matches { paramName := match[1] path = strings.Replace(path, ":"+paramName, strings.ToUpper(paramName), 1) } paths[i] = fmt.Sprintf("%q", path) } buf.WriteString(strings.Join(paths, "|")) if len(routes) > 1 { buf.WriteRune(')') } buf.WriteRune(']') return buf.String() }
go
func routes(action *design.ActionDefinition) string { var buf bytes.Buffer routes := action.Routes buf.WriteRune('[') if len(routes) > 1 { buf.WriteRune('(') } paths := make([]string, len(routes)) for i, r := range routes { path := r.FullPath() matches := design.WildcardRegex.FindAllStringSubmatch(path, -1) for _, match := range matches { paramName := match[1] path = strings.Replace(path, ":"+paramName, strings.ToUpper(paramName), 1) } paths[i] = fmt.Sprintf("%q", path) } buf.WriteString(strings.Join(paths, "|")) if len(routes) > 1 { buf.WriteRune(')') } buf.WriteRune(']') return buf.String() }
[ "func", "routes", "(", "action", "*", "design", ".", "ActionDefinition", ")", "string", "{", "var", "buf", "bytes", ".", "Buffer", "\n", "routes", ":=", "action", ".", "Routes", "\n", "buf", ".", "WriteRune", "(", "'['", ")", "\n", "if", "len", "(", "routes", ")", ">", "1", "{", "buf", ".", "WriteRune", "(", "'('", ")", "\n", "}", "\n", "paths", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "routes", ")", ")", "\n", "for", "i", ",", "r", ":=", "range", "routes", "{", "path", ":=", "r", ".", "FullPath", "(", ")", "\n", "matches", ":=", "design", ".", "WildcardRegex", ".", "FindAllStringSubmatch", "(", "path", ",", "-", "1", ")", "\n", "for", "_", ",", "match", ":=", "range", "matches", "{", "paramName", ":=", "match", "[", "1", "]", "\n", "path", "=", "strings", ".", "Replace", "(", "path", ",", "\"", "\"", "+", "paramName", ",", "strings", ".", "ToUpper", "(", "paramName", ")", ",", "1", ")", "\n", "}", "\n", "paths", "[", "i", "]", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "path", ")", "\n", "}", "\n", "buf", ".", "WriteString", "(", "strings", ".", "Join", "(", "paths", ",", "\"", "\"", ")", ")", "\n", "if", "len", "(", "routes", ")", ">", "1", "{", "buf", ".", "WriteRune", "(", "')'", ")", "\n", "}", "\n", "buf", ".", "WriteRune", "(", "']'", ")", "\n", "return", "buf", ".", "String", "(", ")", "\n", "}" ]
// routes create the action command "Use" suffix.
[ "routes", "create", "the", "action", "command", "Use", "suffix", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/goagen/gen_client/cli_generator.go#L498-L521
166,844
goadesign/goa
design/api.go
CanonicalIdentifier
func CanonicalIdentifier(identifier string) string { base, params, err := mime.ParseMediaType(identifier) if err != nil { return identifier } id := base if i := strings.Index(id, "+"); i != -1 { id = id[:i] } return mime.FormatMediaType(id, params) }
go
func CanonicalIdentifier(identifier string) string { base, params, err := mime.ParseMediaType(identifier) if err != nil { return identifier } id := base if i := strings.Index(id, "+"); i != -1 { id = id[:i] } return mime.FormatMediaType(id, params) }
[ "func", "CanonicalIdentifier", "(", "identifier", "string", ")", "string", "{", "base", ",", "params", ",", "err", ":=", "mime", ".", "ParseMediaType", "(", "identifier", ")", "\n", "if", "err", "!=", "nil", "{", "return", "identifier", "\n", "}", "\n", "id", ":=", "base", "\n", "if", "i", ":=", "strings", ".", "Index", "(", "id", ",", "\"", "\"", ")", ";", "i", "!=", "-", "1", "{", "id", "=", "id", "[", ":", "i", "]", "\n", "}", "\n", "return", "mime", ".", "FormatMediaType", "(", "id", ",", "params", ")", "\n", "}" ]
// CanonicalIdentifier returns the media type identifier sans suffix // which is what the DSL uses to store and lookup media types.
[ "CanonicalIdentifier", "returns", "the", "media", "type", "identifier", "sans", "suffix", "which", "is", "what", "the", "DSL", "uses", "to", "store", "and", "lookup", "media", "types", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/api.go#L207-L217
166,845
goadesign/goa
design/api.go
ExtractWildcards
func ExtractWildcards(path string) []string { matches := WildcardRegex.FindAllStringSubmatch(path, -1) wcs := make([]string, len(matches)) for i, m := range matches { wcs[i] = m[1] } return wcs }
go
func ExtractWildcards(path string) []string { matches := WildcardRegex.FindAllStringSubmatch(path, -1) wcs := make([]string, len(matches)) for i, m := range matches { wcs[i] = m[1] } return wcs }
[ "func", "ExtractWildcards", "(", "path", "string", ")", "[", "]", "string", "{", "matches", ":=", "WildcardRegex", ".", "FindAllStringSubmatch", "(", "path", ",", "-", "1", ")", "\n", "wcs", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "matches", ")", ")", "\n", "for", "i", ",", "m", ":=", "range", "matches", "{", "wcs", "[", "i", "]", "=", "m", "[", "1", "]", "\n", "}", "\n", "return", "wcs", "\n", "}" ]
// ExtractWildcards returns the names of the wildcards that appear in path.
[ "ExtractWildcards", "returns", "the", "names", "of", "the", "wildcards", "that", "appear", "in", "path", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/api.go#L226-L233
166,846
goadesign/goa
design/api.go
IterateSets
func (r MediaTypeRoot) IterateSets(iterator dslengine.SetIterator) { canonicalIDs := make([]string, len(r)) i := 0 for _, mt := range r { canonicalID := CanonicalIdentifier(mt.Identifier) Design.MediaTypes[canonicalID] = mt canonicalIDs[i] = canonicalID i++ } sort.Strings(canonicalIDs) set := make([]dslengine.Definition, len(canonicalIDs)) for i, cid := range canonicalIDs { set[i] = Design.MediaTypes[cid] } iterator(set) }
go
func (r MediaTypeRoot) IterateSets(iterator dslengine.SetIterator) { canonicalIDs := make([]string, len(r)) i := 0 for _, mt := range r { canonicalID := CanonicalIdentifier(mt.Identifier) Design.MediaTypes[canonicalID] = mt canonicalIDs[i] = canonicalID i++ } sort.Strings(canonicalIDs) set := make([]dslengine.Definition, len(canonicalIDs)) for i, cid := range canonicalIDs { set[i] = Design.MediaTypes[cid] } iterator(set) }
[ "func", "(", "r", "MediaTypeRoot", ")", "IterateSets", "(", "iterator", "dslengine", ".", "SetIterator", ")", "{", "canonicalIDs", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "r", ")", ")", "\n", "i", ":=", "0", "\n", "for", "_", ",", "mt", ":=", "range", "r", "{", "canonicalID", ":=", "CanonicalIdentifier", "(", "mt", ".", "Identifier", ")", "\n", "Design", ".", "MediaTypes", "[", "canonicalID", "]", "=", "mt", "\n", "canonicalIDs", "[", "i", "]", "=", "canonicalID", "\n", "i", "++", "\n", "}", "\n", "sort", ".", "Strings", "(", "canonicalIDs", ")", "\n", "set", ":=", "make", "(", "[", "]", "dslengine", ".", "Definition", ",", "len", "(", "canonicalIDs", ")", ")", "\n", "for", "i", ",", "cid", ":=", "range", "canonicalIDs", "{", "set", "[", "i", "]", "=", "Design", ".", "MediaTypes", "[", "cid", "]", "\n", "}", "\n", "iterator", "(", "set", ")", "\n", "}" ]
// IterateSets iterates over the one generated media type definition set.
[ "IterateSets", "iterates", "over", "the", "one", "generated", "media", "type", "definition", "set", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/api.go#L246-L261
166,847
goadesign/goa
dslengine/validation.go
Merge
func (verr *ValidationErrors) Merge(err *ValidationErrors) { if err == nil { return } verr.Errors = append(verr.Errors, err.Errors...) verr.Definitions = append(verr.Definitions, err.Definitions...) }
go
func (verr *ValidationErrors) Merge(err *ValidationErrors) { if err == nil { return } verr.Errors = append(verr.Errors, err.Errors...) verr.Definitions = append(verr.Definitions, err.Definitions...) }
[ "func", "(", "verr", "*", "ValidationErrors", ")", "Merge", "(", "err", "*", "ValidationErrors", ")", "{", "if", "err", "==", "nil", "{", "return", "\n", "}", "\n", "verr", ".", "Errors", "=", "append", "(", "verr", ".", "Errors", ",", "err", ".", "Errors", "...", ")", "\n", "verr", ".", "Definitions", "=", "append", "(", "verr", ".", "Definitions", ",", "err", ".", "Definitions", "...", ")", "\n", "}" ]
// Merge merges validation errors into the target.
[ "Merge", "merges", "validation", "errors", "into", "the", "target", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/dslengine/validation.go#L24-L30
166,848
goadesign/goa
dslengine/validation.go
Add
func (verr *ValidationErrors) Add(def Definition, format string, vals ...interface{}) { verr.AddError(def, fmt.Errorf(format, vals...)) }
go
func (verr *ValidationErrors) Add(def Definition, format string, vals ...interface{}) { verr.AddError(def, fmt.Errorf(format, vals...)) }
[ "func", "(", "verr", "*", "ValidationErrors", ")", "Add", "(", "def", "Definition", ",", "format", "string", ",", "vals", "...", "interface", "{", "}", ")", "{", "verr", ".", "AddError", "(", "def", ",", "fmt", ".", "Errorf", "(", "format", ",", "vals", "...", ")", ")", "\n", "}" ]
// Add adds a validation error to the target.
[ "Add", "adds", "a", "validation", "error", "to", "the", "target", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/dslengine/validation.go#L33-L35
166,849
goadesign/goa
dslengine/validation.go
AddError
func (verr *ValidationErrors) AddError(def Definition, err error) { if v, ok := err.(*ValidationErrors); ok { verr.Errors = append(verr.Errors, v.Errors...) verr.Definitions = append(verr.Definitions, v.Definitions...) return } verr.Errors = append(verr.Errors, err) verr.Definitions = append(verr.Definitions, def) }
go
func (verr *ValidationErrors) AddError(def Definition, err error) { if v, ok := err.(*ValidationErrors); ok { verr.Errors = append(verr.Errors, v.Errors...) verr.Definitions = append(verr.Definitions, v.Definitions...) return } verr.Errors = append(verr.Errors, err) verr.Definitions = append(verr.Definitions, def) }
[ "func", "(", "verr", "*", "ValidationErrors", ")", "AddError", "(", "def", "Definition", ",", "err", "error", ")", "{", "if", "v", ",", "ok", ":=", "err", ".", "(", "*", "ValidationErrors", ")", ";", "ok", "{", "verr", ".", "Errors", "=", "append", "(", "verr", ".", "Errors", ",", "v", ".", "Errors", "...", ")", "\n", "verr", ".", "Definitions", "=", "append", "(", "verr", ".", "Definitions", ",", "v", ".", "Definitions", "...", ")", "\n", "return", "\n", "}", "\n", "verr", ".", "Errors", "=", "append", "(", "verr", ".", "Errors", ",", "err", ")", "\n", "verr", ".", "Definitions", "=", "append", "(", "verr", ".", "Definitions", ",", "def", ")", "\n", "}" ]
// AddError adds a validation error to the target. // AddError "flattens" validation errors so that the recorded errors are never ValidationErrors // themselves.
[ "AddError", "adds", "a", "validation", "error", "to", "the", "target", ".", "AddError", "flattens", "validation", "errors", "so", "that", "the", "recorded", "errors", "are", "never", "ValidationErrors", "themselves", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/dslengine/validation.go#L40-L48
166,850
goadesign/goa
middleware/xray/wrap_doer.go
Do
func (r *wrapDoer) Do(ctx context.Context, req *http.Request) (*http.Response, error) { s := ContextSegment(ctx) if s == nil { // this request isn't traced return r.wrapped.Do(ctx, req) } sub := s.NewSubsegment(req.URL.Host) defer sub.Close() // update the context with the latest segment ctx = middleware.WithTrace(ctx, sub.TraceID, sub.ID, sub.ParentID) ctx = WithSegment(ctx, sub) sub.RecordRequest(req, "remote") resp, err := r.wrapped.Do(ctx, req) if err != nil { sub.RecordError(err) } else { sub.RecordResponse(resp) } return resp, err }
go
func (r *wrapDoer) Do(ctx context.Context, req *http.Request) (*http.Response, error) { s := ContextSegment(ctx) if s == nil { // this request isn't traced return r.wrapped.Do(ctx, req) } sub := s.NewSubsegment(req.URL.Host) defer sub.Close() // update the context with the latest segment ctx = middleware.WithTrace(ctx, sub.TraceID, sub.ID, sub.ParentID) ctx = WithSegment(ctx, sub) sub.RecordRequest(req, "remote") resp, err := r.wrapped.Do(ctx, req) if err != nil { sub.RecordError(err) } else { sub.RecordResponse(resp) } return resp, err }
[ "func", "(", "r", "*", "wrapDoer", ")", "Do", "(", "ctx", "context", ".", "Context", ",", "req", "*", "http", ".", "Request", ")", "(", "*", "http", ".", "Response", ",", "error", ")", "{", "s", ":=", "ContextSegment", "(", "ctx", ")", "\n", "if", "s", "==", "nil", "{", "// this request isn't traced", "return", "r", ".", "wrapped", ".", "Do", "(", "ctx", ",", "req", ")", "\n", "}", "\n\n", "sub", ":=", "s", ".", "NewSubsegment", "(", "req", ".", "URL", ".", "Host", ")", "\n", "defer", "sub", ".", "Close", "(", ")", "\n\n", "// update the context with the latest segment", "ctx", "=", "middleware", ".", "WithTrace", "(", "ctx", ",", "sub", ".", "TraceID", ",", "sub", ".", "ID", ",", "sub", ".", "ParentID", ")", "\n", "ctx", "=", "WithSegment", "(", "ctx", ",", "sub", ")", "\n\n", "sub", ".", "RecordRequest", "(", "req", ",", "\"", "\"", ")", "\n\n", "resp", ",", "err", ":=", "r", ".", "wrapped", ".", "Do", "(", "ctx", ",", "req", ")", "\n\n", "if", "err", "!=", "nil", "{", "sub", ".", "RecordError", "(", "err", ")", "\n", "}", "else", "{", "sub", ".", "RecordResponse", "(", "resp", ")", "\n", "}", "\n\n", "return", "resp", ",", "err", "\n", "}" ]
// Do calls through to the wrapped Doer, creating subsegments as appropriate.
[ "Do", "calls", "through", "to", "the", "wrapped", "Doer", "creating", "subsegments", "as", "appropriate", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/middleware/xray/wrap_doer.go#L24-L49
166,851
goadesign/goa
design/apidsl/resource.go
CanonicalActionName
func CanonicalActionName(a string) { if r, ok := resourceDefinition(); ok { r.CanonicalActionName = a } }
go
func CanonicalActionName(a string) { if r, ok := resourceDefinition(); ok { r.CanonicalActionName = a } }
[ "func", "CanonicalActionName", "(", "a", "string", ")", "{", "if", "r", ",", "ok", ":=", "resourceDefinition", "(", ")", ";", "ok", "{", "r", ".", "CanonicalActionName", "=", "a", "\n", "}", "\n", "}" ]
// CanonicalActionName sets the name of the action used to compute the resource collection and // // resource collection items hrefs. See Resource.
[ "CanonicalActionName", "sets", "the", "name", "of", "the", "action", "used", "to", "compute", "the", "resource", "collection", "and", "resource", "collection", "items", "hrefs", ".", "See", "Resource", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/apidsl/resource.go#L125-L129
166,852
goadesign/goa
goagen/gen_client/generator.go
multiComment
func multiComment(text string) string { lines := strings.Split(text, "\n") nl := make([]string, len(lines)) for i, l := range lines { nl[i] = "// " + strings.TrimSpace(l) } return strings.Join(nl, "\n") }
go
func multiComment(text string) string { lines := strings.Split(text, "\n") nl := make([]string, len(lines)) for i, l := range lines { nl[i] = "// " + strings.TrimSpace(l) } return strings.Join(nl, "\n") }
[ "func", "multiComment", "(", "text", "string", ")", "string", "{", "lines", ":=", "strings", ".", "Split", "(", "text", ",", "\"", "\\n", "\"", ")", "\n", "nl", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "lines", ")", ")", "\n", "for", "i", ",", "l", ":=", "range", "lines", "{", "nl", "[", "i", "]", "=", "\"", "\"", "+", "strings", ".", "TrimSpace", "(", "l", ")", "\n", "}", "\n", "return", "strings", ".", "Join", "(", "nl", ",", "\"", "\\n", "\"", ")", "\n", "}" ]
// multiComment produces a Go comment containing the given string taking into account newlines.
[ "multiComment", "produces", "a", "Go", "comment", "containing", "the", "given", "string", "taking", "into", "account", "newlines", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/goagen/gen_client/generator.go#L712-L719
166,853
goadesign/goa
goagen/gen_client/generator.go
goTypeRefExt
func goTypeRefExt(t design.DataType, tabs int, pkg string) string { ref := codegen.GoTypeRef(t, nil, tabs, false) if strings.HasPrefix(ref, "*") { return fmt.Sprintf("%s.%s", pkg, ref[1:]) } return fmt.Sprintf("%s.%s", pkg, ref) }
go
func goTypeRefExt(t design.DataType, tabs int, pkg string) string { ref := codegen.GoTypeRef(t, nil, tabs, false) if strings.HasPrefix(ref, "*") { return fmt.Sprintf("%s.%s", pkg, ref[1:]) } return fmt.Sprintf("%s.%s", pkg, ref) }
[ "func", "goTypeRefExt", "(", "t", "design", ".", "DataType", ",", "tabs", "int", ",", "pkg", "string", ")", "string", "{", "ref", ":=", "codegen", ".", "GoTypeRef", "(", "t", ",", "nil", ",", "tabs", ",", "false", ")", "\n", "if", "strings", ".", "HasPrefix", "(", "ref", ",", "\"", "\"", ")", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "pkg", ",", "ref", "[", "1", ":", "]", ")", "\n", "}", "\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "pkg", ",", "ref", ")", "\n", "}" ]
// gotTypeRefExt computes the type reference for a type in a different package.
[ "gotTypeRefExt", "computes", "the", "type", "reference", "for", "a", "type", "in", "a", "different", "package", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/goagen/gen_client/generator.go#L722-L728
166,854
goadesign/goa
goagen/gen_client/generator.go
decodeGoTypeRef
func decodeGoTypeRef(t design.DataType, required []string, tabs int, private bool) string { mt, ok := t.(*design.MediaTypeDefinition) if ok && mt.IsError() { return "*goa.ErrorResponse" } return codegen.GoTypeRef(t, required, tabs, private) }
go
func decodeGoTypeRef(t design.DataType, required []string, tabs int, private bool) string { mt, ok := t.(*design.MediaTypeDefinition) if ok && mt.IsError() { return "*goa.ErrorResponse" } return codegen.GoTypeRef(t, required, tabs, private) }
[ "func", "decodeGoTypeRef", "(", "t", "design", ".", "DataType", ",", "required", "[", "]", "string", ",", "tabs", "int", ",", "private", "bool", ")", "string", "{", "mt", ",", "ok", ":=", "t", ".", "(", "*", "design", ".", "MediaTypeDefinition", ")", "\n", "if", "ok", "&&", "mt", ".", "IsError", "(", ")", "{", "return", "\"", "\"", "\n", "}", "\n", "return", "codegen", ".", "GoTypeRef", "(", "t", ",", "required", ",", "tabs", ",", "private", ")", "\n", "}" ]
// decodeGoTypeRef handles the case where the type being decoded is a error response media type.
[ "decodeGoTypeRef", "handles", "the", "case", "where", "the", "type", "being", "decoded", "is", "a", "error", "response", "media", "type", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/goagen/gen_client/generator.go#L731-L737
166,855
goadesign/goa
goagen/gen_client/generator.go
decodeGoTypeName
func decodeGoTypeName(t design.DataType, required []string, tabs int, private bool) string { mt, ok := t.(*design.MediaTypeDefinition) if ok && mt.IsError() { return "goa.ErrorResponse" } return codegen.GoTypeName(t, required, tabs, private) }
go
func decodeGoTypeName(t design.DataType, required []string, tabs int, private bool) string { mt, ok := t.(*design.MediaTypeDefinition) if ok && mt.IsError() { return "goa.ErrorResponse" } return codegen.GoTypeName(t, required, tabs, private) }
[ "func", "decodeGoTypeName", "(", "t", "design", ".", "DataType", ",", "required", "[", "]", "string", ",", "tabs", "int", ",", "private", "bool", ")", "string", "{", "mt", ",", "ok", ":=", "t", ".", "(", "*", "design", ".", "MediaTypeDefinition", ")", "\n", "if", "ok", "&&", "mt", ".", "IsError", "(", ")", "{", "return", "\"", "\"", "\n", "}", "\n", "return", "codegen", ".", "GoTypeName", "(", "t", ",", "required", ",", "tabs", ",", "private", ")", "\n", "}" ]
// decodeGoTypeName handles the case where the type being decoded is a error response media type.
[ "decodeGoTypeName", "handles", "the", "case", "where", "the", "type", "being", "decoded", "is", "a", "error", "response", "media", "type", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/goagen/gen_client/generator.go#L740-L746
166,856
goadesign/goa
goagen/gen_client/generator.go
cmdFieldType
func cmdFieldType(t design.DataType, point bool) string { var pointer, suffix string if point && !t.IsArray() { pointer = "*" } suffix = codegen.GoNativeType(t) return pointer + suffix }
go
func cmdFieldType(t design.DataType, point bool) string { var pointer, suffix string if point && !t.IsArray() { pointer = "*" } suffix = codegen.GoNativeType(t) return pointer + suffix }
[ "func", "cmdFieldType", "(", "t", "design", ".", "DataType", ",", "point", "bool", ")", "string", "{", "var", "pointer", ",", "suffix", "string", "\n", "if", "point", "&&", "!", "t", ".", "IsArray", "(", ")", "{", "pointer", "=", "\"", "\"", "\n", "}", "\n", "suffix", "=", "codegen", ".", "GoNativeType", "(", "t", ")", "\n", "return", "pointer", "+", "suffix", "\n", "}" ]
// cmdFieldType computes the Go type name used to store command flags of the given design type.
[ "cmdFieldType", "computes", "the", "Go", "type", "name", "used", "to", "store", "command", "flags", "of", "the", "given", "design", "type", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/goagen/gen_client/generator.go#L749-L756
166,857
goadesign/goa
goagen/gen_client/generator.go
cmdFieldTypeString
func cmdFieldTypeString(t design.DataType, point bool) string { var pointer, suffix string if point && !t.IsArray() { pointer = "*" } if t.Kind() == design.UUIDKind || t.Kind() == design.DateTimeKind || t.Kind() == design.AnyKind || t.Kind() == design.NumberKind || t.Kind() == design.BooleanKind { suffix = "string" } else if isArrayOfType(t, design.UUIDKind, design.DateTimeKind, design.AnyKind, design.NumberKind, design.BooleanKind) { suffix = "[]string" } else { suffix = codegen.GoNativeType(t) } return pointer + suffix }
go
func cmdFieldTypeString(t design.DataType, point bool) string { var pointer, suffix string if point && !t.IsArray() { pointer = "*" } if t.Kind() == design.UUIDKind || t.Kind() == design.DateTimeKind || t.Kind() == design.AnyKind || t.Kind() == design.NumberKind || t.Kind() == design.BooleanKind { suffix = "string" } else if isArrayOfType(t, design.UUIDKind, design.DateTimeKind, design.AnyKind, design.NumberKind, design.BooleanKind) { suffix = "[]string" } else { suffix = codegen.GoNativeType(t) } return pointer + suffix }
[ "func", "cmdFieldTypeString", "(", "t", "design", ".", "DataType", ",", "point", "bool", ")", "string", "{", "var", "pointer", ",", "suffix", "string", "\n", "if", "point", "&&", "!", "t", ".", "IsArray", "(", ")", "{", "pointer", "=", "\"", "\"", "\n", "}", "\n", "if", "t", ".", "Kind", "(", ")", "==", "design", ".", "UUIDKind", "||", "t", ".", "Kind", "(", ")", "==", "design", ".", "DateTimeKind", "||", "t", ".", "Kind", "(", ")", "==", "design", ".", "AnyKind", "||", "t", ".", "Kind", "(", ")", "==", "design", ".", "NumberKind", "||", "t", ".", "Kind", "(", ")", "==", "design", ".", "BooleanKind", "{", "suffix", "=", "\"", "\"", "\n", "}", "else", "if", "isArrayOfType", "(", "t", ",", "design", ".", "UUIDKind", ",", "design", ".", "DateTimeKind", ",", "design", ".", "AnyKind", ",", "design", ".", "NumberKind", ",", "design", ".", "BooleanKind", ")", "{", "suffix", "=", "\"", "\"", "\n", "}", "else", "{", "suffix", "=", "codegen", ".", "GoNativeType", "(", "t", ")", "\n", "}", "\n", "return", "pointer", "+", "suffix", "\n", "}" ]
// cmdFieldTypeString computes the Go type name used to store command flags of the given design type. Complex types are String
[ "cmdFieldTypeString", "computes", "the", "Go", "type", "name", "used", "to", "store", "command", "flags", "of", "the", "given", "design", "type", ".", "Complex", "types", "are", "String" ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/goagen/gen_client/generator.go#L759-L772
166,858
goadesign/goa
goagen/gen_client/generator.go
toString
func toString(name, target string, att *design.AttributeDefinition) string { switch actual := att.Type.(type) { case design.Primitive: switch actual.Kind() { case design.IntegerKind: return fmt.Sprintf("%s := strconv.Itoa(%s)", target, name) case design.BooleanKind: return fmt.Sprintf("%s := strconv.FormatBool(%s)", target, name) case design.NumberKind: return fmt.Sprintf("%s := strconv.FormatFloat(%s, 'f', -1, 64)", target, name) case design.StringKind: return fmt.Sprintf("%s := %s", target, name) case design.DateTimeKind: return fmt.Sprintf("%s := %s.Format(time.RFC3339)", target, strings.Replace(name, "*", "", -1)) // remove pointer if present case design.UUIDKind: return fmt.Sprintf("%s := %s.String()", target, strings.Replace(name, "*", "", -1)) // remove pointer if present case design.AnyKind: return fmt.Sprintf("%s := fmt.Sprintf(\"%%v\", %s)", target, name) case design.FileKind: return fmt.Sprintf("%s := fmt.Sprintf(\"%%v\", %s)", target, name) default: panic("unknown primitive type") } case *design.Array: data := map[string]interface{}{ "Name": name, "Target": target, "ElemType": actual.ElemType, } return codegen.RunTemplate(arrayToStringTmpl, data) default: panic("cannot convert non simple type " + att.Type.Name() + " to string") // bug } }
go
func toString(name, target string, att *design.AttributeDefinition) string { switch actual := att.Type.(type) { case design.Primitive: switch actual.Kind() { case design.IntegerKind: return fmt.Sprintf("%s := strconv.Itoa(%s)", target, name) case design.BooleanKind: return fmt.Sprintf("%s := strconv.FormatBool(%s)", target, name) case design.NumberKind: return fmt.Sprintf("%s := strconv.FormatFloat(%s, 'f', -1, 64)", target, name) case design.StringKind: return fmt.Sprintf("%s := %s", target, name) case design.DateTimeKind: return fmt.Sprintf("%s := %s.Format(time.RFC3339)", target, strings.Replace(name, "*", "", -1)) // remove pointer if present case design.UUIDKind: return fmt.Sprintf("%s := %s.String()", target, strings.Replace(name, "*", "", -1)) // remove pointer if present case design.AnyKind: return fmt.Sprintf("%s := fmt.Sprintf(\"%%v\", %s)", target, name) case design.FileKind: return fmt.Sprintf("%s := fmt.Sprintf(\"%%v\", %s)", target, name) default: panic("unknown primitive type") } case *design.Array: data := map[string]interface{}{ "Name": name, "Target": target, "ElemType": actual.ElemType, } return codegen.RunTemplate(arrayToStringTmpl, data) default: panic("cannot convert non simple type " + att.Type.Name() + " to string") // bug } }
[ "func", "toString", "(", "name", ",", "target", "string", ",", "att", "*", "design", ".", "AttributeDefinition", ")", "string", "{", "switch", "actual", ":=", "att", ".", "Type", ".", "(", "type", ")", "{", "case", "design", ".", "Primitive", ":", "switch", "actual", ".", "Kind", "(", ")", "{", "case", "design", ".", "IntegerKind", ":", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "target", ",", "name", ")", "\n", "case", "design", ".", "BooleanKind", ":", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "target", ",", "name", ")", "\n", "case", "design", ".", "NumberKind", ":", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "target", ",", "name", ")", "\n", "case", "design", ".", "StringKind", ":", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "target", ",", "name", ")", "\n", "case", "design", ".", "DateTimeKind", ":", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "target", ",", "strings", ".", "Replace", "(", "name", ",", "\"", "\"", ",", "\"", "\"", ",", "-", "1", ")", ")", "// remove pointer if present", "\n", "case", "design", ".", "UUIDKind", ":", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "target", ",", "strings", ".", "Replace", "(", "name", ",", "\"", "\"", ",", "\"", "\"", ",", "-", "1", ")", ")", "// remove pointer if present", "\n", "case", "design", ".", "AnyKind", ":", "return", "fmt", ".", "Sprintf", "(", "\"", "\\\"", "\\\"", "\"", ",", "target", ",", "name", ")", "\n", "case", "design", ".", "FileKind", ":", "return", "fmt", ".", "Sprintf", "(", "\"", "\\\"", "\\\"", "\"", ",", "target", ",", "name", ")", "\n", "default", ":", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "case", "*", "design", ".", "Array", ":", "data", ":=", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "name", ",", "\"", "\"", ":", "target", ",", "\"", "\"", ":", "actual", ".", "ElemType", ",", "}", "\n", "return", "codegen", ".", "RunTemplate", "(", "arrayToStringTmpl", ",", "data", ")", "\n", "default", ":", "panic", "(", "\"", "\"", "+", "att", ".", "Type", ".", "Name", "(", ")", "+", "\"", "\"", ")", "// bug", "\n", "}", "\n", "}" ]
// toString generates Go code that converts the given simple type attribute into a string.
[ "toString", "generates", "Go", "code", "that", "converts", "the", "given", "simple", "type", "attribute", "into", "a", "string", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/goagen/gen_client/generator.go#L792-L825
166,859
goadesign/goa
goagen/gen_client/generator.go
defaultPath
func defaultPath(action *design.ActionDefinition) string { for _, r := range action.Routes { candidate := r.FullPath() if !strings.ContainsRune(candidate, ':') { return candidate } } return "" }
go
func defaultPath(action *design.ActionDefinition) string { for _, r := range action.Routes { candidate := r.FullPath() if !strings.ContainsRune(candidate, ':') { return candidate } } return "" }
[ "func", "defaultPath", "(", "action", "*", "design", ".", "ActionDefinition", ")", "string", "{", "for", "_", ",", "r", ":=", "range", "action", ".", "Routes", "{", "candidate", ":=", "r", ".", "FullPath", "(", ")", "\n", "if", "!", "strings", ".", "ContainsRune", "(", "candidate", ",", "':'", ")", "{", "return", "candidate", "\n", "}", "\n", "}", "\n", "return", "\"", "\"", "\n", "}" ]
// defaultPath returns the first route path for the given action that does not take any wildcard, // empty string if none.
[ "defaultPath", "returns", "the", "first", "route", "path", "for", "the", "given", "action", "that", "does", "not", "take", "any", "wildcard", "empty", "string", "if", "none", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/goagen/gen_client/generator.go#L829-L837
166,860
goadesign/goa
goagen/gen_client/generator.go
signerType
func signerType(scheme *design.SecuritySchemeDefinition) string { switch scheme.Kind { case design.JWTSecurityKind: return "goaclient.JWTSigner" // goa client package imported under goaclient case design.OAuth2SecurityKind: return "goaclient.OAuth2Signer" case design.APIKeySecurityKind: return "goaclient.APIKeySigner" case design.BasicAuthSecurityKind: return "goaclient.BasicSigner" } return "" }
go
func signerType(scheme *design.SecuritySchemeDefinition) string { switch scheme.Kind { case design.JWTSecurityKind: return "goaclient.JWTSigner" // goa client package imported under goaclient case design.OAuth2SecurityKind: return "goaclient.OAuth2Signer" case design.APIKeySecurityKind: return "goaclient.APIKeySigner" case design.BasicAuthSecurityKind: return "goaclient.BasicSigner" } return "" }
[ "func", "signerType", "(", "scheme", "*", "design", ".", "SecuritySchemeDefinition", ")", "string", "{", "switch", "scheme", ".", "Kind", "{", "case", "design", ".", "JWTSecurityKind", ":", "return", "\"", "\"", "// goa client package imported under goaclient", "\n", "case", "design", ".", "OAuth2SecurityKind", ":", "return", "\"", "\"", "\n", "case", "design", ".", "APIKeySecurityKind", ":", "return", "\"", "\"", "\n", "case", "design", ".", "BasicAuthSecurityKind", ":", "return", "\"", "\"", "\n", "}", "\n", "return", "\"", "\"", "\n", "}" ]
// signerType returns the name of the client signer used for the defined security model on the Action
[ "signerType", "returns", "the", "name", "of", "the", "client", "signer", "used", "for", "the", "defined", "security", "model", "on", "the", "Action" ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/goagen/gen_client/generator.go#L840-L852
166,861
goadesign/goa
goagen/gen_client/generator.go
pathTemplate
func pathTemplate(r *design.RouteDefinition) string { return design.WildcardRegex.ReplaceAllLiteralString(r.FullPath(), "/%s") }
go
func pathTemplate(r *design.RouteDefinition) string { return design.WildcardRegex.ReplaceAllLiteralString(r.FullPath(), "/%s") }
[ "func", "pathTemplate", "(", "r", "*", "design", ".", "RouteDefinition", ")", "string", "{", "return", "design", ".", "WildcardRegex", ".", "ReplaceAllLiteralString", "(", "r", ".", "FullPath", "(", ")", ",", "\"", "\"", ")", "\n", "}" ]
// pathTemplate returns a fmt format suitable to build a request path to the route.
[ "pathTemplate", "returns", "a", "fmt", "format", "suitable", "to", "build", "a", "request", "path", "to", "the", "route", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/goagen/gen_client/generator.go#L855-L857
166,862
goadesign/goa
goagen/gen_client/generator.go
pathParams
func pathParams(r *design.RouteDefinition) string { pnames := r.Params() params := make(design.Object, len(pnames)) for _, p := range pnames { params[p] = r.Parent.Params.Type.ToObject()[p] } return join(&design.AttributeDefinition{Type: params}, false, pnames) }
go
func pathParams(r *design.RouteDefinition) string { pnames := r.Params() params := make(design.Object, len(pnames)) for _, p := range pnames { params[p] = r.Parent.Params.Type.ToObject()[p] } return join(&design.AttributeDefinition{Type: params}, false, pnames) }
[ "func", "pathParams", "(", "r", "*", "design", ".", "RouteDefinition", ")", "string", "{", "pnames", ":=", "r", ".", "Params", "(", ")", "\n", "params", ":=", "make", "(", "design", ".", "Object", ",", "len", "(", "pnames", ")", ")", "\n", "for", "_", ",", "p", ":=", "range", "pnames", "{", "params", "[", "p", "]", "=", "r", ".", "Parent", ".", "Params", ".", "Type", ".", "ToObject", "(", ")", "[", "p", "]", "\n", "}", "\n", "return", "join", "(", "&", "design", ".", "AttributeDefinition", "{", "Type", ":", "params", "}", ",", "false", ",", "pnames", ")", "\n", "}" ]
// pathParams return the function signature of the path factory function for the given route.
[ "pathParams", "return", "the", "function", "signature", "of", "the", "path", "factory", "function", "for", "the", "given", "route", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/goagen/gen_client/generator.go#L860-L867
166,863
goadesign/goa
goagen/gen_client/generator.go
typeName
func typeName(mt *design.MediaTypeDefinition) string { if mt.IsError() { return "ErrorResponse" } return codegen.GoTypeName(mt, mt.AllRequired(), 1, false) }
go
func typeName(mt *design.MediaTypeDefinition) string { if mt.IsError() { return "ErrorResponse" } return codegen.GoTypeName(mt, mt.AllRequired(), 1, false) }
[ "func", "typeName", "(", "mt", "*", "design", ".", "MediaTypeDefinition", ")", "string", "{", "if", "mt", ".", "IsError", "(", ")", "{", "return", "\"", "\"", "\n", "}", "\n", "return", "codegen", ".", "GoTypeName", "(", "mt", ",", "mt", ".", "AllRequired", "(", ")", ",", "1", ",", "false", ")", "\n", "}" ]
// typeName returns Go type name of given MediaType definition.
[ "typeName", "returns", "Go", "type", "name", "of", "given", "MediaType", "definition", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/goagen/gen_client/generator.go#L870-L875
166,864
goadesign/goa
goagen/gen_client/generator.go
initParams
func initParams(att *design.AttributeDefinition) ([]*paramData, []*paramData) { if att == nil { return nil, nil } obj := att.Type.ToObject() var reqParamData []*paramData var optParamData []*paramData for n, q := range obj { varName := codegen.Goify(n, false) param := &paramData{ Name: n, VarName: varName, Attribute: q, } if q.Type.IsPrimitive() { param.MustToString = q.Type.Kind() != design.StringKind param.ValueName = toValueTypeName(varName, n, att) if att.IsRequired(n) { reqParamData = append(reqParamData, param) } else { param.CheckNil = true optParamData = append(optParamData, param) } } else { if q.Type.IsArray() { param.IsArray = true param.ElemAttribute = q.Type.ToArray().ElemType } param.MustToString = true param.ValueName = varName param.CheckNil = true if att.IsRequired(n) { reqParamData = append(reqParamData, param) } else { optParamData = append(optParamData, param) } } } return reqParamData, optParamData }
go
func initParams(att *design.AttributeDefinition) ([]*paramData, []*paramData) { if att == nil { return nil, nil } obj := att.Type.ToObject() var reqParamData []*paramData var optParamData []*paramData for n, q := range obj { varName := codegen.Goify(n, false) param := &paramData{ Name: n, VarName: varName, Attribute: q, } if q.Type.IsPrimitive() { param.MustToString = q.Type.Kind() != design.StringKind param.ValueName = toValueTypeName(varName, n, att) if att.IsRequired(n) { reqParamData = append(reqParamData, param) } else { param.CheckNil = true optParamData = append(optParamData, param) } } else { if q.Type.IsArray() { param.IsArray = true param.ElemAttribute = q.Type.ToArray().ElemType } param.MustToString = true param.ValueName = varName param.CheckNil = true if att.IsRequired(n) { reqParamData = append(reqParamData, param) } else { optParamData = append(optParamData, param) } } } return reqParamData, optParamData }
[ "func", "initParams", "(", "att", "*", "design", ".", "AttributeDefinition", ")", "(", "[", "]", "*", "paramData", ",", "[", "]", "*", "paramData", ")", "{", "if", "att", "==", "nil", "{", "return", "nil", ",", "nil", "\n", "}", "\n", "obj", ":=", "att", ".", "Type", ".", "ToObject", "(", ")", "\n", "var", "reqParamData", "[", "]", "*", "paramData", "\n", "var", "optParamData", "[", "]", "*", "paramData", "\n", "for", "n", ",", "q", ":=", "range", "obj", "{", "varName", ":=", "codegen", ".", "Goify", "(", "n", ",", "false", ")", "\n", "param", ":=", "&", "paramData", "{", "Name", ":", "n", ",", "VarName", ":", "varName", ",", "Attribute", ":", "q", ",", "}", "\n", "if", "q", ".", "Type", ".", "IsPrimitive", "(", ")", "{", "param", ".", "MustToString", "=", "q", ".", "Type", ".", "Kind", "(", ")", "!=", "design", ".", "StringKind", "\n", "param", ".", "ValueName", "=", "toValueTypeName", "(", "varName", ",", "n", ",", "att", ")", "\n", "if", "att", ".", "IsRequired", "(", "n", ")", "{", "reqParamData", "=", "append", "(", "reqParamData", ",", "param", ")", "\n", "}", "else", "{", "param", ".", "CheckNil", "=", "true", "\n", "optParamData", "=", "append", "(", "optParamData", ",", "param", ")", "\n", "}", "\n", "}", "else", "{", "if", "q", ".", "Type", ".", "IsArray", "(", ")", "{", "param", ".", "IsArray", "=", "true", "\n", "param", ".", "ElemAttribute", "=", "q", ".", "Type", ".", "ToArray", "(", ")", ".", "ElemType", "\n", "}", "\n", "param", ".", "MustToString", "=", "true", "\n", "param", ".", "ValueName", "=", "varName", "\n", "param", ".", "CheckNil", "=", "true", "\n", "if", "att", ".", "IsRequired", "(", "n", ")", "{", "reqParamData", "=", "append", "(", "reqParamData", ",", "param", ")", "\n", "}", "else", "{", "optParamData", "=", "append", "(", "optParamData", ",", "param", ")", "\n", "}", "\n", "}", "\n", "}", "\n\n", "return", "reqParamData", ",", "optParamData", "\n", "}" ]
// initParams returns required and optional paramData extracted from given attribute definition.
[ "initParams", "returns", "required", "and", "optional", "paramData", "extracted", "from", "given", "attribute", "definition", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/goagen/gen_client/generator.go#L889-L929
166,865
goadesign/goa
middleware/security/jwt/context.go
WithJWT
func WithJWT(ctx context.Context, t *jwt.Token) context.Context { return context.WithValue(ctx, jwtKey, t) }
go
func WithJWT(ctx context.Context, t *jwt.Token) context.Context { return context.WithValue(ctx, jwtKey, t) }
[ "func", "WithJWT", "(", "ctx", "context", ".", "Context", ",", "t", "*", "jwt", ".", "Token", ")", "context", ".", "Context", "{", "return", "context", ".", "WithValue", "(", "ctx", ",", "jwtKey", ",", "t", ")", "\n", "}" ]
// WithJWT creates a child context containing the given JWT.
[ "WithJWT", "creates", "a", "child", "context", "containing", "the", "given", "JWT", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/middleware/security/jwt/context.go#L16-L18
166,866
goadesign/goa
middleware/security/jwt/context.go
ContextJWT
func ContextJWT(ctx context.Context) *jwt.Token { token, ok := ctx.Value(jwtKey).(*jwt.Token) if !ok { return nil } return token }
go
func ContextJWT(ctx context.Context) *jwt.Token { token, ok := ctx.Value(jwtKey).(*jwt.Token) if !ok { return nil } return token }
[ "func", "ContextJWT", "(", "ctx", "context", ".", "Context", ")", "*", "jwt", ".", "Token", "{", "token", ",", "ok", ":=", "ctx", ".", "Value", "(", "jwtKey", ")", ".", "(", "*", "jwt", ".", "Token", ")", "\n", "if", "!", "ok", "{", "return", "nil", "\n", "}", "\n", "return", "token", "\n", "}" ]
// ContextJWT retrieves the JWT token from a `context` that went through our security middleware.
[ "ContextJWT", "retrieves", "the", "JWT", "token", "from", "a", "context", "that", "went", "through", "our", "security", "middleware", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/middleware/security/jwt/context.go#L21-L27
166,867
goadesign/goa
cors/cors.go
MatchOriginRegexp
func MatchOriginRegexp(origin string, spec *regexp.Regexp) bool { return spec.Match([]byte(origin)) }
go
func MatchOriginRegexp(origin string, spec *regexp.Regexp) bool { return spec.Match([]byte(origin)) }
[ "func", "MatchOriginRegexp", "(", "origin", "string", ",", "spec", "*", "regexp", ".", "Regexp", ")", "bool", "{", "return", "spec", ".", "Match", "(", "[", "]", "byte", "(", "origin", ")", ")", "\n", "}" ]
// MatchOriginRegexp returns true if the given Origin header value matches the // origin specification. // Spec must be a valid regex
[ "MatchOriginRegexp", "returns", "true", "if", "the", "given", "Origin", "header", "value", "matches", "the", "origin", "specification", ".", "Spec", "must", "be", "a", "valid", "regex" ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/cors/cors.go#L57-L59
166,868
goadesign/goa
cors/cors.go
HandlePreflight
func HandlePreflight() goa.Handler { return func(ctx context.Context, rw http.ResponseWriter, req *http.Request) error { rw.WriteHeader(200) return nil } }
go
func HandlePreflight() goa.Handler { return func(ctx context.Context, rw http.ResponseWriter, req *http.Request) error { rw.WriteHeader(200) return nil } }
[ "func", "HandlePreflight", "(", ")", "goa", ".", "Handler", "{", "return", "func", "(", "ctx", "context", ".", "Context", ",", "rw", "http", ".", "ResponseWriter", ",", "req", "*", "http", ".", "Request", ")", "error", "{", "rw", ".", "WriteHeader", "(", "200", ")", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// HandlePreflight returns a simple 200 response. The middleware takes care of handling CORS.
[ "HandlePreflight", "returns", "a", "simple", "200", "response", ".", "The", "middleware", "takes", "care", "of", "handling", "CORS", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/cors/cors.go#L62-L67
166,869
goadesign/goa
design/apidsl/api.go
buildEncodingDefinition
func buildEncodingDefinition(encoding bool, args ...interface{}) *design.EncodingDefinition { var dsl func() var ok bool funcName := "Consumes" if encoding { funcName = "Produces" } if len(args) == 0 { dslengine.ReportError("missing argument in call to %s", funcName) return nil } if _, ok = args[0].(string); !ok { dslengine.ReportError("first argument to %s must be a string (MIME type)", funcName) return nil } last := len(args) if dsl, ok = args[len(args)-1].(func()); ok { last = len(args) - 1 } mimeTypes := make([]string, last) for i := 0; i < last; i++ { var mimeType string if mimeType, ok = args[i].(string); !ok { dslengine.ReportError("argument #%d of %s must be a string (MIME type)", i, funcName) return nil } mimeTypes[i] = mimeType } d := &design.EncodingDefinition{MIMETypes: mimeTypes, Encoder: encoding} if dsl != nil { dslengine.Execute(dsl, d) } return d }
go
func buildEncodingDefinition(encoding bool, args ...interface{}) *design.EncodingDefinition { var dsl func() var ok bool funcName := "Consumes" if encoding { funcName = "Produces" } if len(args) == 0 { dslengine.ReportError("missing argument in call to %s", funcName) return nil } if _, ok = args[0].(string); !ok { dslengine.ReportError("first argument to %s must be a string (MIME type)", funcName) return nil } last := len(args) if dsl, ok = args[len(args)-1].(func()); ok { last = len(args) - 1 } mimeTypes := make([]string, last) for i := 0; i < last; i++ { var mimeType string if mimeType, ok = args[i].(string); !ok { dslengine.ReportError("argument #%d of %s must be a string (MIME type)", i, funcName) return nil } mimeTypes[i] = mimeType } d := &design.EncodingDefinition{MIMETypes: mimeTypes, Encoder: encoding} if dsl != nil { dslengine.Execute(dsl, d) } return d }
[ "func", "buildEncodingDefinition", "(", "encoding", "bool", ",", "args", "...", "interface", "{", "}", ")", "*", "design", ".", "EncodingDefinition", "{", "var", "dsl", "func", "(", ")", "\n", "var", "ok", "bool", "\n", "funcName", ":=", "\"", "\"", "\n", "if", "encoding", "{", "funcName", "=", "\"", "\"", "\n", "}", "\n", "if", "len", "(", "args", ")", "==", "0", "{", "dslengine", ".", "ReportError", "(", "\"", "\"", ",", "funcName", ")", "\n", "return", "nil", "\n", "}", "\n", "if", "_", ",", "ok", "=", "args", "[", "0", "]", ".", "(", "string", ")", ";", "!", "ok", "{", "dslengine", ".", "ReportError", "(", "\"", "\"", ",", "funcName", ")", "\n", "return", "nil", "\n", "}", "\n", "last", ":=", "len", "(", "args", ")", "\n", "if", "dsl", ",", "ok", "=", "args", "[", "len", "(", "args", ")", "-", "1", "]", ".", "(", "func", "(", ")", ")", ";", "ok", "{", "last", "=", "len", "(", "args", ")", "-", "1", "\n", "}", "\n", "mimeTypes", ":=", "make", "(", "[", "]", "string", ",", "last", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "last", ";", "i", "++", "{", "var", "mimeType", "string", "\n", "if", "mimeType", ",", "ok", "=", "args", "[", "i", "]", ".", "(", "string", ")", ";", "!", "ok", "{", "dslengine", ".", "ReportError", "(", "\"", "\"", ",", "i", ",", "funcName", ")", "\n", "return", "nil", "\n", "}", "\n", "mimeTypes", "[", "i", "]", "=", "mimeType", "\n", "}", "\n", "d", ":=", "&", "design", ".", "EncodingDefinition", "{", "MIMETypes", ":", "mimeTypes", ",", "Encoder", ":", "encoding", "}", "\n", "if", "dsl", "!=", "nil", "{", "dslengine", ".", "Execute", "(", "dsl", ",", "d", ")", "\n", "}", "\n", "return", "d", "\n", "}" ]
// buildEncodingDefinition builds up an encoding definition.
[ "buildEncodingDefinition", "builds", "up", "an", "encoding", "definition", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/apidsl/api.go#L409-L442
166,870
goadesign/goa
goagen/gen_app/generator.go
NewGenerator
func NewGenerator(options ...Option) *Generator { g := &Generator{} g.validator = codegen.NewValidator() for _, option := range options { option(g) } return g }
go
func NewGenerator(options ...Option) *Generator { g := &Generator{} g.validator = codegen.NewValidator() for _, option := range options { option(g) } return g }
[ "func", "NewGenerator", "(", "options", "...", "Option", ")", "*", "Generator", "{", "g", ":=", "&", "Generator", "{", "}", "\n", "g", ".", "validator", "=", "codegen", ".", "NewValidator", "(", ")", "\n\n", "for", "_", ",", "option", ":=", "range", "options", "{", "option", "(", "g", ")", "\n", "}", "\n\n", "return", "g", "\n", "}" ]
//NewGenerator returns an initialized instance of an Application Generator
[ "NewGenerator", "returns", "an", "initialized", "instance", "of", "an", "Application", "Generator" ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/goagen/gen_app/generator.go#L16-L25
166,871
goadesign/goa
goagen/gen_app/generator.go
Cleanup
func (g *Generator) Cleanup() { if len(g.genfiles) == 0 { return } os.RemoveAll(g.OutDir) g.genfiles = nil }
go
func (g *Generator) Cleanup() { if len(g.genfiles) == 0 { return } os.RemoveAll(g.OutDir) g.genfiles = nil }
[ "func", "(", "g", "*", "Generator", ")", "Cleanup", "(", ")", "{", "if", "len", "(", "g", ".", "genfiles", ")", "==", "0", "{", "return", "\n", "}", "\n", "os", ".", "RemoveAll", "(", "g", ".", "OutDir", ")", "\n", "g", ".", "genfiles", "=", "nil", "\n", "}" ]
// Cleanup removes the entire "app" directory if it was created by this generator.
[ "Cleanup", "removes", "the", "entire", "app", "directory", "if", "it", "was", "created", "by", "this", "generator", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/goagen/gen_app/generator.go#L117-L123
166,872
goadesign/goa
goagen/gen_app/generator.go
generateHrefs
func (g *Generator) generateHrefs() (err error) { var ( hrefFile string resWr *ResourcesWriter ) { hrefFile = filepath.Join(g.OutDir, "hrefs.go") resWr, err = NewResourcesWriter(hrefFile) if err != nil { return } } defer func() { resWr.Close() if err == nil { err = resWr.FormatCode() } }() title := fmt.Sprintf("%s: Application Resource Href Factories", g.API.Context()) imports := []*codegen.ImportSpec{ codegen.SimpleImport("fmt"), codegen.SimpleImport("strings"), } if err = resWr.WriteHeader(title, g.Target, imports); err != nil { return err } g.genfiles = append(g.genfiles, hrefFile) err = g.API.IterateResources(func(r *design.ResourceDefinition) error { m := g.API.MediaTypeWithIdentifier(r.MediaType) var identifier string if m != nil { identifier = m.Identifier } else { identifier = "text/plain" } data := ResourceData{ Name: codegen.Goify(r.Name, true), Identifier: identifier, Description: r.Description, Type: m, CanonicalTemplate: codegen.CanonicalTemplate(r), CanonicalParams: codegen.CanonicalParams(r), } return resWr.Execute(&data) }) return }
go
func (g *Generator) generateHrefs() (err error) { var ( hrefFile string resWr *ResourcesWriter ) { hrefFile = filepath.Join(g.OutDir, "hrefs.go") resWr, err = NewResourcesWriter(hrefFile) if err != nil { return } } defer func() { resWr.Close() if err == nil { err = resWr.FormatCode() } }() title := fmt.Sprintf("%s: Application Resource Href Factories", g.API.Context()) imports := []*codegen.ImportSpec{ codegen.SimpleImport("fmt"), codegen.SimpleImport("strings"), } if err = resWr.WriteHeader(title, g.Target, imports); err != nil { return err } g.genfiles = append(g.genfiles, hrefFile) err = g.API.IterateResources(func(r *design.ResourceDefinition) error { m := g.API.MediaTypeWithIdentifier(r.MediaType) var identifier string if m != nil { identifier = m.Identifier } else { identifier = "text/plain" } data := ResourceData{ Name: codegen.Goify(r.Name, true), Identifier: identifier, Description: r.Description, Type: m, CanonicalTemplate: codegen.CanonicalTemplate(r), CanonicalParams: codegen.CanonicalParams(r), } return resWr.Execute(&data) }) return }
[ "func", "(", "g", "*", "Generator", ")", "generateHrefs", "(", ")", "(", "err", "error", ")", "{", "var", "(", "hrefFile", "string", "\n", "resWr", "*", "ResourcesWriter", "\n", ")", "\n", "{", "hrefFile", "=", "filepath", ".", "Join", "(", "g", ".", "OutDir", ",", "\"", "\"", ")", "\n", "resWr", ",", "err", "=", "NewResourcesWriter", "(", "hrefFile", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "}", "\n", "defer", "func", "(", ")", "{", "resWr", ".", "Close", "(", ")", "\n", "if", "err", "==", "nil", "{", "err", "=", "resWr", ".", "FormatCode", "(", ")", "\n", "}", "\n", "}", "(", ")", "\n", "title", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "g", ".", "API", ".", "Context", "(", ")", ")", "\n", "imports", ":=", "[", "]", "*", "codegen", ".", "ImportSpec", "{", "codegen", ".", "SimpleImport", "(", "\"", "\"", ")", ",", "codegen", ".", "SimpleImport", "(", "\"", "\"", ")", ",", "}", "\n", "if", "err", "=", "resWr", ".", "WriteHeader", "(", "title", ",", "g", ".", "Target", ",", "imports", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "g", ".", "genfiles", "=", "append", "(", "g", ".", "genfiles", ",", "hrefFile", ")", "\n", "err", "=", "g", ".", "API", ".", "IterateResources", "(", "func", "(", "r", "*", "design", ".", "ResourceDefinition", ")", "error", "{", "m", ":=", "g", ".", "API", ".", "MediaTypeWithIdentifier", "(", "r", ".", "MediaType", ")", "\n", "var", "identifier", "string", "\n", "if", "m", "!=", "nil", "{", "identifier", "=", "m", ".", "Identifier", "\n", "}", "else", "{", "identifier", "=", "\"", "\"", "\n", "}", "\n", "data", ":=", "ResourceData", "{", "Name", ":", "codegen", ".", "Goify", "(", "r", ".", "Name", ",", "true", ")", ",", "Identifier", ":", "identifier", ",", "Description", ":", "r", ".", "Description", ",", "Type", ":", "m", ",", "CanonicalTemplate", ":", "codegen", ".", "CanonicalTemplate", "(", "r", ")", ",", "CanonicalParams", ":", "codegen", ".", "CanonicalParams", "(", "r", ")", ",", "}", "\n", "return", "resWr", ".", "Execute", "(", "&", "data", ")", "\n", "}", ")", "\n", "return", "\n", "}" ]
// generateHrefs iterates through the API resources and generates the href factory methods.
[ "generateHrefs", "iterates", "through", "the", "API", "resources", "and", "generates", "the", "href", "factory", "methods", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/goagen/gen_app/generator.go#L377-L423
166,873
goadesign/goa
design/example.go
Generate
func (eg *exampleGenerator) Generate(seen []string) interface{} { // Randomize array length first, since that's from higher level if eg.hasLengthValidation() { return eg.generateValidatedLengthExample(seen) } // Enum should dominate, because the potential "examples" are fixed if eg.hasEnumValidation() { return eg.generateValidatedEnumExample() } // loop until a satisified example is generated hasFormat, hasPattern, hasMinMax := eg.hasFormatValidation(), eg.hasPatternValidation(), eg.hasMinMaxValidation() attempts := 0 for attempts < maxAttempts { attempts++ var example interface{} // Format comes first, since it initiates the example if hasFormat { example = eg.generateFormatExample() } // now validate with the rest of matchers; if not satisified, redo if hasPattern { if example == nil { example = eg.generateValidatedPatternExample() } else if !eg.checkPatternValidation(example) { continue } } if hasMinMax { if example == nil { example = eg.generateValidatedMinMaxValueExample() } else if !eg.checkMinMaxValueValidation(example) { continue } } if example == nil { example = eg.a.Type.GenerateExample(eg.r, seen) } return example } return eg.a.Type.GenerateExample(eg.r, seen) }
go
func (eg *exampleGenerator) Generate(seen []string) interface{} { // Randomize array length first, since that's from higher level if eg.hasLengthValidation() { return eg.generateValidatedLengthExample(seen) } // Enum should dominate, because the potential "examples" are fixed if eg.hasEnumValidation() { return eg.generateValidatedEnumExample() } // loop until a satisified example is generated hasFormat, hasPattern, hasMinMax := eg.hasFormatValidation(), eg.hasPatternValidation(), eg.hasMinMaxValidation() attempts := 0 for attempts < maxAttempts { attempts++ var example interface{} // Format comes first, since it initiates the example if hasFormat { example = eg.generateFormatExample() } // now validate with the rest of matchers; if not satisified, redo if hasPattern { if example == nil { example = eg.generateValidatedPatternExample() } else if !eg.checkPatternValidation(example) { continue } } if hasMinMax { if example == nil { example = eg.generateValidatedMinMaxValueExample() } else if !eg.checkMinMaxValueValidation(example) { continue } } if example == nil { example = eg.a.Type.GenerateExample(eg.r, seen) } return example } return eg.a.Type.GenerateExample(eg.r, seen) }
[ "func", "(", "eg", "*", "exampleGenerator", ")", "Generate", "(", "seen", "[", "]", "string", ")", "interface", "{", "}", "{", "// Randomize array length first, since that's from higher level", "if", "eg", ".", "hasLengthValidation", "(", ")", "{", "return", "eg", ".", "generateValidatedLengthExample", "(", "seen", ")", "\n", "}", "\n", "// Enum should dominate, because the potential \"examples\" are fixed", "if", "eg", ".", "hasEnumValidation", "(", ")", "{", "return", "eg", ".", "generateValidatedEnumExample", "(", ")", "\n", "}", "\n", "// loop until a satisified example is generated", "hasFormat", ",", "hasPattern", ",", "hasMinMax", ":=", "eg", ".", "hasFormatValidation", "(", ")", ",", "eg", ".", "hasPatternValidation", "(", ")", ",", "eg", ".", "hasMinMaxValidation", "(", ")", "\n", "attempts", ":=", "0", "\n", "for", "attempts", "<", "maxAttempts", "{", "attempts", "++", "\n", "var", "example", "interface", "{", "}", "\n", "// Format comes first, since it initiates the example", "if", "hasFormat", "{", "example", "=", "eg", ".", "generateFormatExample", "(", ")", "\n", "}", "\n", "// now validate with the rest of matchers; if not satisified, redo", "if", "hasPattern", "{", "if", "example", "==", "nil", "{", "example", "=", "eg", ".", "generateValidatedPatternExample", "(", ")", "\n", "}", "else", "if", "!", "eg", ".", "checkPatternValidation", "(", "example", ")", "{", "continue", "\n", "}", "\n", "}", "\n", "if", "hasMinMax", "{", "if", "example", "==", "nil", "{", "example", "=", "eg", ".", "generateValidatedMinMaxValueExample", "(", ")", "\n", "}", "else", "if", "!", "eg", ".", "checkMinMaxValueValidation", "(", "example", ")", "{", "continue", "\n", "}", "\n", "}", "\n", "if", "example", "==", "nil", "{", "example", "=", "eg", ".", "a", ".", "Type", ".", "GenerateExample", "(", "eg", ".", "r", ",", "seen", ")", "\n", "}", "\n", "return", "example", "\n", "}", "\n", "return", "eg", ".", "a", ".", "Type", ".", "GenerateExample", "(", "eg", ".", "r", ",", "seen", ")", "\n", "}" ]
// Generate generates a random value based on the given validations.
[ "Generate", "generates", "a", "random", "value", "based", "on", "the", "given", "validations", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/example.go#L27-L67
166,874
goadesign/goa
design/example.go
generateValidatedLengthExample
func (eg *exampleGenerator) generateValidatedLengthExample(seen []string) interface{} { count := eg.ExampleLength() if !eg.a.Type.IsArray() { return eg.r.faker.Characters(count) } res := make([]interface{}, count) for i := 0; i < count; i++ { res[i] = eg.a.Type.ToArray().ElemType.GenerateExample(eg.r, seen) } return res }
go
func (eg *exampleGenerator) generateValidatedLengthExample(seen []string) interface{} { count := eg.ExampleLength() if !eg.a.Type.IsArray() { return eg.r.faker.Characters(count) } res := make([]interface{}, count) for i := 0; i < count; i++ { res[i] = eg.a.Type.ToArray().ElemType.GenerateExample(eg.r, seen) } return res }
[ "func", "(", "eg", "*", "exampleGenerator", ")", "generateValidatedLengthExample", "(", "seen", "[", "]", "string", ")", "interface", "{", "}", "{", "count", ":=", "eg", ".", "ExampleLength", "(", ")", "\n", "if", "!", "eg", ".", "a", ".", "Type", ".", "IsArray", "(", ")", "{", "return", "eg", ".", "r", ".", "faker", ".", "Characters", "(", "count", ")", "\n", "}", "\n", "res", ":=", "make", "(", "[", "]", "interface", "{", "}", ",", "count", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "count", ";", "i", "++", "{", "res", "[", "i", "]", "=", "eg", ".", "a", ".", "Type", ".", "ToArray", "(", ")", ".", "ElemType", ".", "GenerateExample", "(", "eg", ".", "r", ",", "seen", ")", "\n", "}", "\n", "return", "res", "\n", "}" ]
// generateValidatedLengthExample generates a random size array of examples based on what's given.
[ "generateValidatedLengthExample", "generates", "a", "random", "size", "array", "of", "examples", "based", "on", "what", "s", "given", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/example.go#L115-L125
166,875
goadesign/goa
design/example.go
generateValidatedEnumExample
func (eg *exampleGenerator) generateValidatedEnumExample() interface{} { if !eg.hasEnumValidation() { return nil } values := eg.a.Validation.Values count := len(values) i := eg.r.Int() % count return values[i] }
go
func (eg *exampleGenerator) generateValidatedEnumExample() interface{} { if !eg.hasEnumValidation() { return nil } values := eg.a.Validation.Values count := len(values) i := eg.r.Int() % count return values[i] }
[ "func", "(", "eg", "*", "exampleGenerator", ")", "generateValidatedEnumExample", "(", ")", "interface", "{", "}", "{", "if", "!", "eg", ".", "hasEnumValidation", "(", ")", "{", "return", "nil", "\n", "}", "\n", "values", ":=", "eg", ".", "a", ".", "Validation", ".", "Values", "\n", "count", ":=", "len", "(", "values", ")", "\n", "i", ":=", "eg", ".", "r", ".", "Int", "(", ")", "%", "count", "\n", "return", "values", "[", "i", "]", "\n", "}" ]
// generateValidatedEnumExample returns a random selected enum value.
[ "generateValidatedEnumExample", "returns", "a", "random", "selected", "enum", "value", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/example.go#L132-L140
166,876
goadesign/goa
design/example.go
generateFormatExample
func (eg *exampleGenerator) generateFormatExample() interface{} { if !eg.hasFormatValidation() { return nil } format := eg.a.Validation.Format if res, ok := map[string]interface{}{ "email": eg.r.faker.Email(), "hostname": eg.r.faker.DomainName() + "." + eg.r.faker.DomainSuffix(), "date": time.Unix(int64(eg.r.Int())%1454957045, 0).Format("2006-01-02"), // to obtain a "fixed" rand "date-time": time.Unix(int64(eg.r.Int())%1454957045, 0).Format(time.RFC3339), // to obtain a "fixed" rand "ipv4": eg.r.faker.IPv4Address().String(), "ipv6": eg.r.faker.IPv6Address().String(), "ip": eg.r.faker.IPv4Address().String(), "uri": eg.r.faker.URL(), "mac": func() string { res, err := regen.Generate(`([0-9A-F]{2}-){5}[0-9A-F]{2}`) if err != nil { return "12-34-56-78-9A-BC" } return res }(), "cidr": "192.168.100.14/24", "regexp": eg.r.faker.Characters(3) + ".*", "rfc1123": time.Unix(int64(eg.r.Int())%1454957045, 0).Format(time.RFC1123), // to obtain a "fixed" rand }[format]; ok { return res } panic("Validation: unknown format '" + format + "'") // bug }
go
func (eg *exampleGenerator) generateFormatExample() interface{} { if !eg.hasFormatValidation() { return nil } format := eg.a.Validation.Format if res, ok := map[string]interface{}{ "email": eg.r.faker.Email(), "hostname": eg.r.faker.DomainName() + "." + eg.r.faker.DomainSuffix(), "date": time.Unix(int64(eg.r.Int())%1454957045, 0).Format("2006-01-02"), // to obtain a "fixed" rand "date-time": time.Unix(int64(eg.r.Int())%1454957045, 0).Format(time.RFC3339), // to obtain a "fixed" rand "ipv4": eg.r.faker.IPv4Address().String(), "ipv6": eg.r.faker.IPv6Address().String(), "ip": eg.r.faker.IPv4Address().String(), "uri": eg.r.faker.URL(), "mac": func() string { res, err := regen.Generate(`([0-9A-F]{2}-){5}[0-9A-F]{2}`) if err != nil { return "12-34-56-78-9A-BC" } return res }(), "cidr": "192.168.100.14/24", "regexp": eg.r.faker.Characters(3) + ".*", "rfc1123": time.Unix(int64(eg.r.Int())%1454957045, 0).Format(time.RFC1123), // to obtain a "fixed" rand }[format]; ok { return res } panic("Validation: unknown format '" + format + "'") // bug }
[ "func", "(", "eg", "*", "exampleGenerator", ")", "generateFormatExample", "(", ")", "interface", "{", "}", "{", "if", "!", "eg", ".", "hasFormatValidation", "(", ")", "{", "return", "nil", "\n", "}", "\n", "format", ":=", "eg", ".", "a", ".", "Validation", ".", "Format", "\n", "if", "res", ",", "ok", ":=", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "eg", ".", "r", ".", "faker", ".", "Email", "(", ")", ",", "\"", "\"", ":", "eg", ".", "r", ".", "faker", ".", "DomainName", "(", ")", "+", "\"", "\"", "+", "eg", ".", "r", ".", "faker", ".", "DomainSuffix", "(", ")", ",", "\"", "\"", ":", "time", ".", "Unix", "(", "int64", "(", "eg", ".", "r", ".", "Int", "(", ")", ")", "%", "1454957045", ",", "0", ")", ".", "Format", "(", "\"", "\"", ")", ",", "// to obtain a \"fixed\" rand", "\"", "\"", ":", "time", ".", "Unix", "(", "int64", "(", "eg", ".", "r", ".", "Int", "(", ")", ")", "%", "1454957045", ",", "0", ")", ".", "Format", "(", "time", ".", "RFC3339", ")", ",", "// to obtain a \"fixed\" rand", "\"", "\"", ":", "eg", ".", "r", ".", "faker", ".", "IPv4Address", "(", ")", ".", "String", "(", ")", ",", "\"", "\"", ":", "eg", ".", "r", ".", "faker", ".", "IPv6Address", "(", ")", ".", "String", "(", ")", ",", "\"", "\"", ":", "eg", ".", "r", ".", "faker", ".", "IPv4Address", "(", ")", ".", "String", "(", ")", ",", "\"", "\"", ":", "eg", ".", "r", ".", "faker", ".", "URL", "(", ")", ",", "\"", "\"", ":", "func", "(", ")", "string", "{", "res", ",", "err", ":=", "regen", ".", "Generate", "(", "`([0-9A-F]{2}-){5}[0-9A-F]{2}`", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", "\n", "}", "\n", "return", "res", "\n", "}", "(", ")", ",", "\"", "\"", ":", "\"", "\"", ",", "\"", "\"", ":", "eg", ".", "r", ".", "faker", ".", "Characters", "(", "3", ")", "+", "\"", "\"", ",", "\"", "\"", ":", "time", ".", "Unix", "(", "int64", "(", "eg", ".", "r", ".", "Int", "(", ")", ")", "%", "1454957045", ",", "0", ")", ".", "Format", "(", "time", ".", "RFC1123", ")", ",", "// to obtain a \"fixed\" rand", "}", "[", "format", "]", ";", "ok", "{", "return", "res", "\n", "}", "\n", "panic", "(", "\"", "\"", "+", "format", "+", "\"", "\"", ")", "// bug", "\n", "}" ]
// generateFormatExample returns a random example based on the format the user asks.
[ "generateFormatExample", "returns", "a", "random", "example", "based", "on", "the", "format", "the", "user", "asks", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/example.go#L147-L175
166,877
goadesign/goa
middleware/tracer.go
TraceIDFunc
func TraceIDFunc(f IDFunc) TracerOption { return func(o *tracerOptions) *tracerOptions { if f == nil { panic("trace ID function cannot be nil") } o.traceIDFunc = f return o } }
go
func TraceIDFunc(f IDFunc) TracerOption { return func(o *tracerOptions) *tracerOptions { if f == nil { panic("trace ID function cannot be nil") } o.traceIDFunc = f return o } }
[ "func", "TraceIDFunc", "(", "f", "IDFunc", ")", "TracerOption", "{", "return", "func", "(", "o", "*", "tracerOptions", ")", "*", "tracerOptions", "{", "if", "f", "==", "nil", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "o", ".", "traceIDFunc", "=", "f", "\n", "return", "o", "\n", "}", "\n", "}" ]
// TraceIDFunc is a constructor option that overrides the function used to // compute trace IDs.
[ "TraceIDFunc", "is", "a", "constructor", "option", "that", "overrides", "the", "function", "used", "to", "compute", "trace", "IDs", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/middleware/tracer.go#L48-L56
166,878
goadesign/goa
middleware/tracer.go
SpanIDFunc
func SpanIDFunc(f IDFunc) TracerOption { return func(o *tracerOptions) *tracerOptions { if f == nil { panic("span ID function cannot be nil") } o.spanIDFunc = f return o } }
go
func SpanIDFunc(f IDFunc) TracerOption { return func(o *tracerOptions) *tracerOptions { if f == nil { panic("span ID function cannot be nil") } o.spanIDFunc = f return o } }
[ "func", "SpanIDFunc", "(", "f", "IDFunc", ")", "TracerOption", "{", "return", "func", "(", "o", "*", "tracerOptions", ")", "*", "tracerOptions", "{", "if", "f", "==", "nil", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "o", ".", "spanIDFunc", "=", "f", "\n", "return", "o", "\n", "}", "\n", "}" ]
// SpanIDFunc is a constructor option that overrides the function used to // compute span IDs.
[ "SpanIDFunc", "is", "a", "constructor", "option", "that", "overrides", "the", "function", "used", "to", "compute", "span", "IDs", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/middleware/tracer.go#L60-L68
166,879
goadesign/goa
middleware/tracer.go
SamplingPercent
func SamplingPercent(p int) TracerOption { if p < 0 || p > 100 { panic("sampling rate must be between 0 and 100") } return func(o *tracerOptions) *tracerOptions { o.samplingPercent = p return o } }
go
func SamplingPercent(p int) TracerOption { if p < 0 || p > 100 { panic("sampling rate must be between 0 and 100") } return func(o *tracerOptions) *tracerOptions { o.samplingPercent = p return o } }
[ "func", "SamplingPercent", "(", "p", "int", ")", "TracerOption", "{", "if", "p", "<", "0", "||", "p", ">", "100", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "return", "func", "(", "o", "*", "tracerOptions", ")", "*", "tracerOptions", "{", "o", ".", "samplingPercent", "=", "p", "\n", "return", "o", "\n", "}", "\n", "}" ]
// SamplingPercent sets the tracing sampling rate as a percentage value. // It panics if p is less than 0 or more than 100. // SamplingPercent and MaxSamplingRate are mutually exclusive.
[ "SamplingPercent", "sets", "the", "tracing", "sampling", "rate", "as", "a", "percentage", "value", ".", "It", "panics", "if", "p", "is", "less", "than", "0", "or", "more", "than", "100", ".", "SamplingPercent", "and", "MaxSamplingRate", "are", "mutually", "exclusive", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/middleware/tracer.go#L73-L81
166,880
goadesign/goa
middleware/tracer.go
MaxSamplingRate
func MaxSamplingRate(r int) TracerOption { if r <= 0 { panic("max sampling rate must be greater than 0") } return func(o *tracerOptions) *tracerOptions { o.maxSamplingRate = r return o } }
go
func MaxSamplingRate(r int) TracerOption { if r <= 0 { panic("max sampling rate must be greater than 0") } return func(o *tracerOptions) *tracerOptions { o.maxSamplingRate = r return o } }
[ "func", "MaxSamplingRate", "(", "r", "int", ")", "TracerOption", "{", "if", "r", "<=", "0", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "return", "func", "(", "o", "*", "tracerOptions", ")", "*", "tracerOptions", "{", "o", ".", "maxSamplingRate", "=", "r", "\n", "return", "o", "\n", "}", "\n", "}" ]
// MaxSamplingRate sets a target sampling rate in requests per second. Setting a // max sampling rate causes the middleware to adjust the sampling percent // dynamically. // SamplingPercent and MaxSamplingRate are mutually exclusive.
[ "MaxSamplingRate", "sets", "a", "target", "sampling", "rate", "in", "requests", "per", "second", ".", "Setting", "a", "max", "sampling", "rate", "causes", "the", "middleware", "to", "adjust", "the", "sampling", "percent", "dynamically", ".", "SamplingPercent", "and", "MaxSamplingRate", "are", "mutually", "exclusive", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/middleware/tracer.go#L87-L95
166,881
goadesign/goa
middleware/tracer.go
SampleSize
func SampleSize(s int) TracerOption { if s <= 0 { panic("sample size must be greater than 0") } return func(o *tracerOptions) *tracerOptions { o.sampleSize = s return o } }
go
func SampleSize(s int) TracerOption { if s <= 0 { panic("sample size must be greater than 0") } return func(o *tracerOptions) *tracerOptions { o.sampleSize = s return o } }
[ "func", "SampleSize", "(", "s", "int", ")", "TracerOption", "{", "if", "s", "<=", "0", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "return", "func", "(", "o", "*", "tracerOptions", ")", "*", "tracerOptions", "{", "o", ".", "sampleSize", "=", "s", "\n", "return", "o", "\n", "}", "\n", "}" ]
// SampleSize sets the number of requests between two adjustments of the sampling // rate when MaxSamplingRate is set. Defaults to 1,000.
[ "SampleSize", "sets", "the", "number", "of", "requests", "between", "two", "adjustments", "of", "the", "sampling", "rate", "when", "MaxSamplingRate", "is", "set", ".", "Defaults", "to", "1", "000", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/middleware/tracer.go#L99-L107
166,882
goadesign/goa
middleware/tracer.go
NewTracer
func NewTracer(opts ...TracerOption) goa.Middleware { o := &tracerOptions{ traceIDFunc: shortID, spanIDFunc: shortID, samplingPercent: 100, sampleSize: 1000, // only applies if maxSamplingRate is set } for _, opt := range opts { o = opt(o) } var sampler Sampler if o.maxSamplingRate > 0 { sampler = NewAdaptiveSampler(o.maxSamplingRate, o.sampleSize) } else { sampler = NewFixedSampler(o.samplingPercent) } return func(h goa.Handler) goa.Handler { return func(ctx context.Context, rw http.ResponseWriter, req *http.Request) error { // insert a new trace ID only if not already being traced. traceID := req.Header.Get(TraceIDHeader) if traceID == "" { // insert tracing only within sample. if sampler.Sample() { traceID = o.traceIDFunc() } else { return h(ctx, rw, req) } } // insert IDs into context to enable tracing. spanID := o.spanIDFunc() parentID := req.Header.Get(ParentSpanIDHeader) ctx = WithTrace(ctx, traceID, spanID, parentID) return h(ctx, rw, req) } } }
go
func NewTracer(opts ...TracerOption) goa.Middleware { o := &tracerOptions{ traceIDFunc: shortID, spanIDFunc: shortID, samplingPercent: 100, sampleSize: 1000, // only applies if maxSamplingRate is set } for _, opt := range opts { o = opt(o) } var sampler Sampler if o.maxSamplingRate > 0 { sampler = NewAdaptiveSampler(o.maxSamplingRate, o.sampleSize) } else { sampler = NewFixedSampler(o.samplingPercent) } return func(h goa.Handler) goa.Handler { return func(ctx context.Context, rw http.ResponseWriter, req *http.Request) error { // insert a new trace ID only if not already being traced. traceID := req.Header.Get(TraceIDHeader) if traceID == "" { // insert tracing only within sample. if sampler.Sample() { traceID = o.traceIDFunc() } else { return h(ctx, rw, req) } } // insert IDs into context to enable tracing. spanID := o.spanIDFunc() parentID := req.Header.Get(ParentSpanIDHeader) ctx = WithTrace(ctx, traceID, spanID, parentID) return h(ctx, rw, req) } } }
[ "func", "NewTracer", "(", "opts", "...", "TracerOption", ")", "goa", ".", "Middleware", "{", "o", ":=", "&", "tracerOptions", "{", "traceIDFunc", ":", "shortID", ",", "spanIDFunc", ":", "shortID", ",", "samplingPercent", ":", "100", ",", "sampleSize", ":", "1000", ",", "// only applies if maxSamplingRate is set", "}", "\n", "for", "_", ",", "opt", ":=", "range", "opts", "{", "o", "=", "opt", "(", "o", ")", "\n", "}", "\n", "var", "sampler", "Sampler", "\n", "if", "o", ".", "maxSamplingRate", ">", "0", "{", "sampler", "=", "NewAdaptiveSampler", "(", "o", ".", "maxSamplingRate", ",", "o", ".", "sampleSize", ")", "\n", "}", "else", "{", "sampler", "=", "NewFixedSampler", "(", "o", ".", "samplingPercent", ")", "\n", "}", "\n", "return", "func", "(", "h", "goa", ".", "Handler", ")", "goa", ".", "Handler", "{", "return", "func", "(", "ctx", "context", ".", "Context", ",", "rw", "http", ".", "ResponseWriter", ",", "req", "*", "http", ".", "Request", ")", "error", "{", "// insert a new trace ID only if not already being traced.", "traceID", ":=", "req", ".", "Header", ".", "Get", "(", "TraceIDHeader", ")", "\n", "if", "traceID", "==", "\"", "\"", "{", "// insert tracing only within sample.", "if", "sampler", ".", "Sample", "(", ")", "{", "traceID", "=", "o", ".", "traceIDFunc", "(", ")", "\n", "}", "else", "{", "return", "h", "(", "ctx", ",", "rw", ",", "req", ")", "\n", "}", "\n", "}", "\n\n", "// insert IDs into context to enable tracing.", "spanID", ":=", "o", ".", "spanIDFunc", "(", ")", "\n", "parentID", ":=", "req", ".", "Header", ".", "Get", "(", "ParentSpanIDHeader", ")", "\n", "ctx", "=", "WithTrace", "(", "ctx", ",", "traceID", ",", "spanID", ",", "parentID", ")", "\n", "return", "h", "(", "ctx", ",", "rw", ",", "req", ")", "\n", "}", "\n", "}", "\n", "}" ]
// NewTracer returns a trace middleware that initializes the trace information // in the request context. The information can be retrieved using any of the // ContextXXX functions. // // samplingPercent must be a value between 0 and 100. It represents the percentage // of requests that should be traced. If the incoming request has a Trace ID // header then the sampling rate is disregarded and the tracing is enabled. // // spanIDFunc and traceIDFunc are the functions used to create Span and Trace // IDs respectively. This is configurable so that the created IDs are compatible // with the various backend tracing systems. The xray package provides // implementations that produce AWS X-Ray compatible IDs.
[ "NewTracer", "returns", "a", "trace", "middleware", "that", "initializes", "the", "trace", "information", "in", "the", "request", "context", ".", "The", "information", "can", "be", "retrieved", "using", "any", "of", "the", "ContextXXX", "functions", ".", "samplingPercent", "must", "be", "a", "value", "between", "0", "and", "100", ".", "It", "represents", "the", "percentage", "of", "requests", "that", "should", "be", "traced", ".", "If", "the", "incoming", "request", "has", "a", "Trace", "ID", "header", "then", "the", "sampling", "rate", "is", "disregarded", "and", "the", "tracing", "is", "enabled", ".", "spanIDFunc", "and", "traceIDFunc", "are", "the", "functions", "used", "to", "create", "Span", "and", "Trace", "IDs", "respectively", ".", "This", "is", "configurable", "so", "that", "the", "created", "IDs", "are", "compatible", "with", "the", "various", "backend", "tracing", "systems", ".", "The", "xray", "package", "provides", "implementations", "that", "produce", "AWS", "X", "-", "Ray", "compatible", "IDs", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/middleware/tracer.go#L121-L157
166,883
goadesign/goa
middleware/tracer.go
Tracer
func Tracer(sampleRate int, spanIDFunc, traceIDFunc IDFunc) goa.Middleware { return NewTracer(SamplingPercent(sampleRate), SpanIDFunc(spanIDFunc), TraceIDFunc(traceIDFunc)) }
go
func Tracer(sampleRate int, spanIDFunc, traceIDFunc IDFunc) goa.Middleware { return NewTracer(SamplingPercent(sampleRate), SpanIDFunc(spanIDFunc), TraceIDFunc(traceIDFunc)) }
[ "func", "Tracer", "(", "sampleRate", "int", ",", "spanIDFunc", ",", "traceIDFunc", "IDFunc", ")", "goa", ".", "Middleware", "{", "return", "NewTracer", "(", "SamplingPercent", "(", "sampleRate", ")", ",", "SpanIDFunc", "(", "spanIDFunc", ")", ",", "TraceIDFunc", "(", "traceIDFunc", ")", ")", "\n", "}" ]
// Tracer is deprecated in favor of NewTracer.
[ "Tracer", "is", "deprecated", "in", "favor", "of", "NewTracer", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/middleware/tracer.go#L160-L162
166,884
goadesign/goa
middleware/tracer.go
ContextTraceID
func ContextTraceID(ctx context.Context) string { if t := ctx.Value(traceKey); t != nil { return t.(string) } return "" }
go
func ContextTraceID(ctx context.Context) string { if t := ctx.Value(traceKey); t != nil { return t.(string) } return "" }
[ "func", "ContextTraceID", "(", "ctx", "context", ".", "Context", ")", "string", "{", "if", "t", ":=", "ctx", ".", "Value", "(", "traceKey", ")", ";", "t", "!=", "nil", "{", "return", "t", ".", "(", "string", ")", "\n", "}", "\n", "return", "\"", "\"", "\n", "}" ]
// ContextTraceID returns the trace ID extracted from the given context if any, // the empty string otherwise.
[ "ContextTraceID", "returns", "the", "trace", "ID", "extracted", "from", "the", "given", "context", "if", "any", "the", "empty", "string", "otherwise", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/middleware/tracer.go#L172-L177
166,885
goadesign/goa
middleware/tracer.go
ContextSpanID
func ContextSpanID(ctx context.Context) string { if s := ctx.Value(spanKey); s != nil { return s.(string) } return "" }
go
func ContextSpanID(ctx context.Context) string { if s := ctx.Value(spanKey); s != nil { return s.(string) } return "" }
[ "func", "ContextSpanID", "(", "ctx", "context", ".", "Context", ")", "string", "{", "if", "s", ":=", "ctx", ".", "Value", "(", "spanKey", ")", ";", "s", "!=", "nil", "{", "return", "s", ".", "(", "string", ")", "\n", "}", "\n", "return", "\"", "\"", "\n", "}" ]
// ContextSpanID returns the span ID extracted from the given context if any, // the empty string otherwise.
[ "ContextSpanID", "returns", "the", "span", "ID", "extracted", "from", "the", "given", "context", "if", "any", "the", "empty", "string", "otherwise", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/middleware/tracer.go#L181-L186
166,886
goadesign/goa
middleware/tracer.go
ContextParentSpanID
func ContextParentSpanID(ctx context.Context) string { if p := ctx.Value(parentSpanKey); p != nil { return p.(string) } return "" }
go
func ContextParentSpanID(ctx context.Context) string { if p := ctx.Value(parentSpanKey); p != nil { return p.(string) } return "" }
[ "func", "ContextParentSpanID", "(", "ctx", "context", ".", "Context", ")", "string", "{", "if", "p", ":=", "ctx", ".", "Value", "(", "parentSpanKey", ")", ";", "p", "!=", "nil", "{", "return", "p", ".", "(", "string", ")", "\n", "}", "\n", "return", "\"", "\"", "\n", "}" ]
// ContextParentSpanID returns the parent span ID extracted from the given // context if any, the empty string otherwise.
[ "ContextParentSpanID", "returns", "the", "parent", "span", "ID", "extracted", "from", "the", "given", "context", "if", "any", "the", "empty", "string", "otherwise", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/middleware/tracer.go#L190-L195
166,887
goadesign/goa
middleware/tracer.go
WithTrace
func WithTrace(ctx context.Context, traceID, spanID, parentID string) context.Context { if parentID != "" { ctx = context.WithValue(ctx, parentSpanKey, parentID) } ctx = context.WithValue(ctx, traceKey, traceID) ctx = context.WithValue(ctx, spanKey, spanID) return ctx }
go
func WithTrace(ctx context.Context, traceID, spanID, parentID string) context.Context { if parentID != "" { ctx = context.WithValue(ctx, parentSpanKey, parentID) } ctx = context.WithValue(ctx, traceKey, traceID) ctx = context.WithValue(ctx, spanKey, spanID) return ctx }
[ "func", "WithTrace", "(", "ctx", "context", ".", "Context", ",", "traceID", ",", "spanID", ",", "parentID", "string", ")", "context", ".", "Context", "{", "if", "parentID", "!=", "\"", "\"", "{", "ctx", "=", "context", ".", "WithValue", "(", "ctx", ",", "parentSpanKey", ",", "parentID", ")", "\n", "}", "\n", "ctx", "=", "context", ".", "WithValue", "(", "ctx", ",", "traceKey", ",", "traceID", ")", "\n", "ctx", "=", "context", ".", "WithValue", "(", "ctx", ",", "spanKey", ",", "spanID", ")", "\n", "return", "ctx", "\n", "}" ]
// WithTrace returns a context containing the given trace, span and parent span // IDs.
[ "WithTrace", "returns", "a", "context", "containing", "the", "given", "trace", "span", "and", "parent", "span", "IDs", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/middleware/tracer.go#L199-L206
166,888
goadesign/goa
middleware/tracer.go
Do
func (d *tracedDoer) Do(ctx context.Context, req *http.Request) (*http.Response, error) { var ( traceID = ContextTraceID(ctx) spanID = ContextSpanID(ctx) ) if traceID != "" { req.Header.Set(TraceIDHeader, traceID) req.Header.Set(ParentSpanIDHeader, spanID) } return d.Doer.Do(ctx, req) }
go
func (d *tracedDoer) Do(ctx context.Context, req *http.Request) (*http.Response, error) { var ( traceID = ContextTraceID(ctx) spanID = ContextSpanID(ctx) ) if traceID != "" { req.Header.Set(TraceIDHeader, traceID) req.Header.Set(ParentSpanIDHeader, spanID) } return d.Doer.Do(ctx, req) }
[ "func", "(", "d", "*", "tracedDoer", ")", "Do", "(", "ctx", "context", ".", "Context", ",", "req", "*", "http", ".", "Request", ")", "(", "*", "http", ".", "Response", ",", "error", ")", "{", "var", "(", "traceID", "=", "ContextTraceID", "(", "ctx", ")", "\n", "spanID", "=", "ContextSpanID", "(", "ctx", ")", "\n", ")", "\n", "if", "traceID", "!=", "\"", "\"", "{", "req", ".", "Header", ".", "Set", "(", "TraceIDHeader", ",", "traceID", ")", "\n", "req", ".", "Header", ".", "Set", "(", "ParentSpanIDHeader", ",", "spanID", ")", "\n", "}", "\n\n", "return", "d", ".", "Doer", ".", "Do", "(", "ctx", ",", "req", ")", "\n", "}" ]
// Do adds the tracing headers to the requests before making it.
[ "Do", "adds", "the", "tracing", "headers", "to", "the", "requests", "before", "making", "it", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/middleware/tracer.go#L209-L220
166,889
goadesign/goa
validation.go
ValidatePattern
func ValidatePattern(p string, val string) bool { knownPatternsLock.RLock() r, ok := knownPatterns[p] knownPatternsLock.RUnlock() if !ok { r = regexp.MustCompile(p) // DSL validation makes sure regexp is valid knownPatternsLock.Lock() knownPatterns[p] = r knownPatternsLock.Unlock() } return r.MatchString(val) }
go
func ValidatePattern(p string, val string) bool { knownPatternsLock.RLock() r, ok := knownPatterns[p] knownPatternsLock.RUnlock() if !ok { r = regexp.MustCompile(p) // DSL validation makes sure regexp is valid knownPatternsLock.Lock() knownPatterns[p] = r knownPatternsLock.Unlock() } return r.MatchString(val) }
[ "func", "ValidatePattern", "(", "p", "string", ",", "val", "string", ")", "bool", "{", "knownPatternsLock", ".", "RLock", "(", ")", "\n", "r", ",", "ok", ":=", "knownPatterns", "[", "p", "]", "\n", "knownPatternsLock", ".", "RUnlock", "(", ")", "\n", "if", "!", "ok", "{", "r", "=", "regexp", ".", "MustCompile", "(", "p", ")", "// DSL validation makes sure regexp is valid", "\n", "knownPatternsLock", ".", "Lock", "(", ")", "\n", "knownPatterns", "[", "p", "]", "=", "r", "\n", "knownPatternsLock", ".", "Unlock", "(", ")", "\n", "}", "\n", "return", "r", ".", "MatchString", "(", "val", ")", "\n", "}" ]
// ValidatePattern returns an error if val does not match the regular expression p. // It makes an effort to minimize the number of times the regular expression needs to be compiled.
[ "ValidatePattern", "returns", "an", "error", "if", "val", "does", "not", "match", "the", "regular", "expression", "p", ".", "It", "makes", "an", "effort", "to", "minimize", "the", "number", "of", "times", "the", "regular", "expression", "needs", "to", "be", "compiled", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/validation.go#L144-L155
166,890
goadesign/goa
client/client.go
New
func New(c Doer) *Client { if c == nil { c = HTTPClientDoer(http.DefaultClient) } return &Client{Doer: c} }
go
func New(c Doer) *Client { if c == nil { c = HTTPClientDoer(http.DefaultClient) } return &Client{Doer: c} }
[ "func", "New", "(", "c", "Doer", ")", "*", "Client", "{", "if", "c", "==", "nil", "{", "c", "=", "HTTPClientDoer", "(", "http", ".", "DefaultClient", ")", "\n", "}", "\n", "return", "&", "Client", "{", "Doer", ":", "c", "}", "\n", "}" ]
// New creates a new API client that wraps c. // If c is nil, the returned client wraps http.DefaultClient.
[ "New", "creates", "a", "new", "API", "client", "that", "wraps", "c", ".", "If", "c", "is", "nil", "the", "returned", "client", "wraps", "http", ".", "DefaultClient", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/client/client.go#L41-L46
166,891
goadesign/goa
client/client.go
Do
func (f doFunc) Do(ctx context.Context, req *http.Request) (*http.Response, error) { return f(ctx, req) }
go
func (f doFunc) Do(ctx context.Context, req *http.Request) (*http.Response, error) { return f(ctx, req) }
[ "func", "(", "f", "doFunc", ")", "Do", "(", "ctx", "context", ".", "Context", ",", "req", "*", "http", ".", "Request", ")", "(", "*", "http", ".", "Response", ",", "error", ")", "{", "return", "f", "(", "ctx", ",", "req", ")", "\n", "}" ]
// Do implements Doer.Do
[ "Do", "implements", "Doer", ".", "Do" ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/client/client.go#L59-L61
166,892
goadesign/goa
client/client.go
Do
func (c *Client) Do(ctx context.Context, req *http.Request) (*http.Response, error) { // TODO: setting the request ID should be done via client middleware. For now only set it if the // caller provided one in the ctx. if ctxreqid := ContextRequestID(ctx); ctxreqid != "" { req.Header.Set("X-Request-Id", ctxreqid) } if c.UserAgent != "" { req.Header.Set("User-Agent", c.UserAgent) } startedAt := time.Now() ctx, id := ContextWithRequestID(ctx) goa.LogInfo(ctx, "started", "id", id, req.Method, req.URL.String()) if c.Dump { c.dumpRequest(ctx, req) } resp, err := c.Doer.Do(ctx, req) if err != nil { goa.LogError(ctx, "failed", "err", err) return nil, err } goa.LogInfo(ctx, "completed", "id", id, "status", resp.StatusCode, "time", time.Since(startedAt).String()) if c.Dump { c.dumpResponse(ctx, resp) } return resp, err }
go
func (c *Client) Do(ctx context.Context, req *http.Request) (*http.Response, error) { // TODO: setting the request ID should be done via client middleware. For now only set it if the // caller provided one in the ctx. if ctxreqid := ContextRequestID(ctx); ctxreqid != "" { req.Header.Set("X-Request-Id", ctxreqid) } if c.UserAgent != "" { req.Header.Set("User-Agent", c.UserAgent) } startedAt := time.Now() ctx, id := ContextWithRequestID(ctx) goa.LogInfo(ctx, "started", "id", id, req.Method, req.URL.String()) if c.Dump { c.dumpRequest(ctx, req) } resp, err := c.Doer.Do(ctx, req) if err != nil { goa.LogError(ctx, "failed", "err", err) return nil, err } goa.LogInfo(ctx, "completed", "id", id, "status", resp.StatusCode, "time", time.Since(startedAt).String()) if c.Dump { c.dumpResponse(ctx, resp) } return resp, err }
[ "func", "(", "c", "*", "Client", ")", "Do", "(", "ctx", "context", ".", "Context", ",", "req", "*", "http", ".", "Request", ")", "(", "*", "http", ".", "Response", ",", "error", ")", "{", "// TODO: setting the request ID should be done via client middleware. For now only set it if the", "// caller provided one in the ctx.", "if", "ctxreqid", ":=", "ContextRequestID", "(", "ctx", ")", ";", "ctxreqid", "!=", "\"", "\"", "{", "req", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "ctxreqid", ")", "\n", "}", "\n", "if", "c", ".", "UserAgent", "!=", "\"", "\"", "{", "req", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "c", ".", "UserAgent", ")", "\n", "}", "\n", "startedAt", ":=", "time", ".", "Now", "(", ")", "\n", "ctx", ",", "id", ":=", "ContextWithRequestID", "(", "ctx", ")", "\n", "goa", ".", "LogInfo", "(", "ctx", ",", "\"", "\"", ",", "\"", "\"", ",", "id", ",", "req", ".", "Method", ",", "req", ".", "URL", ".", "String", "(", ")", ")", "\n", "if", "c", ".", "Dump", "{", "c", ".", "dumpRequest", "(", "ctx", ",", "req", ")", "\n", "}", "\n", "resp", ",", "err", ":=", "c", ".", "Doer", ".", "Do", "(", "ctx", ",", "req", ")", "\n", "if", "err", "!=", "nil", "{", "goa", ".", "LogError", "(", "ctx", ",", "\"", "\"", ",", "\"", "\"", ",", "err", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n", "goa", ".", "LogInfo", "(", "ctx", ",", "\"", "\"", ",", "\"", "\"", ",", "id", ",", "\"", "\"", ",", "resp", ".", "StatusCode", ",", "\"", "\"", ",", "time", ".", "Since", "(", "startedAt", ")", ".", "String", "(", ")", ")", "\n", "if", "c", ".", "Dump", "{", "c", ".", "dumpResponse", "(", "ctx", ",", "resp", ")", "\n", "}", "\n", "return", "resp", ",", "err", "\n", "}" ]
// Do wraps the underlying http client Do method and adds logging. // The logger should be in the context.
[ "Do", "wraps", "the", "underlying", "http", "client", "Do", "method", "and", "adds", "logging", ".", "The", "logger", "should", "be", "in", "the", "context", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/client/client.go#L65-L90
166,893
goadesign/goa
client/client.go
dumpRequest
func (c *Client) dumpRequest(ctx context.Context, req *http.Request) { reqBody, err := dumpReqBody(req) if err != nil { goa.LogError(ctx, "Failed to load request body for dump", "err", err.Error()) } goa.LogInfo(ctx, "request headers", headersToSlice(req.Header)...) if reqBody != nil { goa.LogInfo(ctx, "request", "body", string(reqBody)) } }
go
func (c *Client) dumpRequest(ctx context.Context, req *http.Request) { reqBody, err := dumpReqBody(req) if err != nil { goa.LogError(ctx, "Failed to load request body for dump", "err", err.Error()) } goa.LogInfo(ctx, "request headers", headersToSlice(req.Header)...) if reqBody != nil { goa.LogInfo(ctx, "request", "body", string(reqBody)) } }
[ "func", "(", "c", "*", "Client", ")", "dumpRequest", "(", "ctx", "context", ".", "Context", ",", "req", "*", "http", ".", "Request", ")", "{", "reqBody", ",", "err", ":=", "dumpReqBody", "(", "req", ")", "\n", "if", "err", "!=", "nil", "{", "goa", ".", "LogError", "(", "ctx", ",", "\"", "\"", ",", "\"", "\"", ",", "err", ".", "Error", "(", ")", ")", "\n", "}", "\n", "goa", ".", "LogInfo", "(", "ctx", ",", "\"", "\"", ",", "headersToSlice", "(", "req", ".", "Header", ")", "...", ")", "\n", "if", "reqBody", "!=", "nil", "{", "goa", ".", "LogInfo", "(", "ctx", ",", "\"", "\"", ",", "\"", "\"", ",", "string", "(", "reqBody", ")", ")", "\n", "}", "\n", "}" ]
// Dump request if needed.
[ "Dump", "request", "if", "needed", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/client/client.go#L93-L102
166,894
goadesign/goa
client/client.go
dumpResponse
func (c *Client) dumpResponse(ctx context.Context, resp *http.Response) { respBody, _ := dumpRespBody(resp) goa.LogInfo(ctx, "response headers", headersToSlice(resp.Header)...) if respBody != nil { goa.LogInfo(ctx, "response", "body", string(respBody)) } }
go
func (c *Client) dumpResponse(ctx context.Context, resp *http.Response) { respBody, _ := dumpRespBody(resp) goa.LogInfo(ctx, "response headers", headersToSlice(resp.Header)...) if respBody != nil { goa.LogInfo(ctx, "response", "body", string(respBody)) } }
[ "func", "(", "c", "*", "Client", ")", "dumpResponse", "(", "ctx", "context", ".", "Context", ",", "resp", "*", "http", ".", "Response", ")", "{", "respBody", ",", "_", ":=", "dumpRespBody", "(", "resp", ")", "\n", "goa", ".", "LogInfo", "(", "ctx", ",", "\"", "\"", ",", "headersToSlice", "(", "resp", ".", "Header", ")", "...", ")", "\n", "if", "respBody", "!=", "nil", "{", "goa", ".", "LogInfo", "(", "ctx", ",", "\"", "\"", ",", "\"", "\"", ",", "string", "(", "respBody", ")", ")", "\n", "}", "\n", "}" ]
// dumpResponse dumps the response and the request.
[ "dumpResponse", "dumps", "the", "response", "and", "the", "request", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/client/client.go#L105-L111
166,895
goadesign/goa
client/client.go
headersToSlice
func headersToSlice(header http.Header) []interface{} { res := make([]interface{}, 2*len(header)) i := 0 for k, v := range header { res[i] = k if len(v) == 1 { res[i+1] = v[0] } else { res[i+1] = v } i += 2 } return res }
go
func headersToSlice(header http.Header) []interface{} { res := make([]interface{}, 2*len(header)) i := 0 for k, v := range header { res[i] = k if len(v) == 1 { res[i+1] = v[0] } else { res[i+1] = v } i += 2 } return res }
[ "func", "headersToSlice", "(", "header", "http", ".", "Header", ")", "[", "]", "interface", "{", "}", "{", "res", ":=", "make", "(", "[", "]", "interface", "{", "}", ",", "2", "*", "len", "(", "header", ")", ")", "\n", "i", ":=", "0", "\n", "for", "k", ",", "v", ":=", "range", "header", "{", "res", "[", "i", "]", "=", "k", "\n", "if", "len", "(", "v", ")", "==", "1", "{", "res", "[", "i", "+", "1", "]", "=", "v", "[", "0", "]", "\n", "}", "else", "{", "res", "[", "i", "+", "1", "]", "=", "v", "\n", "}", "\n", "i", "+=", "2", "\n", "}", "\n", "return", "res", "\n", "}" ]
// headersToSlice produces a loggable slice from a HTTP header.
[ "headersToSlice", "produces", "a", "loggable", "slice", "from", "a", "HTTP", "header", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/client/client.go#L114-L127
166,896
goadesign/goa
client/client.go
dumpReqBody
func dumpReqBody(req *http.Request) ([]byte, error) { if req.Body == nil { return nil, nil } var save io.ReadCloser var err error save, req.Body, err = drainBody(req.Body) if err != nil { return nil, err } var b bytes.Buffer var dest io.Writer = &b chunked := len(req.TransferEncoding) > 0 && req.TransferEncoding[0] == "chunked" if chunked { dest = httputil.NewChunkedWriter(dest) } _, err = io.Copy(dest, req.Body) if chunked { dest.(io.Closer).Close() io.WriteString(&b, "\r\n") } req.Body = save return b.Bytes(), err }
go
func dumpReqBody(req *http.Request) ([]byte, error) { if req.Body == nil { return nil, nil } var save io.ReadCloser var err error save, req.Body, err = drainBody(req.Body) if err != nil { return nil, err } var b bytes.Buffer var dest io.Writer = &b chunked := len(req.TransferEncoding) > 0 && req.TransferEncoding[0] == "chunked" if chunked { dest = httputil.NewChunkedWriter(dest) } _, err = io.Copy(dest, req.Body) if chunked { dest.(io.Closer).Close() io.WriteString(&b, "\r\n") } req.Body = save return b.Bytes(), err }
[ "func", "dumpReqBody", "(", "req", "*", "http", ".", "Request", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "if", "req", ".", "Body", "==", "nil", "{", "return", "nil", ",", "nil", "\n", "}", "\n", "var", "save", "io", ".", "ReadCloser", "\n", "var", "err", "error", "\n", "save", ",", "req", ".", "Body", ",", "err", "=", "drainBody", "(", "req", ".", "Body", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "var", "b", "bytes", ".", "Buffer", "\n", "var", "dest", "io", ".", "Writer", "=", "&", "b", "\n", "chunked", ":=", "len", "(", "req", ".", "TransferEncoding", ")", ">", "0", "&&", "req", ".", "TransferEncoding", "[", "0", "]", "==", "\"", "\"", "\n", "if", "chunked", "{", "dest", "=", "httputil", ".", "NewChunkedWriter", "(", "dest", ")", "\n", "}", "\n", "_", ",", "err", "=", "io", ".", "Copy", "(", "dest", ",", "req", ".", "Body", ")", "\n", "if", "chunked", "{", "dest", ".", "(", "io", ".", "Closer", ")", ".", "Close", "(", ")", "\n", "io", ".", "WriteString", "(", "&", "b", ",", "\"", "\\r", "\\n", "\"", ")", "\n", "}", "\n", "req", ".", "Body", "=", "save", "\n", "return", "b", ".", "Bytes", "(", ")", ",", "err", "\n", "}" ]
// Dump request body, strongly inspired from httputil.DumpRequest
[ "Dump", "request", "body", "strongly", "inspired", "from", "httputil", ".", "DumpRequest" ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/client/client.go#L130-L153
166,897
goadesign/goa
client/client.go
dumpRespBody
func dumpRespBody(resp *http.Response) ([]byte, error) { if resp.Body == nil { return nil, nil } var b bytes.Buffer savecl := resp.ContentLength var save io.ReadCloser var err error save, resp.Body, err = drainBody(resp.Body) if err != nil { return nil, err } _, err = io.Copy(&b, resp.Body) if err != nil { return nil, err } resp.Body = save resp.ContentLength = savecl if err != nil { return nil, err } return b.Bytes(), nil }
go
func dumpRespBody(resp *http.Response) ([]byte, error) { if resp.Body == nil { return nil, nil } var b bytes.Buffer savecl := resp.ContentLength var save io.ReadCloser var err error save, resp.Body, err = drainBody(resp.Body) if err != nil { return nil, err } _, err = io.Copy(&b, resp.Body) if err != nil { return nil, err } resp.Body = save resp.ContentLength = savecl if err != nil { return nil, err } return b.Bytes(), nil }
[ "func", "dumpRespBody", "(", "resp", "*", "http", ".", "Response", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "if", "resp", ".", "Body", "==", "nil", "{", "return", "nil", ",", "nil", "\n", "}", "\n", "var", "b", "bytes", ".", "Buffer", "\n", "savecl", ":=", "resp", ".", "ContentLength", "\n", "var", "save", "io", ".", "ReadCloser", "\n", "var", "err", "error", "\n", "save", ",", "resp", ".", "Body", ",", "err", "=", "drainBody", "(", "resp", ".", "Body", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "_", ",", "err", "=", "io", ".", "Copy", "(", "&", "b", ",", "resp", ".", "Body", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "resp", ".", "Body", "=", "save", "\n", "resp", ".", "ContentLength", "=", "savecl", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "b", ".", "Bytes", "(", ")", ",", "nil", "\n", "}" ]
// Dump response body, strongly inspired from httputil.DumpResponse
[ "Dump", "response", "body", "strongly", "inspired", "from", "httputil", ".", "DumpResponse" ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/client/client.go#L156-L178
166,898
goadesign/goa
client/client.go
ContextRequestID
func ContextRequestID(ctx context.Context) string { var reqID string id := ctx.Value(reqIDKey) if id != nil { reqID = id.(string) } return reqID }
go
func ContextRequestID(ctx context.Context) string { var reqID string id := ctx.Value(reqIDKey) if id != nil { reqID = id.(string) } return reqID }
[ "func", "ContextRequestID", "(", "ctx", "context", ".", "Context", ")", "string", "{", "var", "reqID", "string", "\n", "id", ":=", "ctx", ".", "Value", "(", "reqIDKey", ")", "\n", "if", "id", "!=", "nil", "{", "reqID", "=", "id", ".", "(", "string", ")", "\n", "}", "\n", "return", "reqID", "\n", "}" ]
// ContextRequestID extracts the Request ID from the context.
[ "ContextRequestID", "extracts", "the", "Request", "ID", "from", "the", "context", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/client/client.go#L228-L235
166,899
goadesign/goa
client/client.go
ContextWithRequestID
func ContextWithRequestID(ctx context.Context) (context.Context, string) { reqID := ContextRequestID(ctx) if reqID == "" { reqID = shortID() ctx = context.WithValue(ctx, reqIDKey, reqID) } return ctx, reqID }
go
func ContextWithRequestID(ctx context.Context) (context.Context, string) { reqID := ContextRequestID(ctx) if reqID == "" { reqID = shortID() ctx = context.WithValue(ctx, reqIDKey, reqID) } return ctx, reqID }
[ "func", "ContextWithRequestID", "(", "ctx", "context", ".", "Context", ")", "(", "context", ".", "Context", ",", "string", ")", "{", "reqID", ":=", "ContextRequestID", "(", "ctx", ")", "\n", "if", "reqID", "==", "\"", "\"", "{", "reqID", "=", "shortID", "(", ")", "\n", "ctx", "=", "context", ".", "WithValue", "(", "ctx", ",", "reqIDKey", ",", "reqID", ")", "\n", "}", "\n", "return", "ctx", ",", "reqID", "\n", "}" ]
// ContextWithRequestID returns ctx and the request ID if it already has one or creates and returns a new context with // a new request ID.
[ "ContextWithRequestID", "returns", "ctx", "and", "the", "request", "ID", "if", "it", "already", "has", "one", "or", "creates", "and", "returns", "a", "new", "context", "with", "a", "new", "request", "ID", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/client/client.go#L239-L246