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,600
goadesign/goa
uuid/uuid.go
UnmarshalText
func (u *UUID) UnmarshalText(text []byte) error { t := uuid.UUID{} err := t.UnmarshalText(text) for i, b := range t.Bytes() { u[i] = b } return err }
go
func (u *UUID) UnmarshalText(text []byte) error { t := uuid.UUID{} err := t.UnmarshalText(text) for i, b := range t.Bytes() { u[i] = b } return err }
[ "func", "(", "u", "*", "UUID", ")", "UnmarshalText", "(", "text", "[", "]", "byte", ")", "error", "{", "t", ":=", "uuid", ".", "UUID", "{", "}", "\n", "err", ":=", "t", ".", "UnmarshalText", "(", "text", ")", "\n", "for", "i", ",", "b", ":=", "range", "t", ".", "Bytes", "(", ")", "{", "u", "[", "i", "]", "=", "b", "\n", "}", "\n", "return", "err", "\n", "}" ]
// UnmarshalText Wrapper over the real UnmarshalText method
[ "UnmarshalText", "Wrapper", "over", "the", "real", "UnmarshalText", "method" ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/uuid/uuid.go#L52-L59
166,601
goadesign/goa
uuid/uuid.go
Scan
func (u *UUID) Scan(src interface{}) error { switch src := src.(type) { case []byte: if len(src) == uuid.Size { return u.UnmarshalBinary(src) } return u.UnmarshalText(src) case string: return u.UnmarshalText([]byte(src)) } return fmt.Errorf("uuid: cannot convert %T to UUID", src) }
go
func (u *UUID) Scan(src interface{}) error { switch src := src.(type) { case []byte: if len(src) == uuid.Size { return u.UnmarshalBinary(src) } return u.UnmarshalText(src) case string: return u.UnmarshalText([]byte(src)) } return fmt.Errorf("uuid: cannot convert %T to UUID", src) }
[ "func", "(", "u", "*", "UUID", ")", "Scan", "(", "src", "interface", "{", "}", ")", "error", "{", "switch", "src", ":=", "src", ".", "(", "type", ")", "{", "case", "[", "]", "byte", ":", "if", "len", "(", "src", ")", "==", "uuid", ".", "Size", "{", "return", "u", ".", "UnmarshalBinary", "(", "src", ")", "\n", "}", "\n", "return", "u", ".", "UnmarshalText", "(", "src", ")", "\n\n", "case", "string", ":", "return", "u", ".", "UnmarshalText", "(", "[", "]", "byte", "(", "src", ")", ")", "\n", "}", "\n\n", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "src", ")", "\n", "}" ]
// Scan implements the sql.Scanner interface. // A 16-byte slice is handled by UnmarshalBinary, while // a longer byte slice or a string is handled by UnmarshalText.
[ "Scan", "implements", "the", "sql", ".", "Scanner", "interface", ".", "A", "16", "-", "byte", "slice", "is", "handled", "by", "UnmarshalBinary", "while", "a", "longer", "byte", "slice", "or", "a", "string", "is", "handled", "by", "UnmarshalText", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/uuid/uuid.go#L69-L82
166,602
goadesign/goa
design/apidsl/attribute.go
attributeFromRef
func attributeFromRef(name string, ref design.DataType) *design.AttributeDefinition { if ref == nil { return nil } switch t := ref.(type) { case *design.UserTypeDefinition: if t.DSLFunc != nil { dsl := t.DSLFunc t.DSLFunc = nil dslengine.Execute(dsl, t.AttributeDefinition) } if att, ok := t.ToObject()[name]; ok { return design.DupAtt(att) } case *design.MediaTypeDefinition: if t.DSLFunc != nil { dsl := t.DSLFunc t.DSLFunc = nil dslengine.Execute(dsl, t) } if att, ok := t.ToObject()[name]; ok { return design.DupAtt(att) } case design.Object: if att, ok := t[name]; ok { return design.DupAtt(att) } } return nil }
go
func attributeFromRef(name string, ref design.DataType) *design.AttributeDefinition { if ref == nil { return nil } switch t := ref.(type) { case *design.UserTypeDefinition: if t.DSLFunc != nil { dsl := t.DSLFunc t.DSLFunc = nil dslengine.Execute(dsl, t.AttributeDefinition) } if att, ok := t.ToObject()[name]; ok { return design.DupAtt(att) } case *design.MediaTypeDefinition: if t.DSLFunc != nil { dsl := t.DSLFunc t.DSLFunc = nil dslengine.Execute(dsl, t) } if att, ok := t.ToObject()[name]; ok { return design.DupAtt(att) } case design.Object: if att, ok := t[name]; ok { return design.DupAtt(att) } } return nil }
[ "func", "attributeFromRef", "(", "name", "string", ",", "ref", "design", ".", "DataType", ")", "*", "design", ".", "AttributeDefinition", "{", "if", "ref", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "switch", "t", ":=", "ref", ".", "(", "type", ")", "{", "case", "*", "design", ".", "UserTypeDefinition", ":", "if", "t", ".", "DSLFunc", "!=", "nil", "{", "dsl", ":=", "t", ".", "DSLFunc", "\n", "t", ".", "DSLFunc", "=", "nil", "\n", "dslengine", ".", "Execute", "(", "dsl", ",", "t", ".", "AttributeDefinition", ")", "\n", "}", "\n", "if", "att", ",", "ok", ":=", "t", ".", "ToObject", "(", ")", "[", "name", "]", ";", "ok", "{", "return", "design", ".", "DupAtt", "(", "att", ")", "\n", "}", "\n", "case", "*", "design", ".", "MediaTypeDefinition", ":", "if", "t", ".", "DSLFunc", "!=", "nil", "{", "dsl", ":=", "t", ".", "DSLFunc", "\n", "t", ".", "DSLFunc", "=", "nil", "\n", "dslengine", ".", "Execute", "(", "dsl", ",", "t", ")", "\n", "}", "\n", "if", "att", ",", "ok", ":=", "t", ".", "ToObject", "(", ")", "[", "name", "]", ";", "ok", "{", "return", "design", ".", "DupAtt", "(", "att", ")", "\n", "}", "\n", "case", "design", ".", "Object", ":", "if", "att", ",", "ok", ":=", "t", "[", "name", "]", ";", "ok", "{", "return", "design", ".", "DupAtt", "(", "att", ")", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// attributeFromRef returns a base attribute given a reference data type. // It takes care of running the DSL on the reference type if it hasn't run yet.
[ "attributeFromRef", "returns", "a", "base", "attribute", "given", "a", "reference", "data", "type", ".", "It", "takes", "care", "of", "running", "the", "DSL", "on", "the", "reference", "type", "if", "it", "hasn", "t", "run", "yet", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/apidsl/attribute.go#L144-L173
166,603
goadesign/goa
dslengine/runner.go
Register
func Register(r Root) { for _, o := range roots { if r.DSLName() == o.DSLName() { fmt.Fprintf(os.Stderr, "goagen: duplicate DSL %s", r.DSLName()) os.Exit(1) } } t := reflect.TypeOf(r) if t.Kind() == reflect.Ptr { t = t.Elem() } dslPackages[t.PkgPath()] = true roots = append(roots, r) }
go
func Register(r Root) { for _, o := range roots { if r.DSLName() == o.DSLName() { fmt.Fprintf(os.Stderr, "goagen: duplicate DSL %s", r.DSLName()) os.Exit(1) } } t := reflect.TypeOf(r) if t.Kind() == reflect.Ptr { t = t.Elem() } dslPackages[t.PkgPath()] = true roots = append(roots, r) }
[ "func", "Register", "(", "r", "Root", ")", "{", "for", "_", ",", "o", ":=", "range", "roots", "{", "if", "r", ".", "DSLName", "(", ")", "==", "o", ".", "DSLName", "(", ")", "{", "fmt", ".", "Fprintf", "(", "os", ".", "Stderr", ",", "\"", "\"", ",", "r", ".", "DSLName", "(", ")", ")", "\n", "os", ".", "Exit", "(", "1", ")", "\n", "}", "\n", "}", "\n", "t", ":=", "reflect", ".", "TypeOf", "(", "r", ")", "\n", "if", "t", ".", "Kind", "(", ")", "==", "reflect", ".", "Ptr", "{", "t", "=", "t", ".", "Elem", "(", ")", "\n", "}", "\n", "dslPackages", "[", "t", ".", "PkgPath", "(", ")", "]", "=", "true", "\n", "roots", "=", "append", "(", "roots", ",", "r", ")", "\n", "}" ]
// Register adds a DSL Root to be executed by Run.
[ "Register", "adds", "a", "DSL", "Root", "to", "be", "executed", "by", "Run", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/dslengine/runner.go#L53-L66
166,604
goadesign/goa
dslengine/runner.go
ReportError
func ReportError(fm string, vals ...interface{}) { var suffix string if cur := ctxStack.Current(); cur != nil { if ctx := cur.Context(); ctx != "" { suffix = fmt.Sprintf(" in %s", ctx) } } else { suffix = " (top level)" } err := fmt.Errorf(fm+suffix, vals...) file, line := computeErrorLocation() Errors = append(Errors, &Error{ GoError: err, File: file, Line: line, }) }
go
func ReportError(fm string, vals ...interface{}) { var suffix string if cur := ctxStack.Current(); cur != nil { if ctx := cur.Context(); ctx != "" { suffix = fmt.Sprintf(" in %s", ctx) } } else { suffix = " (top level)" } err := fmt.Errorf(fm+suffix, vals...) file, line := computeErrorLocation() Errors = append(Errors, &Error{ GoError: err, File: file, Line: line, }) }
[ "func", "ReportError", "(", "fm", "string", ",", "vals", "...", "interface", "{", "}", ")", "{", "var", "suffix", "string", "\n", "if", "cur", ":=", "ctxStack", ".", "Current", "(", ")", ";", "cur", "!=", "nil", "{", "if", "ctx", ":=", "cur", ".", "Context", "(", ")", ";", "ctx", "!=", "\"", "\"", "{", "suffix", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "ctx", ")", "\n", "}", "\n", "}", "else", "{", "suffix", "=", "\"", "\"", "\n", "}", "\n", "err", ":=", "fmt", ".", "Errorf", "(", "fm", "+", "suffix", ",", "vals", "...", ")", "\n", "file", ",", "line", ":=", "computeErrorLocation", "(", ")", "\n", "Errors", "=", "append", "(", "Errors", ",", "&", "Error", "{", "GoError", ":", "err", ",", "File", ":", "file", ",", "Line", ":", "line", ",", "}", ")", "\n", "}" ]
// ReportError records a DSL error for reporting post DSL execution.
[ "ReportError", "records", "a", "DSL", "error", "for", "reporting", "post", "DSL", "execution", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/dslengine/runner.go#L163-L179
166,605
goadesign/goa
dslengine/runner.go
FailOnError
func FailOnError(err error) { if merr, ok := err.(MultiError); ok { if len(merr) == 0 { return } fmt.Fprintf(os.Stderr, merr.Error()) os.Exit(1) } if err != nil { fmt.Fprintf(os.Stderr, err.Error()) os.Exit(1) } }
go
func FailOnError(err error) { if merr, ok := err.(MultiError); ok { if len(merr) == 0 { return } fmt.Fprintf(os.Stderr, merr.Error()) os.Exit(1) } if err != nil { fmt.Fprintf(os.Stderr, err.Error()) os.Exit(1) } }
[ "func", "FailOnError", "(", "err", "error", ")", "{", "if", "merr", ",", "ok", ":=", "err", ".", "(", "MultiError", ")", ";", "ok", "{", "if", "len", "(", "merr", ")", "==", "0", "{", "return", "\n", "}", "\n", "fmt", ".", "Fprintf", "(", "os", ".", "Stderr", ",", "merr", ".", "Error", "(", ")", ")", "\n", "os", ".", "Exit", "(", "1", ")", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "fmt", ".", "Fprintf", "(", "os", ".", "Stderr", ",", "err", ".", "Error", "(", ")", ")", "\n", "os", ".", "Exit", "(", "1", ")", "\n", "}", "\n", "}" ]
// FailOnError will exit with code 1 if `err != nil`. This function // will handle properly the MultiError this dslengine provides.
[ "FailOnError", "will", "exit", "with", "code", "1", "if", "err", "!", "=", "nil", ".", "This", "function", "will", "handle", "properly", "the", "MultiError", "this", "dslengine", "provides", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/dslengine/runner.go#L183-L195
166,606
goadesign/goa
dslengine/runner.go
InvalidArgError
func InvalidArgError(expected string, actual interface{}) { ReportError("cannot use %#v (type %s) as type %s", actual, reflect.TypeOf(actual), expected) }
go
func InvalidArgError(expected string, actual interface{}) { ReportError("cannot use %#v (type %s) as type %s", actual, reflect.TypeOf(actual), expected) }
[ "func", "InvalidArgError", "(", "expected", "string", ",", "actual", "interface", "{", "}", ")", "{", "ReportError", "(", "\"", "\"", ",", "actual", ",", "reflect", ".", "TypeOf", "(", "actual", ")", ",", "expected", ")", "\n", "}" ]
// InvalidArgError records an invalid argument error. // It is used by DSL functions that take dynamic arguments.
[ "InvalidArgError", "records", "an", "invalid", "argument", "error", ".", "It", "is", "used", "by", "DSL", "functions", "that", "take", "dynamic", "arguments", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/dslengine/runner.go#L214-L217
166,607
goadesign/goa
dslengine/runner.go
Error
func (de *Error) Error() string { if err := de.GoError; err != nil { if de.File == "" { return err.Error() } return fmt.Sprintf("[%s:%d] %s", de.File, de.Line, err.Error()) } return "" }
go
func (de *Error) Error() string { if err := de.GoError; err != nil { if de.File == "" { return err.Error() } return fmt.Sprintf("[%s:%d] %s", de.File, de.Line, err.Error()) } return "" }
[ "func", "(", "de", "*", "Error", ")", "Error", "(", ")", "string", "{", "if", "err", ":=", "de", ".", "GoError", ";", "err", "!=", "nil", "{", "if", "de", ".", "File", "==", "\"", "\"", "{", "return", "err", ".", "Error", "(", ")", "\n", "}", "\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "de", ".", "File", ",", "de", ".", "Line", ",", "err", ".", "Error", "(", ")", ")", "\n", "}", "\n", "return", "\"", "\"", "\n", "}" ]
// Error returns the underlying error message.
[ "Error", "returns", "the", "underlying", "error", "message", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/dslengine/runner.go#L229-L237
166,608
goadesign/goa
dslengine/runner.go
Current
func (s contextStack) Current() Definition { if len(s) == 0 { return nil } return s[len(s)-1] }
go
func (s contextStack) Current() Definition { if len(s) == 0 { return nil } return s[len(s)-1] }
[ "func", "(", "s", "contextStack", ")", "Current", "(", ")", "Definition", "{", "if", "len", "(", "s", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n", "return", "s", "[", "len", "(", "s", ")", "-", "1", "]", "\n", "}" ]
// Current evaluation context, i.e. object being currently built by DSL
[ "Current", "evaluation", "context", "i", ".", "e", ".", "object", "being", "currently", "built", "by", "DSL" ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/dslengine/runner.go#L240-L245
166,609
goadesign/goa
dslengine/runner.go
runSet
func runSet(set DefinitionSet) error { executed := 0 recursed := 0 for executed < len(set) { recursed++ for _, def := range set[executed:] { executed++ if source, ok := def.(Source); ok { if dsl := source.DSL(); dsl != nil { Execute(dsl, source) } } } if recursed > 100 { return fmt.Errorf("too many generated definitions, infinite loop?") } } return nil }
go
func runSet(set DefinitionSet) error { executed := 0 recursed := 0 for executed < len(set) { recursed++ for _, def := range set[executed:] { executed++ if source, ok := def.(Source); ok { if dsl := source.DSL(); dsl != nil { Execute(dsl, source) } } } if recursed > 100 { return fmt.Errorf("too many generated definitions, infinite loop?") } } return nil }
[ "func", "runSet", "(", "set", "DefinitionSet", ")", "error", "{", "executed", ":=", "0", "\n", "recursed", ":=", "0", "\n", "for", "executed", "<", "len", "(", "set", ")", "{", "recursed", "++", "\n", "for", "_", ",", "def", ":=", "range", "set", "[", "executed", ":", "]", "{", "executed", "++", "\n", "if", "source", ",", "ok", ":=", "def", ".", "(", "Source", ")", ";", "ok", "{", "if", "dsl", ":=", "source", ".", "DSL", "(", ")", ";", "dsl", "!=", "nil", "{", "Execute", "(", "dsl", ",", "source", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "if", "recursed", ">", "100", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// runSet executes the DSL for all definitions in the given set. The definition DSLs may append to // the set as they execute.
[ "runSet", "executes", "the", "DSL", "for", "all", "definitions", "in", "the", "given", "set", ".", "The", "definition", "DSLs", "may", "append", "to", "the", "set", "as", "they", "execute", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/dslengine/runner.go#L289-L307
166,610
goadesign/goa
dslengine/runner.go
validateSet
func validateSet(set DefinitionSet) error { errors := &ValidationErrors{} for _, def := range set { if validate, ok := def.(Validate); ok { if err := validate.Validate(); err != nil { errors.AddError(def, err) } } } err := errors.AsError() if err != nil { Errors = append(Errors, &Error{GoError: err}) } return err }
go
func validateSet(set DefinitionSet) error { errors := &ValidationErrors{} for _, def := range set { if validate, ok := def.(Validate); ok { if err := validate.Validate(); err != nil { errors.AddError(def, err) } } } err := errors.AsError() if err != nil { Errors = append(Errors, &Error{GoError: err}) } return err }
[ "func", "validateSet", "(", "set", "DefinitionSet", ")", "error", "{", "errors", ":=", "&", "ValidationErrors", "{", "}", "\n", "for", "_", ",", "def", ":=", "range", "set", "{", "if", "validate", ",", "ok", ":=", "def", ".", "(", "Validate", ")", ";", "ok", "{", "if", "err", ":=", "validate", ".", "Validate", "(", ")", ";", "err", "!=", "nil", "{", "errors", ".", "AddError", "(", "def", ",", "err", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "err", ":=", "errors", ".", "AsError", "(", ")", "\n", "if", "err", "!=", "nil", "{", "Errors", "=", "append", "(", "Errors", ",", "&", "Error", "{", "GoError", ":", "err", "}", ")", "\n", "}", "\n", "return", "err", "\n", "}" ]
// validateSet runs the validation on all the set definitions that define one.
[ "validateSet", "runs", "the", "validation", "on", "all", "the", "set", "definitions", "that", "define", "one", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/dslengine/runner.go#L310-L324
166,611
goadesign/goa
dslengine/runner.go
finalizeSet
func finalizeSet(set DefinitionSet) error { for _, def := range set { if finalize, ok := def.(Finalize); ok { finalize.Finalize() } } return nil }
go
func finalizeSet(set DefinitionSet) error { for _, def := range set { if finalize, ok := def.(Finalize); ok { finalize.Finalize() } } return nil }
[ "func", "finalizeSet", "(", "set", "DefinitionSet", ")", "error", "{", "for", "_", ",", "def", ":=", "range", "set", "{", "if", "finalize", ",", "ok", ":=", "def", ".", "(", "Finalize", ")", ";", "ok", "{", "finalize", ".", "Finalize", "(", ")", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// finalizeSet runs the validation on all the set definitions that define one.
[ "finalizeSet", "runs", "the", "validation", "on", "all", "the", "set", "definitions", "that", "define", "one", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/dslengine/runner.go#L327-L334
166,612
goadesign/goa
dslengine/runner.go
SortRoots
func SortRoots() ([]Root, error) { if len(roots) == 0 { return nil, nil } // First flatten dependencies for each root rootDeps := make(map[string][]Root, len(roots)) rootByName := make(map[string]Root, len(roots)) for _, r := range roots { sorted := sortDependencies(r, func(r Root) []Root { return r.DependsOn() }) length := len(sorted) for i := 0; i < length/2; i++ { sorted[i], sorted[length-i-1] = sorted[length-i-1], sorted[i] } rootDeps[r.DSLName()] = sorted rootByName[r.DSLName()] = r } // Now check for cycles for name, deps := range rootDeps { root := rootByName[name] for otherName, otherdeps := range rootDeps { other := rootByName[otherName] if root.DSLName() == other.DSLName() { continue } dependsOnOther := false for _, dep := range deps { if dep.DSLName() == other.DSLName() { dependsOnOther = true break } } if dependsOnOther { for _, dep := range otherdeps { if dep.DSLName() == root.DSLName() { return nil, fmt.Errorf("dependency cycle: %s and %s depend on each other (directly or not)", root.DSLName(), other.DSLName()) } } } } } // Now sort top level DSLs var sorted []Root for _, r := range roots { s := sortDependencies(r, func(r Root) []Root { return rootDeps[r.DSLName()] }) for _, s := range s { found := false for _, r := range sorted { if r.DSLName() == s.DSLName() { found = true break } } if !found { sorted = append(sorted, s) } } } return sorted, nil }
go
func SortRoots() ([]Root, error) { if len(roots) == 0 { return nil, nil } // First flatten dependencies for each root rootDeps := make(map[string][]Root, len(roots)) rootByName := make(map[string]Root, len(roots)) for _, r := range roots { sorted := sortDependencies(r, func(r Root) []Root { return r.DependsOn() }) length := len(sorted) for i := 0; i < length/2; i++ { sorted[i], sorted[length-i-1] = sorted[length-i-1], sorted[i] } rootDeps[r.DSLName()] = sorted rootByName[r.DSLName()] = r } // Now check for cycles for name, deps := range rootDeps { root := rootByName[name] for otherName, otherdeps := range rootDeps { other := rootByName[otherName] if root.DSLName() == other.DSLName() { continue } dependsOnOther := false for _, dep := range deps { if dep.DSLName() == other.DSLName() { dependsOnOther = true break } } if dependsOnOther { for _, dep := range otherdeps { if dep.DSLName() == root.DSLName() { return nil, fmt.Errorf("dependency cycle: %s and %s depend on each other (directly or not)", root.DSLName(), other.DSLName()) } } } } } // Now sort top level DSLs var sorted []Root for _, r := range roots { s := sortDependencies(r, func(r Root) []Root { return rootDeps[r.DSLName()] }) for _, s := range s { found := false for _, r := range sorted { if r.DSLName() == s.DSLName() { found = true break } } if !found { sorted = append(sorted, s) } } } return sorted, nil }
[ "func", "SortRoots", "(", ")", "(", "[", "]", "Root", ",", "error", ")", "{", "if", "len", "(", "roots", ")", "==", "0", "{", "return", "nil", ",", "nil", "\n", "}", "\n", "// First flatten dependencies for each root", "rootDeps", ":=", "make", "(", "map", "[", "string", "]", "[", "]", "Root", ",", "len", "(", "roots", ")", ")", "\n", "rootByName", ":=", "make", "(", "map", "[", "string", "]", "Root", ",", "len", "(", "roots", ")", ")", "\n", "for", "_", ",", "r", ":=", "range", "roots", "{", "sorted", ":=", "sortDependencies", "(", "r", ",", "func", "(", "r", "Root", ")", "[", "]", "Root", "{", "return", "r", ".", "DependsOn", "(", ")", "}", ")", "\n", "length", ":=", "len", "(", "sorted", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "length", "/", "2", ";", "i", "++", "{", "sorted", "[", "i", "]", ",", "sorted", "[", "length", "-", "i", "-", "1", "]", "=", "sorted", "[", "length", "-", "i", "-", "1", "]", ",", "sorted", "[", "i", "]", "\n", "}", "\n", "rootDeps", "[", "r", ".", "DSLName", "(", ")", "]", "=", "sorted", "\n", "rootByName", "[", "r", ".", "DSLName", "(", ")", "]", "=", "r", "\n", "}", "\n", "// Now check for cycles", "for", "name", ",", "deps", ":=", "range", "rootDeps", "{", "root", ":=", "rootByName", "[", "name", "]", "\n", "for", "otherName", ",", "otherdeps", ":=", "range", "rootDeps", "{", "other", ":=", "rootByName", "[", "otherName", "]", "\n", "if", "root", ".", "DSLName", "(", ")", "==", "other", ".", "DSLName", "(", ")", "{", "continue", "\n", "}", "\n", "dependsOnOther", ":=", "false", "\n", "for", "_", ",", "dep", ":=", "range", "deps", "{", "if", "dep", ".", "DSLName", "(", ")", "==", "other", ".", "DSLName", "(", ")", "{", "dependsOnOther", "=", "true", "\n", "break", "\n", "}", "\n", "}", "\n", "if", "dependsOnOther", "{", "for", "_", ",", "dep", ":=", "range", "otherdeps", "{", "if", "dep", ".", "DSLName", "(", ")", "==", "root", ".", "DSLName", "(", ")", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "root", ".", "DSLName", "(", ")", ",", "other", ".", "DSLName", "(", ")", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "// Now sort top level DSLs", "var", "sorted", "[", "]", "Root", "\n", "for", "_", ",", "r", ":=", "range", "roots", "{", "s", ":=", "sortDependencies", "(", "r", ",", "func", "(", "r", "Root", ")", "[", "]", "Root", "{", "return", "rootDeps", "[", "r", ".", "DSLName", "(", ")", "]", "}", ")", "\n", "for", "_", ",", "s", ":=", "range", "s", "{", "found", ":=", "false", "\n", "for", "_", ",", "r", ":=", "range", "sorted", "{", "if", "r", ".", "DSLName", "(", ")", "==", "s", ".", "DSLName", "(", ")", "{", "found", "=", "true", "\n", "break", "\n", "}", "\n", "}", "\n", "if", "!", "found", "{", "sorted", "=", "append", "(", "sorted", ",", "s", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "sorted", ",", "nil", "\n", "}" ]
// SortRoots orders the DSL roots making sure dependencies are last. It returns an error if there // is a dependency cycle.
[ "SortRoots", "orders", "the", "DSL", "roots", "making", "sure", "dependencies", "are", "last", ".", "It", "returns", "an", "error", "if", "there", "is", "a", "dependency", "cycle", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/dslengine/runner.go#L338-L397
166,613
goadesign/goa
dslengine/runner.go
sortDependencies
func sortDependencies(root Root, depFunc func(Root) []Root) []Root { seen := make(map[string]bool, len(roots)) var sorted []Root sortDependenciesR(root, seen, &sorted, depFunc) return sorted }
go
func sortDependencies(root Root, depFunc func(Root) []Root) []Root { seen := make(map[string]bool, len(roots)) var sorted []Root sortDependenciesR(root, seen, &sorted, depFunc) return sorted }
[ "func", "sortDependencies", "(", "root", "Root", ",", "depFunc", "func", "(", "Root", ")", "[", "]", "Root", ")", "[", "]", "Root", "{", "seen", ":=", "make", "(", "map", "[", "string", "]", "bool", ",", "len", "(", "roots", ")", ")", "\n", "var", "sorted", "[", "]", "Root", "\n", "sortDependenciesR", "(", "root", ",", "seen", ",", "&", "sorted", ",", "depFunc", ")", "\n", "return", "sorted", "\n", "}" ]
// sortDependencies sorts the depencies of the given root in the given slice.
[ "sortDependencies", "sorts", "the", "depencies", "of", "the", "given", "root", "in", "the", "given", "slice", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/dslengine/runner.go#L400-L405
166,614
goadesign/goa
dslengine/runner.go
sortDependenciesR
func sortDependenciesR(root Root, seen map[string]bool, sorted *[]Root, depFunc func(Root) []Root) { for _, dep := range depFunc(root) { if !seen[dep.DSLName()] { seen[root.DSLName()] = true sortDependenciesR(dep, seen, sorted, depFunc) } } *sorted = append(*sorted, root) }
go
func sortDependenciesR(root Root, seen map[string]bool, sorted *[]Root, depFunc func(Root) []Root) { for _, dep := range depFunc(root) { if !seen[dep.DSLName()] { seen[root.DSLName()] = true sortDependenciesR(dep, seen, sorted, depFunc) } } *sorted = append(*sorted, root) }
[ "func", "sortDependenciesR", "(", "root", "Root", ",", "seen", "map", "[", "string", "]", "bool", ",", "sorted", "*", "[", "]", "Root", ",", "depFunc", "func", "(", "Root", ")", "[", "]", "Root", ")", "{", "for", "_", ",", "dep", ":=", "range", "depFunc", "(", "root", ")", "{", "if", "!", "seen", "[", "dep", ".", "DSLName", "(", ")", "]", "{", "seen", "[", "root", ".", "DSLName", "(", ")", "]", "=", "true", "\n", "sortDependenciesR", "(", "dep", ",", "seen", ",", "sorted", ",", "depFunc", ")", "\n", "}", "\n", "}", "\n", "*", "sorted", "=", "append", "(", "*", "sorted", ",", "root", ")", "\n", "}" ]
// sortDependenciesR sorts the depencies of the given root in the given slice.
[ "sortDependenciesR", "sorts", "the", "depencies", "of", "the", "given", "root", "in", "the", "given", "slice", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/dslengine/runner.go#L408-L416
166,615
goadesign/goa
dslengine/runner.go
caller
func caller() string { pc, file, _, ok := runtime.Caller(2) if ok && filepath.Base(file) == "current.go" { pc, _, _, ok = runtime.Caller(3) } if !ok { return "<unknown>" } return runtime.FuncForPC(pc).Name() }
go
func caller() string { pc, file, _, ok := runtime.Caller(2) if ok && filepath.Base(file) == "current.go" { pc, _, _, ok = runtime.Caller(3) } if !ok { return "<unknown>" } return runtime.FuncForPC(pc).Name() }
[ "func", "caller", "(", ")", "string", "{", "pc", ",", "file", ",", "_", ",", "ok", ":=", "runtime", ".", "Caller", "(", "2", ")", "\n", "if", "ok", "&&", "filepath", ".", "Base", "(", "file", ")", "==", "\"", "\"", "{", "pc", ",", "_", ",", "_", ",", "ok", "=", "runtime", ".", "Caller", "(", "3", ")", "\n", "}", "\n", "if", "!", "ok", "{", "return", "\"", "\"", "\n", "}", "\n\n", "return", "runtime", ".", "FuncForPC", "(", "pc", ")", ".", "Name", "(", ")", "\n", "}" ]
// caller returns the name of calling function.
[ "caller", "returns", "the", "name", "of", "calling", "function", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/dslengine/runner.go#L419-L429
166,616
goadesign/goa
dslengine/definitions.go
Merge
func (v *ValidationDefinition) Merge(other *ValidationDefinition) { if v.Values == nil { v.Values = other.Values } if v.Format == "" { v.Format = other.Format } if v.Pattern == "" { v.Pattern = other.Pattern } if v.Minimum == nil || (other.Minimum != nil && *v.Minimum > *other.Minimum) { v.Minimum = other.Minimum } if v.Maximum == nil || (other.Maximum != nil && *v.Maximum < *other.Maximum) { v.Maximum = other.Maximum } if v.MinLength == nil || (other.MinLength != nil && *v.MinLength > *other.MinLength) { v.MinLength = other.MinLength } if v.MaxLength == nil || (other.MaxLength != nil && *v.MaxLength < *other.MaxLength) { v.MaxLength = other.MaxLength } v.AddRequired(other.Required) }
go
func (v *ValidationDefinition) Merge(other *ValidationDefinition) { if v.Values == nil { v.Values = other.Values } if v.Format == "" { v.Format = other.Format } if v.Pattern == "" { v.Pattern = other.Pattern } if v.Minimum == nil || (other.Minimum != nil && *v.Minimum > *other.Minimum) { v.Minimum = other.Minimum } if v.Maximum == nil || (other.Maximum != nil && *v.Maximum < *other.Maximum) { v.Maximum = other.Maximum } if v.MinLength == nil || (other.MinLength != nil && *v.MinLength > *other.MinLength) { v.MinLength = other.MinLength } if v.MaxLength == nil || (other.MaxLength != nil && *v.MaxLength < *other.MaxLength) { v.MaxLength = other.MaxLength } v.AddRequired(other.Required) }
[ "func", "(", "v", "*", "ValidationDefinition", ")", "Merge", "(", "other", "*", "ValidationDefinition", ")", "{", "if", "v", ".", "Values", "==", "nil", "{", "v", ".", "Values", "=", "other", ".", "Values", "\n", "}", "\n", "if", "v", ".", "Format", "==", "\"", "\"", "{", "v", ".", "Format", "=", "other", ".", "Format", "\n", "}", "\n", "if", "v", ".", "Pattern", "==", "\"", "\"", "{", "v", ".", "Pattern", "=", "other", ".", "Pattern", "\n", "}", "\n", "if", "v", ".", "Minimum", "==", "nil", "||", "(", "other", ".", "Minimum", "!=", "nil", "&&", "*", "v", ".", "Minimum", ">", "*", "other", ".", "Minimum", ")", "{", "v", ".", "Minimum", "=", "other", ".", "Minimum", "\n", "}", "\n", "if", "v", ".", "Maximum", "==", "nil", "||", "(", "other", ".", "Maximum", "!=", "nil", "&&", "*", "v", ".", "Maximum", "<", "*", "other", ".", "Maximum", ")", "{", "v", ".", "Maximum", "=", "other", ".", "Maximum", "\n", "}", "\n", "if", "v", ".", "MinLength", "==", "nil", "||", "(", "other", ".", "MinLength", "!=", "nil", "&&", "*", "v", ".", "MinLength", ">", "*", "other", ".", "MinLength", ")", "{", "v", ".", "MinLength", "=", "other", ".", "MinLength", "\n", "}", "\n", "if", "v", ".", "MaxLength", "==", "nil", "||", "(", "other", ".", "MaxLength", "!=", "nil", "&&", "*", "v", ".", "MaxLength", "<", "*", "other", ".", "MaxLength", ")", "{", "v", ".", "MaxLength", "=", "other", ".", "MaxLength", "\n", "}", "\n", "v", ".", "AddRequired", "(", "other", ".", "Required", ")", "\n", "}" ]
// Merge merges other into v.
[ "Merge", "merges", "other", "into", "v", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/dslengine/definitions.go#L128-L151
166,617
goadesign/goa
dslengine/definitions.go
AddRequired
func (v *ValidationDefinition) AddRequired(required []string) { for _, r := range required { found := false for _, rr := range v.Required { if r == rr { found = true break } } if !found { v.Required = append(v.Required, r) } } }
go
func (v *ValidationDefinition) AddRequired(required []string) { for _, r := range required { found := false for _, rr := range v.Required { if r == rr { found = true break } } if !found { v.Required = append(v.Required, r) } } }
[ "func", "(", "v", "*", "ValidationDefinition", ")", "AddRequired", "(", "required", "[", "]", "string", ")", "{", "for", "_", ",", "r", ":=", "range", "required", "{", "found", ":=", "false", "\n", "for", "_", ",", "rr", ":=", "range", "v", ".", "Required", "{", "if", "r", "==", "rr", "{", "found", "=", "true", "\n", "break", "\n", "}", "\n", "}", "\n", "if", "!", "found", "{", "v", ".", "Required", "=", "append", "(", "v", ".", "Required", ",", "r", ")", "\n", "}", "\n", "}", "\n", "}" ]
// AddRequired merges the required fields from other into v
[ "AddRequired", "merges", "the", "required", "fields", "from", "other", "into", "v" ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/dslengine/definitions.go#L154-L167
166,618
goadesign/goa
dslengine/definitions.go
HasRequiredOnly
func (v *ValidationDefinition) HasRequiredOnly() bool { if len(v.Values) > 0 { return false } if v.Format != "" || v.Pattern != "" { return false } if (v.Minimum != nil) || (v.Maximum != nil) || (v.MaxLength != nil) { return false } return true }
go
func (v *ValidationDefinition) HasRequiredOnly() bool { if len(v.Values) > 0 { return false } if v.Format != "" || v.Pattern != "" { return false } if (v.Minimum != nil) || (v.Maximum != nil) || (v.MaxLength != nil) { return false } return true }
[ "func", "(", "v", "*", "ValidationDefinition", ")", "HasRequiredOnly", "(", ")", "bool", "{", "if", "len", "(", "v", ".", "Values", ")", ">", "0", "{", "return", "false", "\n", "}", "\n", "if", "v", ".", "Format", "!=", "\"", "\"", "||", "v", ".", "Pattern", "!=", "\"", "\"", "{", "return", "false", "\n", "}", "\n", "if", "(", "v", ".", "Minimum", "!=", "nil", ")", "||", "(", "v", ".", "Maximum", "!=", "nil", ")", "||", "(", "v", ".", "MaxLength", "!=", "nil", ")", "{", "return", "false", "\n", "}", "\n", "return", "true", "\n", "}" ]
// HasRequiredOnly returns true if the validation only has the Required field with a non-zero value.
[ "HasRequiredOnly", "returns", "true", "if", "the", "validation", "only", "has", "the", "Required", "field", "with", "a", "non", "-", "zero", "value", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/dslengine/definitions.go#L170-L181
166,619
goadesign/goa
dslengine/definitions.go
Dup
func (v *ValidationDefinition) Dup() *ValidationDefinition { return &ValidationDefinition{ Values: v.Values, Format: v.Format, Pattern: v.Pattern, Minimum: v.Minimum, Maximum: v.Maximum, MinLength: v.MinLength, MaxLength: v.MaxLength, Required: v.Required, } }
go
func (v *ValidationDefinition) Dup() *ValidationDefinition { return &ValidationDefinition{ Values: v.Values, Format: v.Format, Pattern: v.Pattern, Minimum: v.Minimum, Maximum: v.Maximum, MinLength: v.MinLength, MaxLength: v.MaxLength, Required: v.Required, } }
[ "func", "(", "v", "*", "ValidationDefinition", ")", "Dup", "(", ")", "*", "ValidationDefinition", "{", "return", "&", "ValidationDefinition", "{", "Values", ":", "v", ".", "Values", ",", "Format", ":", "v", ".", "Format", ",", "Pattern", ":", "v", ".", "Pattern", ",", "Minimum", ":", "v", ".", "Minimum", ",", "Maximum", ":", "v", ".", "Maximum", ",", "MinLength", ":", "v", ".", "MinLength", ",", "MaxLength", ":", "v", ".", "MaxLength", ",", "Required", ":", "v", ".", "Required", ",", "}", "\n", "}" ]
// Dup makes a shallow dup of the validation.
[ "Dup", "makes", "a", "shallow", "dup", "of", "the", "validation", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/dslengine/definitions.go#L184-L195
166,620
goadesign/goa
error.go
NewErrorClass
func NewErrorClass(code string, status int) ErrorClass { return func(message interface{}, keyvals ...interface{}) error { var msg string switch actual := message.(type) { case string: msg = actual case error: msg = actual.Error() case fmt.Stringer: msg = actual.String() default: msg = fmt.Sprintf("%v", actual) } var meta map[string]interface{} l := len(keyvals) if l > 0 { meta = make(map[string]interface{}) } for i := 0; i < l; i += 2 { k := keyvals[i] var v interface{} = "MISSING" if i+1 < l { v = keyvals[i+1] } meta[fmt.Sprintf("%v", k)] = v } return &ErrorResponse{ID: newErrorID(), Code: code, Status: status, Detail: msg, Meta: meta} } }
go
func NewErrorClass(code string, status int) ErrorClass { return func(message interface{}, keyvals ...interface{}) error { var msg string switch actual := message.(type) { case string: msg = actual case error: msg = actual.Error() case fmt.Stringer: msg = actual.String() default: msg = fmt.Sprintf("%v", actual) } var meta map[string]interface{} l := len(keyvals) if l > 0 { meta = make(map[string]interface{}) } for i := 0; i < l; i += 2 { k := keyvals[i] var v interface{} = "MISSING" if i+1 < l { v = keyvals[i+1] } meta[fmt.Sprintf("%v", k)] = v } return &ErrorResponse{ID: newErrorID(), Code: code, Status: status, Detail: msg, Meta: meta} } }
[ "func", "NewErrorClass", "(", "code", "string", ",", "status", "int", ")", "ErrorClass", "{", "return", "func", "(", "message", "interface", "{", "}", ",", "keyvals", "...", "interface", "{", "}", ")", "error", "{", "var", "msg", "string", "\n", "switch", "actual", ":=", "message", ".", "(", "type", ")", "{", "case", "string", ":", "msg", "=", "actual", "\n", "case", "error", ":", "msg", "=", "actual", ".", "Error", "(", ")", "\n", "case", "fmt", ".", "Stringer", ":", "msg", "=", "actual", ".", "String", "(", ")", "\n", "default", ":", "msg", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "actual", ")", "\n", "}", "\n", "var", "meta", "map", "[", "string", "]", "interface", "{", "}", "\n", "l", ":=", "len", "(", "keyvals", ")", "\n", "if", "l", ">", "0", "{", "meta", "=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "}", "\n", "for", "i", ":=", "0", ";", "i", "<", "l", ";", "i", "+=", "2", "{", "k", ":=", "keyvals", "[", "i", "]", "\n", "var", "v", "interface", "{", "}", "=", "\"", "\"", "\n", "if", "i", "+", "1", "<", "l", "{", "v", "=", "keyvals", "[", "i", "+", "1", "]", "\n", "}", "\n", "meta", "[", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "k", ")", "]", "=", "v", "\n", "}", "\n", "return", "&", "ErrorResponse", "{", "ID", ":", "newErrorID", "(", ")", ",", "Code", ":", "code", ",", "Status", ":", "status", ",", "Detail", ":", "msg", ",", "Meta", ":", "meta", "}", "\n", "}", "\n", "}" ]
// NewErrorClass creates a new error class. // It is the responsibility of the client to guarantee uniqueness of code.
[ "NewErrorClass", "creates", "a", "new", "error", "class", ".", "It", "is", "the", "responsibility", "of", "the", "client", "to", "guarantee", "uniqueness", "of", "code", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/error.go#L130-L158
166,621
goadesign/goa
error.go
InvalidParamTypeError
func InvalidParamTypeError(name string, val interface{}, expected string) error { msg := fmt.Sprintf("invalid value %#v for parameter %#v, must be a %s", val, name, expected) return ErrInvalidRequest(msg, "param", name, "value", val, "expected", expected) }
go
func InvalidParamTypeError(name string, val interface{}, expected string) error { msg := fmt.Sprintf("invalid value %#v for parameter %#v, must be a %s", val, name, expected) return ErrInvalidRequest(msg, "param", name, "value", val, "expected", expected) }
[ "func", "InvalidParamTypeError", "(", "name", "string", ",", "val", "interface", "{", "}", ",", "expected", "string", ")", "error", "{", "msg", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "val", ",", "name", ",", "expected", ")", "\n", "return", "ErrInvalidRequest", "(", "msg", ",", "\"", "\"", ",", "name", ",", "\"", "\"", ",", "val", ",", "\"", "\"", ",", "expected", ")", "\n", "}" ]
// InvalidParamTypeError is the error produced when the type of a parameter does not match the type // defined in the design.
[ "InvalidParamTypeError", "is", "the", "error", "produced", "when", "the", "type", "of", "a", "parameter", "does", "not", "match", "the", "type", "defined", "in", "the", "design", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/error.go#L167-L170
166,622
goadesign/goa
error.go
MissingParamError
func MissingParamError(name string) error { msg := fmt.Sprintf("missing required parameter %#v", name) return ErrInvalidRequest(msg, "name", name) }
go
func MissingParamError(name string) error { msg := fmt.Sprintf("missing required parameter %#v", name) return ErrInvalidRequest(msg, "name", name) }
[ "func", "MissingParamError", "(", "name", "string", ")", "error", "{", "msg", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "name", ")", "\n", "return", "ErrInvalidRequest", "(", "msg", ",", "\"", "\"", ",", "name", ")", "\n", "}" ]
// MissingParamError is the error produced for requests that are missing path or querystring // parameters.
[ "MissingParamError", "is", "the", "error", "produced", "for", "requests", "that", "are", "missing", "path", "or", "querystring", "parameters", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/error.go#L174-L177
166,623
goadesign/goa
error.go
InvalidAttributeTypeError
func InvalidAttributeTypeError(ctx string, val interface{}, expected string) error { msg := fmt.Sprintf("type of %s must be %s but got value %#v", ctx, expected, val) return ErrInvalidRequest(msg, "attribute", ctx, "value", val, "expected", expected) }
go
func InvalidAttributeTypeError(ctx string, val interface{}, expected string) error { msg := fmt.Sprintf("type of %s must be %s but got value %#v", ctx, expected, val) return ErrInvalidRequest(msg, "attribute", ctx, "value", val, "expected", expected) }
[ "func", "InvalidAttributeTypeError", "(", "ctx", "string", ",", "val", "interface", "{", "}", ",", "expected", "string", ")", "error", "{", "msg", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "ctx", ",", "expected", ",", "val", ")", "\n", "return", "ErrInvalidRequest", "(", "msg", ",", "\"", "\"", ",", "ctx", ",", "\"", "\"", ",", "val", ",", "\"", "\"", ",", "expected", ")", "\n", "}" ]
// InvalidAttributeTypeError is the error produced when the type of payload field does not match // the type defined in the design.
[ "InvalidAttributeTypeError", "is", "the", "error", "produced", "when", "the", "type", "of", "payload", "field", "does", "not", "match", "the", "type", "defined", "in", "the", "design", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/error.go#L181-L184
166,624
goadesign/goa
error.go
MissingAttributeError
func MissingAttributeError(ctx, name string) error { msg := fmt.Sprintf("attribute %#v of %s is missing and required", name, ctx) return ErrInvalidRequest(msg, "attribute", name, "parent", ctx) }
go
func MissingAttributeError(ctx, name string) error { msg := fmt.Sprintf("attribute %#v of %s is missing and required", name, ctx) return ErrInvalidRequest(msg, "attribute", name, "parent", ctx) }
[ "func", "MissingAttributeError", "(", "ctx", ",", "name", "string", ")", "error", "{", "msg", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "name", ",", "ctx", ")", "\n", "return", "ErrInvalidRequest", "(", "msg", ",", "\"", "\"", ",", "name", ",", "\"", "\"", ",", "ctx", ")", "\n", "}" ]
// MissingAttributeError is the error produced when a request payload is missing a required field.
[ "MissingAttributeError", "is", "the", "error", "produced", "when", "a", "request", "payload", "is", "missing", "a", "required", "field", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/error.go#L187-L190
166,625
goadesign/goa
error.go
MissingHeaderError
func MissingHeaderError(name string) error { msg := fmt.Sprintf("missing required HTTP header %#v", name) return ErrInvalidRequest(msg, "name", name) }
go
func MissingHeaderError(name string) error { msg := fmt.Sprintf("missing required HTTP header %#v", name) return ErrInvalidRequest(msg, "name", name) }
[ "func", "MissingHeaderError", "(", "name", "string", ")", "error", "{", "msg", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "name", ")", "\n", "return", "ErrInvalidRequest", "(", "msg", ",", "\"", "\"", ",", "name", ")", "\n", "}" ]
// MissingHeaderError is the error produced when a request is missing a required header.
[ "MissingHeaderError", "is", "the", "error", "produced", "when", "a", "request", "is", "missing", "a", "required", "header", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/error.go#L193-L196
166,626
goadesign/goa
error.go
InvalidEnumValueError
func InvalidEnumValueError(ctx string, val interface{}, allowed []interface{}) error { elems := make([]string, len(allowed)) for i, a := range allowed { elems[i] = fmt.Sprintf("%#v", a) } msg := fmt.Sprintf("value of %s must be one of %s but got value %#v", ctx, strings.Join(elems, ", "), val) return ErrInvalidRequest(msg, "attribute", ctx, "value", val, "expected", strings.Join(elems, ", ")) }
go
func InvalidEnumValueError(ctx string, val interface{}, allowed []interface{}) error { elems := make([]string, len(allowed)) for i, a := range allowed { elems[i] = fmt.Sprintf("%#v", a) } msg := fmt.Sprintf("value of %s must be one of %s but got value %#v", ctx, strings.Join(elems, ", "), val) return ErrInvalidRequest(msg, "attribute", ctx, "value", val, "expected", strings.Join(elems, ", ")) }
[ "func", "InvalidEnumValueError", "(", "ctx", "string", ",", "val", "interface", "{", "}", ",", "allowed", "[", "]", "interface", "{", "}", ")", "error", "{", "elems", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "allowed", ")", ")", "\n", "for", "i", ",", "a", ":=", "range", "allowed", "{", "elems", "[", "i", "]", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "a", ")", "\n", "}", "\n", "msg", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "ctx", ",", "strings", ".", "Join", "(", "elems", ",", "\"", "\"", ")", ",", "val", ")", "\n", "return", "ErrInvalidRequest", "(", "msg", ",", "\"", "\"", ",", "ctx", ",", "\"", "\"", ",", "val", ",", "\"", "\"", ",", "strings", ".", "Join", "(", "elems", ",", "\"", "\"", ")", ")", "\n", "}" ]
// InvalidEnumValueError is the error produced when the value of a parameter or payload field does // not match one the values defined in the design Enum validation.
[ "InvalidEnumValueError", "is", "the", "error", "produced", "when", "the", "value", "of", "a", "parameter", "or", "payload", "field", "does", "not", "match", "one", "the", "values", "defined", "in", "the", "design", "Enum", "validation", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/error.go#L200-L207
166,627
goadesign/goa
error.go
InvalidFormatError
func InvalidFormatError(ctx, target string, format Format, formatError error) error { msg := fmt.Sprintf("%s must be formatted as a %s but got value %#v, %s", ctx, format, target, formatError.Error()) return ErrInvalidRequest(msg, "attribute", ctx, "value", target, "expected", format, "error", formatError.Error()) }
go
func InvalidFormatError(ctx, target string, format Format, formatError error) error { msg := fmt.Sprintf("%s must be formatted as a %s but got value %#v, %s", ctx, format, target, formatError.Error()) return ErrInvalidRequest(msg, "attribute", ctx, "value", target, "expected", format, "error", formatError.Error()) }
[ "func", "InvalidFormatError", "(", "ctx", ",", "target", "string", ",", "format", "Format", ",", "formatError", "error", ")", "error", "{", "msg", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "ctx", ",", "format", ",", "target", ",", "formatError", ".", "Error", "(", ")", ")", "\n", "return", "ErrInvalidRequest", "(", "msg", ",", "\"", "\"", ",", "ctx", ",", "\"", "\"", ",", "target", ",", "\"", "\"", ",", "format", ",", "\"", "\"", ",", "formatError", ".", "Error", "(", ")", ")", "\n", "}" ]
// InvalidFormatError is the error produced when the value of a parameter or payload field does not // match the format validation defined in the design.
[ "InvalidFormatError", "is", "the", "error", "produced", "when", "the", "value", "of", "a", "parameter", "or", "payload", "field", "does", "not", "match", "the", "format", "validation", "defined", "in", "the", "design", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/error.go#L211-L214
166,628
goadesign/goa
error.go
InvalidPatternError
func InvalidPatternError(ctx, target string, pattern string) error { msg := fmt.Sprintf("%s must match the regexp %#v but got value %#v", ctx, pattern, target) return ErrInvalidRequest(msg, "attribute", ctx, "value", target, "regexp", pattern) }
go
func InvalidPatternError(ctx, target string, pattern string) error { msg := fmt.Sprintf("%s must match the regexp %#v but got value %#v", ctx, pattern, target) return ErrInvalidRequest(msg, "attribute", ctx, "value", target, "regexp", pattern) }
[ "func", "InvalidPatternError", "(", "ctx", ",", "target", "string", ",", "pattern", "string", ")", "error", "{", "msg", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "ctx", ",", "pattern", ",", "target", ")", "\n", "return", "ErrInvalidRequest", "(", "msg", ",", "\"", "\"", ",", "ctx", ",", "\"", "\"", ",", "target", ",", "\"", "\"", ",", "pattern", ")", "\n", "}" ]
// InvalidPatternError is the error produced when the value of a parameter or payload field does // not match the pattern validation defined in the design.
[ "InvalidPatternError", "is", "the", "error", "produced", "when", "the", "value", "of", "a", "parameter", "or", "payload", "field", "does", "not", "match", "the", "pattern", "validation", "defined", "in", "the", "design", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/error.go#L218-L221
166,629
goadesign/goa
error.go
InvalidRangeError
func InvalidRangeError(ctx string, target interface{}, value interface{}, min bool) error { comp := "greater than or equal to" if !min { comp = "less than or equal to" } msg := fmt.Sprintf("%s must be %s %v but got value %#v", ctx, comp, value, target) return ErrInvalidRequest(msg, "attribute", ctx, "value", target, "comp", comp, "expected", value) }
go
func InvalidRangeError(ctx string, target interface{}, value interface{}, min bool) error { comp := "greater than or equal to" if !min { comp = "less than or equal to" } msg := fmt.Sprintf("%s must be %s %v but got value %#v", ctx, comp, value, target) return ErrInvalidRequest(msg, "attribute", ctx, "value", target, "comp", comp, "expected", value) }
[ "func", "InvalidRangeError", "(", "ctx", "string", ",", "target", "interface", "{", "}", ",", "value", "interface", "{", "}", ",", "min", "bool", ")", "error", "{", "comp", ":=", "\"", "\"", "\n", "if", "!", "min", "{", "comp", "=", "\"", "\"", "\n", "}", "\n", "msg", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "ctx", ",", "comp", ",", "value", ",", "target", ")", "\n", "return", "ErrInvalidRequest", "(", "msg", ",", "\"", "\"", ",", "ctx", ",", "\"", "\"", ",", "target", ",", "\"", "\"", ",", "comp", ",", "\"", "\"", ",", "value", ")", "\n", "}" ]
// InvalidRangeError is the error produced when the value of a parameter or payload field does // not match the range validation defined in the design. value may be a int or a float64.
[ "InvalidRangeError", "is", "the", "error", "produced", "when", "the", "value", "of", "a", "parameter", "or", "payload", "field", "does", "not", "match", "the", "range", "validation", "defined", "in", "the", "design", ".", "value", "may", "be", "a", "int", "or", "a", "float64", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/error.go#L225-L232
166,630
goadesign/goa
error.go
InvalidLengthError
func InvalidLengthError(ctx string, target interface{}, ln, value int, min bool) error { comp := "greater than or equal to" if !min { comp = "less than or equal to" } msg := fmt.Sprintf("length of %s must be %s %d but got value %#v (len=%d)", ctx, comp, value, target, ln) return ErrInvalidRequest(msg, "attribute", ctx, "value", target, "len", ln, "comp", comp, "expected", value) }
go
func InvalidLengthError(ctx string, target interface{}, ln, value int, min bool) error { comp := "greater than or equal to" if !min { comp = "less than or equal to" } msg := fmt.Sprintf("length of %s must be %s %d but got value %#v (len=%d)", ctx, comp, value, target, ln) return ErrInvalidRequest(msg, "attribute", ctx, "value", target, "len", ln, "comp", comp, "expected", value) }
[ "func", "InvalidLengthError", "(", "ctx", "string", ",", "target", "interface", "{", "}", ",", "ln", ",", "value", "int", ",", "min", "bool", ")", "error", "{", "comp", ":=", "\"", "\"", "\n", "if", "!", "min", "{", "comp", "=", "\"", "\"", "\n", "}", "\n", "msg", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "ctx", ",", "comp", ",", "value", ",", "target", ",", "ln", ")", "\n", "return", "ErrInvalidRequest", "(", "msg", ",", "\"", "\"", ",", "ctx", ",", "\"", "\"", ",", "target", ",", "\"", "\"", ",", "ln", ",", "\"", "\"", ",", "comp", ",", "\"", "\"", ",", "value", ")", "\n", "}" ]
// InvalidLengthError is the error produced when the value of a parameter or payload field does // not match the length validation defined in the design.
[ "InvalidLengthError", "is", "the", "error", "produced", "when", "the", "value", "of", "a", "parameter", "or", "payload", "field", "does", "not", "match", "the", "length", "validation", "defined", "in", "the", "design", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/error.go#L236-L243
166,631
goadesign/goa
error.go
NoAuthMiddleware
func NoAuthMiddleware(schemeName string) error { msg := fmt.Sprintf("Auth middleware for security scheme %s is not mounted", schemeName) return ErrNoAuthMiddleware(msg, "scheme", schemeName) }
go
func NoAuthMiddleware(schemeName string) error { msg := fmt.Sprintf("Auth middleware for security scheme %s is not mounted", schemeName) return ErrNoAuthMiddleware(msg, "scheme", schemeName) }
[ "func", "NoAuthMiddleware", "(", "schemeName", "string", ")", "error", "{", "msg", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "schemeName", ")", "\n", "return", "ErrNoAuthMiddleware", "(", "msg", ",", "\"", "\"", ",", "schemeName", ")", "\n", "}" ]
// NoAuthMiddleware is the error produced when goa is unable to lookup a auth middleware for a // security scheme defined in the design.
[ "NoAuthMiddleware", "is", "the", "error", "produced", "when", "goa", "is", "unable", "to", "lookup", "a", "auth", "middleware", "for", "a", "security", "scheme", "defined", "in", "the", "design", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/error.go#L247-L250
166,632
goadesign/goa
error.go
MethodNotAllowedError
func MethodNotAllowedError(method string, allowed []string) error { var plural string if len(allowed) > 1 { plural = " one of" } msg := fmt.Sprintf("Method %s must be%s %s", method, plural, strings.Join(allowed, ", ")) return ErrMethodNotAllowed(msg, "method", method, "allowed", strings.Join(allowed, ", ")) }
go
func MethodNotAllowedError(method string, allowed []string) error { var plural string if len(allowed) > 1 { plural = " one of" } msg := fmt.Sprintf("Method %s must be%s %s", method, plural, strings.Join(allowed, ", ")) return ErrMethodNotAllowed(msg, "method", method, "allowed", strings.Join(allowed, ", ")) }
[ "func", "MethodNotAllowedError", "(", "method", "string", ",", "allowed", "[", "]", "string", ")", "error", "{", "var", "plural", "string", "\n", "if", "len", "(", "allowed", ")", ">", "1", "{", "plural", "=", "\"", "\"", "\n", "}", "\n", "msg", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "method", ",", "plural", ",", "strings", ".", "Join", "(", "allowed", ",", "\"", "\"", ")", ")", "\n", "return", "ErrMethodNotAllowed", "(", "msg", ",", "\"", "\"", ",", "method", ",", "\"", "\"", ",", "strings", ".", "Join", "(", "allowed", ",", "\"", "\"", ")", ")", "\n", "}" ]
// MethodNotAllowedError is the error produced to requests that match the path of a registered // handler but not the HTTP method.
[ "MethodNotAllowedError", "is", "the", "error", "produced", "to", "requests", "that", "match", "the", "path", "of", "a", "registered", "handler", "but", "not", "the", "HTTP", "method", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/error.go#L254-L261
166,633
goadesign/goa
error.go
Error
func (e *ErrorResponse) Error() string { msg := fmt.Sprintf("[%s] %d %s: %s", e.ID, e.Status, e.Code, e.Detail) for k, v := range e.Meta { msg += ", " + fmt.Sprintf("%s: %v", k, v) } return msg }
go
func (e *ErrorResponse) Error() string { msg := fmt.Sprintf("[%s] %d %s: %s", e.ID, e.Status, e.Code, e.Detail) for k, v := range e.Meta { msg += ", " + fmt.Sprintf("%s: %v", k, v) } return msg }
[ "func", "(", "e", "*", "ErrorResponse", ")", "Error", "(", ")", "string", "{", "msg", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "e", ".", "ID", ",", "e", ".", "Status", ",", "e", ".", "Code", ",", "e", ".", "Detail", ")", "\n", "for", "k", ",", "v", ":=", "range", "e", ".", "Meta", "{", "msg", "+=", "\"", "\"", "+", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "k", ",", "v", ")", "\n", "}", "\n", "return", "msg", "\n", "}" ]
// Error returns the error occurrence details.
[ "Error", "returns", "the", "error", "occurrence", "details", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/error.go#L264-L270
166,634
goadesign/goa
goagen/utils/signal.go
Catch
func Catch(signals []os.Signal, then func()) { c := make(chan os.Signal) if signals == nil { signals = defaultSignals } signal.Notify(c, signals...) <-c if then != nil { then() } }
go
func Catch(signals []os.Signal, then func()) { c := make(chan os.Signal) if signals == nil { signals = defaultSignals } signal.Notify(c, signals...) <-c if then != nil { then() } }
[ "func", "Catch", "(", "signals", "[", "]", "os", ".", "Signal", ",", "then", "func", "(", ")", ")", "{", "c", ":=", "make", "(", "chan", "os", ".", "Signal", ")", "\n", "if", "signals", "==", "nil", "{", "signals", "=", "defaultSignals", "\n", "}", "\n", "signal", ".", "Notify", "(", "c", ",", "signals", "...", ")", "\n", "<-", "c", "\n", "if", "then", "!=", "nil", "{", "then", "(", ")", "\n", "}", "\n", "}" ]
// Catch signals and invoke then callback
[ "Catch", "signals", "and", "invoke", "then", "callback" ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/goagen/utils/signal.go#L9-L19
166,635
goadesign/goa
goagen/gen_app/encoding.go
BuildEncoders
func BuildEncoders(info []*design.EncodingDefinition, encoder bool) ([]*EncoderTemplateData, error) { if len(info) == 0 { return nil, nil } // knownStdPackages lists the stdlib packages known by BuildEncoders var knownStdPackages = map[string]string{ "encoding/json": "json", "encoding/xml": "xml", "encoding/gob": "gob", } encs := normalizeEncodingDefinitions(info) data := make([]*EncoderTemplateData, len(encs)) defaultMediaType := info[0].MIMETypes[0] for i, enc := range encs { var pkgName string if name, ok := knownStdPackages[enc.PackagePath]; ok { pkgName = name } else { srcPath, err := codegen.PackageSourcePath(enc.PackagePath) if err != nil { return nil, fmt.Errorf("failed to locate package source of %s (%s)", enc.PackagePath, err) } pkgName, err = codegen.PackageName(srcPath) if err != nil { return nil, fmt.Errorf("failed to load package %s (%s)", enc.PackagePath, err) } } isDefault := false for _, m := range enc.MIMETypes { if m == defaultMediaType { isDefault = true } } d := &EncoderTemplateData{ PackagePath: enc.PackagePath, PackageName: pkgName, Function: enc.Function, MIMETypes: enc.MIMETypes, Default: isDefault, } data[i] = d } return data, nil }
go
func BuildEncoders(info []*design.EncodingDefinition, encoder bool) ([]*EncoderTemplateData, error) { if len(info) == 0 { return nil, nil } // knownStdPackages lists the stdlib packages known by BuildEncoders var knownStdPackages = map[string]string{ "encoding/json": "json", "encoding/xml": "xml", "encoding/gob": "gob", } encs := normalizeEncodingDefinitions(info) data := make([]*EncoderTemplateData, len(encs)) defaultMediaType := info[0].MIMETypes[0] for i, enc := range encs { var pkgName string if name, ok := knownStdPackages[enc.PackagePath]; ok { pkgName = name } else { srcPath, err := codegen.PackageSourcePath(enc.PackagePath) if err != nil { return nil, fmt.Errorf("failed to locate package source of %s (%s)", enc.PackagePath, err) } pkgName, err = codegen.PackageName(srcPath) if err != nil { return nil, fmt.Errorf("failed to load package %s (%s)", enc.PackagePath, err) } } isDefault := false for _, m := range enc.MIMETypes { if m == defaultMediaType { isDefault = true } } d := &EncoderTemplateData{ PackagePath: enc.PackagePath, PackageName: pkgName, Function: enc.Function, MIMETypes: enc.MIMETypes, Default: isDefault, } data[i] = d } return data, nil }
[ "func", "BuildEncoders", "(", "info", "[", "]", "*", "design", ".", "EncodingDefinition", ",", "encoder", "bool", ")", "(", "[", "]", "*", "EncoderTemplateData", ",", "error", ")", "{", "if", "len", "(", "info", ")", "==", "0", "{", "return", "nil", ",", "nil", "\n", "}", "\n", "// knownStdPackages lists the stdlib packages known by BuildEncoders", "var", "knownStdPackages", "=", "map", "[", "string", "]", "string", "{", "\"", "\"", ":", "\"", "\"", ",", "\"", "\"", ":", "\"", "\"", ",", "\"", "\"", ":", "\"", "\"", ",", "}", "\n", "encs", ":=", "normalizeEncodingDefinitions", "(", "info", ")", "\n", "data", ":=", "make", "(", "[", "]", "*", "EncoderTemplateData", ",", "len", "(", "encs", ")", ")", "\n", "defaultMediaType", ":=", "info", "[", "0", "]", ".", "MIMETypes", "[", "0", "]", "\n", "for", "i", ",", "enc", ":=", "range", "encs", "{", "var", "pkgName", "string", "\n", "if", "name", ",", "ok", ":=", "knownStdPackages", "[", "enc", ".", "PackagePath", "]", ";", "ok", "{", "pkgName", "=", "name", "\n", "}", "else", "{", "srcPath", ",", "err", ":=", "codegen", ".", "PackageSourcePath", "(", "enc", ".", "PackagePath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "enc", ".", "PackagePath", ",", "err", ")", "\n", "}", "\n", "pkgName", ",", "err", "=", "codegen", ".", "PackageName", "(", "srcPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "enc", ".", "PackagePath", ",", "err", ")", "\n", "}", "\n", "}", "\n", "isDefault", ":=", "false", "\n", "for", "_", ",", "m", ":=", "range", "enc", ".", "MIMETypes", "{", "if", "m", "==", "defaultMediaType", "{", "isDefault", "=", "true", "\n", "}", "\n", "}", "\n", "d", ":=", "&", "EncoderTemplateData", "{", "PackagePath", ":", "enc", ".", "PackagePath", ",", "PackageName", ":", "pkgName", ",", "Function", ":", "enc", ".", "Function", ",", "MIMETypes", ":", "enc", ".", "MIMETypes", ",", "Default", ":", "isDefault", ",", "}", "\n", "data", "[", "i", "]", "=", "d", "\n", "}", "\n", "return", "data", ",", "nil", "\n", "}" ]
// BuildEncoders builds the template data needed to render the given encoding definitions. // This extra map is needed to handle the case where a single encoding definition maps to multiple // encoding packages. The data is indexed by mime type.
[ "BuildEncoders", "builds", "the", "template", "data", "needed", "to", "render", "the", "given", "encoding", "definitions", ".", "This", "extra", "map", "is", "needed", "to", "handle", "the", "case", "where", "a", "single", "encoding", "definition", "maps", "to", "multiple", "encoding", "packages", ".", "The", "data", "is", "indexed", "by", "mime", "type", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/goagen/gen_app/encoding.go#L14-L59
166,636
goadesign/goa
design/types.go
Name
func (p Primitive) Name() string { switch p { case Boolean: return "boolean" case Integer: return "integer" case Number: return "number" case String, DateTime, UUID: return "string" case Any: return "any" case File: return "file" default: panic("unknown primitive type") // bug } }
go
func (p Primitive) Name() string { switch p { case Boolean: return "boolean" case Integer: return "integer" case Number: return "number" case String, DateTime, UUID: return "string" case Any: return "any" case File: return "file" default: panic("unknown primitive type") // bug } }
[ "func", "(", "p", "Primitive", ")", "Name", "(", ")", "string", "{", "switch", "p", "{", "case", "Boolean", ":", "return", "\"", "\"", "\n", "case", "Integer", ":", "return", "\"", "\"", "\n", "case", "Number", ":", "return", "\"", "\"", "\n", "case", "String", ",", "DateTime", ",", "UUID", ":", "return", "\"", "\"", "\n", "case", "Any", ":", "return", "\"", "\"", "\n", "case", "File", ":", "return", "\"", "\"", "\n", "default", ":", "panic", "(", "\"", "\"", ")", "// bug", "\n", "}", "\n", "}" ]
// Name returns the JSON type name.
[ "Name", "returns", "the", "JSON", "type", "name", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/types.go#L204-L221
166,637
goadesign/goa
design/types.go
CanHaveDefault
func (p Primitive) CanHaveDefault() (ok bool) { switch p { case Boolean, Integer, Number, String, DateTime: ok = true } return }
go
func (p Primitive) CanHaveDefault() (ok bool) { switch p { case Boolean, Integer, Number, String, DateTime: ok = true } return }
[ "func", "(", "p", "Primitive", ")", "CanHaveDefault", "(", ")", "(", "ok", "bool", ")", "{", "switch", "p", "{", "case", "Boolean", ",", "Integer", ",", "Number", ",", "String", ",", "DateTime", ":", "ok", "=", "true", "\n", "}", "\n", "return", "\n", "}" ]
// CanHaveDefault returns whether the primitive can have a default value.
[ "CanHaveDefault", "returns", "whether", "the", "primitive", "can", "have", "a", "default", "value", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/types.go#L248-L254
166,638
goadesign/goa
design/types.go
GenerateExample
func (p Primitive) GenerateExample(r *RandomGenerator, seen []string) interface{} { switch p { case Boolean: return r.Bool() case Integer: return r.Int() case Number: return r.Float64() case String: return r.String() case DateTime: return r.DateTime() case UUID: return r.UUID().String() // Generate string to can be JSON marshaled case Any: // to not make it too complicated, pick one of the primitive types return anyPrimitive[r.Int()%len(anyPrimitive)].GenerateExample(r, seen) case File: return r.File() default: panic("unknown primitive type") // bug } }
go
func (p Primitive) GenerateExample(r *RandomGenerator, seen []string) interface{} { switch p { case Boolean: return r.Bool() case Integer: return r.Int() case Number: return r.Float64() case String: return r.String() case DateTime: return r.DateTime() case UUID: return r.UUID().String() // Generate string to can be JSON marshaled case Any: // to not make it too complicated, pick one of the primitive types return anyPrimitive[r.Int()%len(anyPrimitive)].GenerateExample(r, seen) case File: return r.File() default: panic("unknown primitive type") // bug } }
[ "func", "(", "p", "Primitive", ")", "GenerateExample", "(", "r", "*", "RandomGenerator", ",", "seen", "[", "]", "string", ")", "interface", "{", "}", "{", "switch", "p", "{", "case", "Boolean", ":", "return", "r", ".", "Bool", "(", ")", "\n", "case", "Integer", ":", "return", "r", ".", "Int", "(", ")", "\n", "case", "Number", ":", "return", "r", ".", "Float64", "(", ")", "\n", "case", "String", ":", "return", "r", ".", "String", "(", ")", "\n", "case", "DateTime", ":", "return", "r", ".", "DateTime", "(", ")", "\n", "case", "UUID", ":", "return", "r", ".", "UUID", "(", ")", ".", "String", "(", ")", "// Generate string to can be JSON marshaled", "\n", "case", "Any", ":", "// to not make it too complicated, pick one of the primitive types", "return", "anyPrimitive", "[", "r", ".", "Int", "(", ")", "%", "len", "(", "anyPrimitive", ")", "]", ".", "GenerateExample", "(", "r", ",", "seen", ")", "\n", "case", "File", ":", "return", "r", ".", "File", "(", ")", "\n", "default", ":", "panic", "(", "\"", "\"", ")", "// bug", "\n", "}", "\n", "}" ]
// GenerateExample returns an instance of the given data type.
[ "GenerateExample", "returns", "an", "instance", "of", "the", "given", "data", "type", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/types.go#L290-L312
166,639
goadesign/goa
design/types.go
GenerateExample
func (a *Array) GenerateExample(r *RandomGenerator, seen []string) interface{} { count := r.Int()%3 + 1 res := make([]interface{}, count) for i := 0; i < count; i++ { res[i] = a.ElemType.Type.GenerateExample(r, seen) } return a.MakeSlice(res) }
go
func (a *Array) GenerateExample(r *RandomGenerator, seen []string) interface{} { count := r.Int()%3 + 1 res := make([]interface{}, count) for i := 0; i < count; i++ { res[i] = a.ElemType.Type.GenerateExample(r, seen) } return a.MakeSlice(res) }
[ "func", "(", "a", "*", "Array", ")", "GenerateExample", "(", "r", "*", "RandomGenerator", ",", "seen", "[", "]", "string", ")", "interface", "{", "}", "{", "count", ":=", "r", ".", "Int", "(", ")", "%", "3", "+", "1", "\n", "res", ":=", "make", "(", "[", "]", "interface", "{", "}", ",", "count", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "count", ";", "i", "++", "{", "res", "[", "i", "]", "=", "a", ".", "ElemType", ".", "Type", ".", "GenerateExample", "(", "r", ",", "seen", ")", "\n", "}", "\n", "return", "a", ".", "MakeSlice", "(", "res", ")", "\n", "}" ]
// GenerateExample produces a random array value.
[ "GenerateExample", "produces", "a", "random", "array", "value", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/types.go#L372-L379
166,640
goadesign/goa
design/types.go
Merge
func (o Object) Merge(other Object) { for n, att := range other { o[n] = DupAtt(att) } }
go
func (o Object) Merge(other Object) { for n, att := range other { o[n] = DupAtt(att) } }
[ "func", "(", "o", "Object", ")", "Merge", "(", "other", "Object", ")", "{", "for", "n", ",", "att", ":=", "range", "other", "{", "o", "[", "n", "]", "=", "DupAtt", "(", "att", ")", "\n", "}", "\n", "}" ]
// Merge copies other's attributes into o overridding any pre-existing attribute with the same name.
[ "Merge", "copies", "other", "s", "attributes", "into", "o", "overridding", "any", "pre", "-", "existing", "attribute", "with", "the", "same", "name", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/types.go#L425-L429
166,641
goadesign/goa
design/types.go
GenerateExample
func (o Object) GenerateExample(r *RandomGenerator, seen []string) interface{} { // ensure fixed ordering keys := make([]string, 0, len(o)) for n := range o { keys = append(keys, n) } sort.Strings(keys) res := make(map[string]interface{}) for _, n := range keys { att := o[n] res[n] = att.Type.GenerateExample(r, seen) } return res }
go
func (o Object) GenerateExample(r *RandomGenerator, seen []string) interface{} { // ensure fixed ordering keys := make([]string, 0, len(o)) for n := range o { keys = append(keys, n) } sort.Strings(keys) res := make(map[string]interface{}) for _, n := range keys { att := o[n] res[n] = att.Type.GenerateExample(r, seen) } return res }
[ "func", "(", "o", "Object", ")", "GenerateExample", "(", "r", "*", "RandomGenerator", ",", "seen", "[", "]", "string", ")", "interface", "{", "}", "{", "// ensure fixed ordering", "keys", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "o", ")", ")", "\n", "for", "n", ":=", "range", "o", "{", "keys", "=", "append", "(", "keys", ",", "n", ")", "\n", "}", "\n", "sort", ".", "Strings", "(", "keys", ")", "\n\n", "res", ":=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "for", "_", ",", "n", ":=", "range", "keys", "{", "att", ":=", "o", "[", "n", "]", "\n", "res", "[", "n", "]", "=", "att", ".", "Type", ".", "GenerateExample", "(", "r", ",", "seen", ")", "\n", "}", "\n", "return", "res", "\n", "}" ]
// GenerateExample returns a random value of the object.
[ "GenerateExample", "returns", "a", "random", "value", "of", "the", "object", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/types.go#L438-L452
166,642
goadesign/goa
design/types.go
HasAttributes
func (h *Hash) HasAttributes() bool { return h.KeyType.Type.HasAttributes() || h.ElemType.Type.HasAttributes() }
go
func (h *Hash) HasAttributes() bool { return h.KeyType.Type.HasAttributes() || h.ElemType.Type.HasAttributes() }
[ "func", "(", "h", "*", "Hash", ")", "HasAttributes", "(", ")", "bool", "{", "return", "h", ".", "KeyType", ".", "Type", ".", "HasAttributes", "(", ")", "||", "h", ".", "ElemType", ".", "Type", ".", "HasAttributes", "(", ")", "\n", "}" ]
// HasAttributes returns true if the either hash's key type is user defined // or the element type is user defined.
[ "HasAttributes", "returns", "true", "if", "the", "either", "hash", "s", "key", "type", "is", "user", "defined", "or", "the", "element", "type", "is", "user", "defined", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/types.go#L465-L467
166,643
goadesign/goa
design/types.go
CanHaveDefault
func (h *Hash) CanHaveDefault() bool { return h.KeyType.Type.CanHaveDefault() && h.ElemType.Type.CanHaveDefault() }
go
func (h *Hash) CanHaveDefault() bool { return h.KeyType.Type.CanHaveDefault() && h.ElemType.Type.CanHaveDefault() }
[ "func", "(", "h", "*", "Hash", ")", "CanHaveDefault", "(", ")", "bool", "{", "return", "h", ".", "KeyType", ".", "Type", ".", "CanHaveDefault", "(", ")", "&&", "h", ".", "ElemType", ".", "Type", ".", "CanHaveDefault", "(", ")", "\n", "}" ]
// CanHaveDefault returns true if the hash type can have a default value. // The hash type can have a default value only if both the key type and // the element type can have a default value.
[ "CanHaveDefault", "returns", "true", "if", "the", "hash", "type", "can", "have", "a", "default", "value", ".", "The", "hash", "type", "can", "have", "a", "default", "value", "only", "if", "both", "the", "key", "type", "and", "the", "element", "type", "can", "have", "a", "default", "value", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/types.go#L490-L492
166,644
goadesign/goa
design/types.go
GenerateExample
func (h *Hash) GenerateExample(r *RandomGenerator, seen []string) interface{} { count := r.Int()%3 + 1 pair := map[interface{}]interface{}{} for i := 0; i < count; i++ { pair[h.KeyType.Type.GenerateExample(r, seen)] = h.ElemType.Type.GenerateExample(r, seen) } return h.MakeMap(pair) }
go
func (h *Hash) GenerateExample(r *RandomGenerator, seen []string) interface{} { count := r.Int()%3 + 1 pair := map[interface{}]interface{}{} for i := 0; i < count; i++ { pair[h.KeyType.Type.GenerateExample(r, seen)] = h.ElemType.Type.GenerateExample(r, seen) } return h.MakeMap(pair) }
[ "func", "(", "h", "*", "Hash", ")", "GenerateExample", "(", "r", "*", "RandomGenerator", ",", "seen", "[", "]", "string", ")", "interface", "{", "}", "{", "count", ":=", "r", ".", "Int", "(", ")", "%", "3", "+", "1", "\n", "pair", ":=", "map", "[", "interface", "{", "}", "]", "interface", "{", "}", "{", "}", "\n", "for", "i", ":=", "0", ";", "i", "<", "count", ";", "i", "++", "{", "pair", "[", "h", ".", "KeyType", ".", "Type", ".", "GenerateExample", "(", "r", ",", "seen", ")", "]", "=", "h", ".", "ElemType", ".", "Type", ".", "GenerateExample", "(", "r", ",", "seen", ")", "\n", "}", "\n", "return", "h", ".", "MakeMap", "(", "pair", ")", "\n", "}" ]
// GenerateExample returns a random hash value.
[ "GenerateExample", "returns", "a", "random", "hash", "value", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/types.go#L512-L519
166,645
goadesign/goa
design/types.go
IterateAttributes
func (o Object) IterateAttributes(it AttributeIterator) error { names := make([]string, len(o)) i := 0 for n := range o { names[i] = n i++ } sort.Strings(names) for _, n := range names { if err := it(n, o[n]); err != nil { return err } } return nil }
go
func (o Object) IterateAttributes(it AttributeIterator) error { names := make([]string, len(o)) i := 0 for n := range o { names[i] = n i++ } sort.Strings(names) for _, n := range names { if err := it(n, o[n]); err != nil { return err } } return nil }
[ "func", "(", "o", "Object", ")", "IterateAttributes", "(", "it", "AttributeIterator", ")", "error", "{", "names", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "o", ")", ")", "\n", "i", ":=", "0", "\n", "for", "n", ":=", "range", "o", "{", "names", "[", "i", "]", "=", "n", "\n", "i", "++", "\n", "}", "\n", "sort", ".", "Strings", "(", "names", ")", "\n", "for", "_", ",", "n", ":=", "range", "names", "{", "if", "err", ":=", "it", "(", "n", ",", "o", "[", "n", "]", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// IterateAttributes calls the given iterator passing in each attribute sorted in alphabetical order. // Iteration stops if an iterator returns an error and in this case IterateObject returns that // error.
[ "IterateAttributes", "calls", "the", "given", "iterator", "passing", "in", "each", "attribute", "sorted", "in", "alphabetical", "order", ".", "Iteration", "stops", "if", "an", "iterator", "returns", "an", "error", "and", "in", "this", "case", "IterateObject", "returns", "that", "error", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/types.go#L537-L551
166,646
goadesign/goa
design/types.go
UserTypes
func UserTypes(dt DataType) map[string]*UserTypeDefinition { collect := func(types map[string]*UserTypeDefinition) func(*AttributeDefinition) error { return func(at *AttributeDefinition) error { if u, ok := at.Type.(*UserTypeDefinition); ok { types[u.TypeName] = u } else if m, ok := at.Type.(*MediaTypeDefinition); ok { types[m.TypeName] = m.UserTypeDefinition } return nil } } switch actual := dt.(type) { case Primitive: return nil case *Array: return UserTypes(actual.ElemType.Type) case *Hash: ktypes := UserTypes(actual.KeyType.Type) vtypes := UserTypes(actual.ElemType.Type) if vtypes == nil { return ktypes } for n, ut := range ktypes { vtypes[n] = ut } return vtypes case Object: types := make(map[string]*UserTypeDefinition) for _, att := range actual { att.Walk(collect(types)) } if len(types) == 0 { return nil } return types case *UserTypeDefinition: types := map[string]*UserTypeDefinition{actual.TypeName: actual} actual.Walk(collect(types)) return types case *MediaTypeDefinition: types := map[string]*UserTypeDefinition{actual.TypeName: actual.UserTypeDefinition} actual.Walk(collect(types)) return types default: panic("unknown type") // bug } }
go
func UserTypes(dt DataType) map[string]*UserTypeDefinition { collect := func(types map[string]*UserTypeDefinition) func(*AttributeDefinition) error { return func(at *AttributeDefinition) error { if u, ok := at.Type.(*UserTypeDefinition); ok { types[u.TypeName] = u } else if m, ok := at.Type.(*MediaTypeDefinition); ok { types[m.TypeName] = m.UserTypeDefinition } return nil } } switch actual := dt.(type) { case Primitive: return nil case *Array: return UserTypes(actual.ElemType.Type) case *Hash: ktypes := UserTypes(actual.KeyType.Type) vtypes := UserTypes(actual.ElemType.Type) if vtypes == nil { return ktypes } for n, ut := range ktypes { vtypes[n] = ut } return vtypes case Object: types := make(map[string]*UserTypeDefinition) for _, att := range actual { att.Walk(collect(types)) } if len(types) == 0 { return nil } return types case *UserTypeDefinition: types := map[string]*UserTypeDefinition{actual.TypeName: actual} actual.Walk(collect(types)) return types case *MediaTypeDefinition: types := map[string]*UserTypeDefinition{actual.TypeName: actual.UserTypeDefinition} actual.Walk(collect(types)) return types default: panic("unknown type") // bug } }
[ "func", "UserTypes", "(", "dt", "DataType", ")", "map", "[", "string", "]", "*", "UserTypeDefinition", "{", "collect", ":=", "func", "(", "types", "map", "[", "string", "]", "*", "UserTypeDefinition", ")", "func", "(", "*", "AttributeDefinition", ")", "error", "{", "return", "func", "(", "at", "*", "AttributeDefinition", ")", "error", "{", "if", "u", ",", "ok", ":=", "at", ".", "Type", ".", "(", "*", "UserTypeDefinition", ")", ";", "ok", "{", "types", "[", "u", ".", "TypeName", "]", "=", "u", "\n", "}", "else", "if", "m", ",", "ok", ":=", "at", ".", "Type", ".", "(", "*", "MediaTypeDefinition", ")", ";", "ok", "{", "types", "[", "m", ".", "TypeName", "]", "=", "m", ".", "UserTypeDefinition", "\n", "}", "\n", "return", "nil", "\n", "}", "\n", "}", "\n", "switch", "actual", ":=", "dt", ".", "(", "type", ")", "{", "case", "Primitive", ":", "return", "nil", "\n", "case", "*", "Array", ":", "return", "UserTypes", "(", "actual", ".", "ElemType", ".", "Type", ")", "\n", "case", "*", "Hash", ":", "ktypes", ":=", "UserTypes", "(", "actual", ".", "KeyType", ".", "Type", ")", "\n", "vtypes", ":=", "UserTypes", "(", "actual", ".", "ElemType", ".", "Type", ")", "\n", "if", "vtypes", "==", "nil", "{", "return", "ktypes", "\n", "}", "\n", "for", "n", ",", "ut", ":=", "range", "ktypes", "{", "vtypes", "[", "n", "]", "=", "ut", "\n", "}", "\n", "return", "vtypes", "\n", "case", "Object", ":", "types", ":=", "make", "(", "map", "[", "string", "]", "*", "UserTypeDefinition", ")", "\n", "for", "_", ",", "att", ":=", "range", "actual", "{", "att", ".", "Walk", "(", "collect", "(", "types", ")", ")", "\n", "}", "\n", "if", "len", "(", "types", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n", "return", "types", "\n", "case", "*", "UserTypeDefinition", ":", "types", ":=", "map", "[", "string", "]", "*", "UserTypeDefinition", "{", "actual", ".", "TypeName", ":", "actual", "}", "\n", "actual", ".", "Walk", "(", "collect", "(", "types", ")", ")", "\n", "return", "types", "\n", "case", "*", "MediaTypeDefinition", ":", "types", ":=", "map", "[", "string", "]", "*", "UserTypeDefinition", "{", "actual", ".", "TypeName", ":", "actual", ".", "UserTypeDefinition", "}", "\n", "actual", ".", "Walk", "(", "collect", "(", "types", ")", ")", "\n", "return", "types", "\n", "default", ":", "panic", "(", "\"", "\"", ")", "// bug", "\n", "}", "\n", "}" ]
// UserTypes traverses the data type recursively and collects all the user types used to // define it. The returned map is indexed by type name.
[ "UserTypes", "traverses", "the", "data", "type", "recursively", "and", "collects", "all", "the", "user", "types", "used", "to", "define", "it", ".", "The", "returned", "map", "is", "indexed", "by", "type", "name", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/types.go#L555-L601
166,647
goadesign/goa
design/types.go
ToSlice
func (a ArrayVal) ToSlice() []interface{} { arr := make([]interface{}, len(a)) for i, elem := range a { switch actual := elem.(type) { case ArrayVal: arr[i] = actual.ToSlice() case HashVal: arr[i] = actual.ToMap() default: arr[i] = actual } } return arr }
go
func (a ArrayVal) ToSlice() []interface{} { arr := make([]interface{}, len(a)) for i, elem := range a { switch actual := elem.(type) { case ArrayVal: arr[i] = actual.ToSlice() case HashVal: arr[i] = actual.ToMap() default: arr[i] = actual } } return arr }
[ "func", "(", "a", "ArrayVal", ")", "ToSlice", "(", ")", "[", "]", "interface", "{", "}", "{", "arr", ":=", "make", "(", "[", "]", "interface", "{", "}", ",", "len", "(", "a", ")", ")", "\n", "for", "i", ",", "elem", ":=", "range", "a", "{", "switch", "actual", ":=", "elem", ".", "(", "type", ")", "{", "case", "ArrayVal", ":", "arr", "[", "i", "]", "=", "actual", ".", "ToSlice", "(", ")", "\n", "case", "HashVal", ":", "arr", "[", "i", "]", "=", "actual", ".", "ToMap", "(", ")", "\n", "default", ":", "arr", "[", "i", "]", "=", "actual", "\n", "}", "\n", "}", "\n", "return", "arr", "\n", "}" ]
// ToSlice converts an ArrayVal to a slice.
[ "ToSlice", "converts", "an", "ArrayVal", "to", "a", "slice", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/types.go#L646-L659
166,648
goadesign/goa
design/types.go
ToMap
func (h HashVal) ToMap() map[interface{}]interface{} { mp := make(map[interface{}]interface{}, len(h)) for k, v := range h { switch actual := v.(type) { case ArrayVal: mp[k] = actual.ToSlice() case HashVal: mp[k] = actual.ToMap() default: mp[k] = actual } } return mp }
go
func (h HashVal) ToMap() map[interface{}]interface{} { mp := make(map[interface{}]interface{}, len(h)) for k, v := range h { switch actual := v.(type) { case ArrayVal: mp[k] = actual.ToSlice() case HashVal: mp[k] = actual.ToMap() default: mp[k] = actual } } return mp }
[ "func", "(", "h", "HashVal", ")", "ToMap", "(", ")", "map", "[", "interface", "{", "}", "]", "interface", "{", "}", "{", "mp", ":=", "make", "(", "map", "[", "interface", "{", "}", "]", "interface", "{", "}", ",", "len", "(", "h", ")", ")", "\n", "for", "k", ",", "v", ":=", "range", "h", "{", "switch", "actual", ":=", "v", ".", "(", "type", ")", "{", "case", "ArrayVal", ":", "mp", "[", "k", "]", "=", "actual", ".", "ToSlice", "(", ")", "\n", "case", "HashVal", ":", "mp", "[", "k", "]", "=", "actual", ".", "ToMap", "(", ")", "\n", "default", ":", "mp", "[", "k", "]", "=", "actual", "\n", "}", "\n", "}", "\n", "return", "mp", "\n", "}" ]
// ToMap converts a HashVal to a map.
[ "ToMap", "converts", "a", "HashVal", "to", "a", "map", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/types.go#L662-L675
166,649
goadesign/goa
design/types.go
NewUserTypeDefinition
func NewUserTypeDefinition(name string, dsl func()) *UserTypeDefinition { return &UserTypeDefinition{ TypeName: name, AttributeDefinition: &AttributeDefinition{DSLFunc: dsl}, } }
go
func NewUserTypeDefinition(name string, dsl func()) *UserTypeDefinition { return &UserTypeDefinition{ TypeName: name, AttributeDefinition: &AttributeDefinition{DSLFunc: dsl}, } }
[ "func", "NewUserTypeDefinition", "(", "name", "string", ",", "dsl", "func", "(", ")", ")", "*", "UserTypeDefinition", "{", "return", "&", "UserTypeDefinition", "{", "TypeName", ":", "name", ",", "AttributeDefinition", ":", "&", "AttributeDefinition", "{", "DSLFunc", ":", "dsl", "}", ",", "}", "\n", "}" ]
// NewUserTypeDefinition creates a user type definition but does not // execute the DSL.
[ "NewUserTypeDefinition", "creates", "a", "user", "type", "definition", "but", "does", "not", "execute", "the", "DSL", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/types.go#L679-L684
166,650
goadesign/goa
design/types.go
IsCompatible
func (u *UserTypeDefinition) IsCompatible(val interface{}) bool { return u.Type == nil || u.Type.IsCompatible(val) }
go
func (u *UserTypeDefinition) IsCompatible(val interface{}) bool { return u.Type == nil || u.Type.IsCompatible(val) }
[ "func", "(", "u", "*", "UserTypeDefinition", ")", "IsCompatible", "(", "val", "interface", "{", "}", ")", "bool", "{", "return", "u", ".", "Type", "==", "nil", "||", "u", ".", "Type", ".", "IsCompatible", "(", "val", ")", "\n", "}" ]
// IsCompatible returns true if val is compatible with u.
[ "IsCompatible", "returns", "true", "if", "val", "is", "compatible", "with", "u", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/types.go#L720-L722
166,651
goadesign/goa
design/types.go
Finalize
func (u *UserTypeDefinition) Finalize() { if u.Reference != nil { if bat := u.AttributeDefinition; bat != nil { u.AttributeDefinition.Inherit(bat) } } u.GenerateExample(Design.RandomGenerator(), nil) }
go
func (u *UserTypeDefinition) Finalize() { if u.Reference != nil { if bat := u.AttributeDefinition; bat != nil { u.AttributeDefinition.Inherit(bat) } } u.GenerateExample(Design.RandomGenerator(), nil) }
[ "func", "(", "u", "*", "UserTypeDefinition", ")", "Finalize", "(", ")", "{", "if", "u", ".", "Reference", "!=", "nil", "{", "if", "bat", ":=", "u", ".", "AttributeDefinition", ";", "bat", "!=", "nil", "{", "u", ".", "AttributeDefinition", ".", "Inherit", "(", "bat", ")", "\n", "}", "\n", "}", "\n\n", "u", ".", "GenerateExample", "(", "Design", ".", "RandomGenerator", "(", ")", ",", "nil", ")", "\n", "}" ]
// Finalize merges base type attributes.
[ "Finalize", "merges", "base", "type", "attributes", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/types.go#L725-L733
166,652
goadesign/goa
design/types.go
NewMediaTypeDefinition
func NewMediaTypeDefinition(name, identifier string, dsl func()) *MediaTypeDefinition { return &MediaTypeDefinition{ UserTypeDefinition: &UserTypeDefinition{ AttributeDefinition: &AttributeDefinition{Type: Object{}, DSLFunc: dsl}, TypeName: name, }, Identifier: identifier, } }
go
func NewMediaTypeDefinition(name, identifier string, dsl func()) *MediaTypeDefinition { return &MediaTypeDefinition{ UserTypeDefinition: &UserTypeDefinition{ AttributeDefinition: &AttributeDefinition{Type: Object{}, DSLFunc: dsl}, TypeName: name, }, Identifier: identifier, } }
[ "func", "NewMediaTypeDefinition", "(", "name", ",", "identifier", "string", ",", "dsl", "func", "(", ")", ")", "*", "MediaTypeDefinition", "{", "return", "&", "MediaTypeDefinition", "{", "UserTypeDefinition", ":", "&", "UserTypeDefinition", "{", "AttributeDefinition", ":", "&", "AttributeDefinition", "{", "Type", ":", "Object", "{", "}", ",", "DSLFunc", ":", "dsl", "}", ",", "TypeName", ":", "name", ",", "}", ",", "Identifier", ":", "identifier", ",", "}", "\n", "}" ]
// NewMediaTypeDefinition creates a media type definition but does not // execute the DSL.
[ "NewMediaTypeDefinition", "creates", "a", "media", "type", "definition", "but", "does", "not", "execute", "the", "DSL", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/types.go#L737-L745
166,653
goadesign/goa
design/types.go
IsError
func (m *MediaTypeDefinition) IsError() bool { base, params, err := mime.ParseMediaType(m.Identifier) if err != nil { panic("invalid media type identifier " + m.Identifier) // bug } delete(params, "view") return mime.FormatMediaType(base, params) == ErrorMedia.Identifier }
go
func (m *MediaTypeDefinition) IsError() bool { base, params, err := mime.ParseMediaType(m.Identifier) if err != nil { panic("invalid media type identifier " + m.Identifier) // bug } delete(params, "view") return mime.FormatMediaType(base, params) == ErrorMedia.Identifier }
[ "func", "(", "m", "*", "MediaTypeDefinition", ")", "IsError", "(", ")", "bool", "{", "base", ",", "params", ",", "err", ":=", "mime", ".", "ParseMediaType", "(", "m", ".", "Identifier", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "\"", "\"", "+", "m", ".", "Identifier", ")", "// bug", "\n", "}", "\n", "delete", "(", "params", ",", "\"", "\"", ")", "\n", "return", "mime", ".", "FormatMediaType", "(", "base", ",", "params", ")", "==", "ErrorMedia", ".", "Identifier", "\n", "}" ]
// IsError returns true if the media type is implemented via a goa struct.
[ "IsError", "returns", "true", "if", "the", "media", "type", "is", "implemented", "via", "a", "goa", "struct", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/types.go#L751-L758
166,654
goadesign/goa
design/types.go
ComputeViews
func (m *MediaTypeDefinition) ComputeViews() map[string]*ViewDefinition { if m.Views != nil { return m.Views } if m.IsArray() { if mt, ok := m.ToArray().ElemType.Type.(*MediaTypeDefinition); ok { return mt.ComputeViews() } } return nil }
go
func (m *MediaTypeDefinition) ComputeViews() map[string]*ViewDefinition { if m.Views != nil { return m.Views } if m.IsArray() { if mt, ok := m.ToArray().ElemType.Type.(*MediaTypeDefinition); ok { return mt.ComputeViews() } } return nil }
[ "func", "(", "m", "*", "MediaTypeDefinition", ")", "ComputeViews", "(", ")", "map", "[", "string", "]", "*", "ViewDefinition", "{", "if", "m", ".", "Views", "!=", "nil", "{", "return", "m", ".", "Views", "\n", "}", "\n", "if", "m", ".", "IsArray", "(", ")", "{", "if", "mt", ",", "ok", ":=", "m", ".", "ToArray", "(", ")", ".", "ElemType", ".", "Type", ".", "(", "*", "MediaTypeDefinition", ")", ";", "ok", "{", "return", "mt", ".", "ComputeViews", "(", ")", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// ComputeViews returns the media type views recursing as necessary if the media type is a // collection.
[ "ComputeViews", "returns", "the", "media", "type", "views", "recursing", "as", "necessary", "if", "the", "media", "type", "is", "a", "collection", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/types.go#L762-L772
166,655
goadesign/goa
design/types.go
Finalize
func (m *MediaTypeDefinition) Finalize() { if m.ContentType == "" { m.ContentType = m.Identifier } m.UserTypeDefinition.Finalize() }
go
func (m *MediaTypeDefinition) Finalize() { if m.ContentType == "" { m.ContentType = m.Identifier } m.UserTypeDefinition.Finalize() }
[ "func", "(", "m", "*", "MediaTypeDefinition", ")", "Finalize", "(", ")", "{", "if", "m", ".", "ContentType", "==", "\"", "\"", "{", "m", ".", "ContentType", "=", "m", ".", "Identifier", "\n", "}", "\n", "m", ".", "UserTypeDefinition", ".", "Finalize", "(", ")", "\n", "}" ]
// Finalize sets the value of ContentType to the identifier if not set.
[ "Finalize", "sets", "the", "value", "of", "ContentType", "to", "the", "identifier", "if", "not", "set", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/types.go#L775-L780
166,656
goadesign/goa
design/types.go
IterateViews
func (m *MediaTypeDefinition) IterateViews(it ViewIterator) error { o := m.Views // gather names and sort them names := make([]string, len(o)) i := 0 for n := range o { names[i] = n i++ } sort.Strings(names) // iterate for _, n := range names { if err := it(o[n]); err != nil { return err } } return nil }
go
func (m *MediaTypeDefinition) IterateViews(it ViewIterator) error { o := m.Views // gather names and sort them names := make([]string, len(o)) i := 0 for n := range o { names[i] = n i++ } sort.Strings(names) // iterate for _, n := range names { if err := it(o[n]); err != nil { return err } } return nil }
[ "func", "(", "m", "*", "MediaTypeDefinition", ")", "IterateViews", "(", "it", "ViewIterator", ")", "error", "{", "o", ":=", "m", ".", "Views", "\n", "// gather names and sort them", "names", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "o", ")", ")", "\n", "i", ":=", "0", "\n", "for", "n", ":=", "range", "o", "{", "names", "[", "i", "]", "=", "n", "\n", "i", "++", "\n", "}", "\n", "sort", ".", "Strings", "(", "names", ")", "\n", "// iterate", "for", "_", ",", "n", ":=", "range", "names", "{", "if", "err", ":=", "it", "(", "o", "[", "n", "]", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// IterateViews calls the given iterator passing in each attribute sorted in alphabetical order. // Iteration stops if an iterator returns an error and in this case IterateViews returns that // error.
[ "IterateViews", "calls", "the", "given", "iterator", "passing", "in", "each", "attribute", "sorted", "in", "alphabetical", "order", ".", "Iteration", "stops", "if", "an", "iterator", "returns", "an", "error", "and", "in", "this", "case", "IterateViews", "returns", "that", "error", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/types.go#L788-L805
166,657
goadesign/goa
design/types.go
Project
func (m *MediaTypeDefinition) Project(view string) (*MediaTypeDefinition, *UserTypeDefinition, error) { canonical := m.projectCanonical(view) if p, ok := ProjectedMediaTypes[canonical]; ok { var links *UserTypeDefinition mLinks := ProjectedMediaTypes[canonical+"; links"] if mLinks != nil { links = mLinks.UserTypeDefinition } return p, links, nil } if m.IsArray() { return m.projectCollection(view) } return m.projectSingle(view, canonical) }
go
func (m *MediaTypeDefinition) Project(view string) (*MediaTypeDefinition, *UserTypeDefinition, error) { canonical := m.projectCanonical(view) if p, ok := ProjectedMediaTypes[canonical]; ok { var links *UserTypeDefinition mLinks := ProjectedMediaTypes[canonical+"; links"] if mLinks != nil { links = mLinks.UserTypeDefinition } return p, links, nil } if m.IsArray() { return m.projectCollection(view) } return m.projectSingle(view, canonical) }
[ "func", "(", "m", "*", "MediaTypeDefinition", ")", "Project", "(", "view", "string", ")", "(", "*", "MediaTypeDefinition", ",", "*", "UserTypeDefinition", ",", "error", ")", "{", "canonical", ":=", "m", ".", "projectCanonical", "(", "view", ")", "\n", "if", "p", ",", "ok", ":=", "ProjectedMediaTypes", "[", "canonical", "]", ";", "ok", "{", "var", "links", "*", "UserTypeDefinition", "\n", "mLinks", ":=", "ProjectedMediaTypes", "[", "canonical", "+", "\"", "\"", "]", "\n", "if", "mLinks", "!=", "nil", "{", "links", "=", "mLinks", ".", "UserTypeDefinition", "\n", "}", "\n", "return", "p", ",", "links", ",", "nil", "\n", "}", "\n", "if", "m", ".", "IsArray", "(", ")", "{", "return", "m", ".", "projectCollection", "(", "view", ")", "\n", "}", "\n", "return", "m", ".", "projectSingle", "(", "view", ",", "canonical", ")", "\n", "}" ]
// Project creates a MediaTypeDefinition containing the fields defined in the given view. The // resuling media type only defines the default view and its identifier is modified to indicate that // it was projected by adding the view as id parameter. links is a user type of type Object where // each key corresponds to a linked media type as defined by the media type "links" attribute.
[ "Project", "creates", "a", "MediaTypeDefinition", "containing", "the", "fields", "defined", "in", "the", "given", "view", ".", "The", "resuling", "media", "type", "only", "defines", "the", "default", "view", "and", "its", "identifier", "is", "modified", "to", "indicate", "that", "it", "was", "projected", "by", "adding", "the", "view", "as", "id", "parameter", ".", "links", "is", "a", "user", "type", "of", "type", "Object", "where", "each", "key", "corresponds", "to", "a", "linked", "media", "type", "as", "defined", "by", "the", "media", "type", "links", "attribute", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/types.go#L811-L825
166,658
goadesign/goa
design/types.go
projectIdentifier
func (m *MediaTypeDefinition) projectIdentifier(view string) string { base, params, err := mime.ParseMediaType(m.Identifier) if err != nil { base = m.Identifier } params["view"] = view return mime.FormatMediaType(base, params) }
go
func (m *MediaTypeDefinition) projectIdentifier(view string) string { base, params, err := mime.ParseMediaType(m.Identifier) if err != nil { base = m.Identifier } params["view"] = view return mime.FormatMediaType(base, params) }
[ "func", "(", "m", "*", "MediaTypeDefinition", ")", "projectIdentifier", "(", "view", "string", ")", "string", "{", "base", ",", "params", ",", "err", ":=", "mime", ".", "ParseMediaType", "(", "m", ".", "Identifier", ")", "\n", "if", "err", "!=", "nil", "{", "base", "=", "m", ".", "Identifier", "\n", "}", "\n", "params", "[", "\"", "\"", "]", "=", "view", "\n", "return", "mime", ".", "FormatMediaType", "(", "base", ",", "params", ")", "\n", "}" ]
// projectIdentifier computes the projected media type identifier by adding the "view" param. We // need the projected media type identifier to be different so that looking up projected media types // from ProjectedMediaTypes works correctly. It's also good for clients.
[ "projectIdentifier", "computes", "the", "projected", "media", "type", "identifier", "by", "adding", "the", "view", "param", ".", "We", "need", "the", "projected", "media", "type", "identifier", "to", "be", "different", "so", "that", "looking", "up", "projected", "media", "types", "from", "ProjectedMediaTypes", "works", "correctly", ".", "It", "s", "also", "good", "for", "clients", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/types.go#L984-L991
166,659
goadesign/goa
design/types.go
projectCanonical
func (m *MediaTypeDefinition) projectCanonical(view string) string { cano := CanonicalIdentifier(m.Identifier) base, params, _ := mime.ParseMediaType(cano) if params["view"] != "" { return cano // Already projected } params["view"] = view return mime.FormatMediaType(base, params) }
go
func (m *MediaTypeDefinition) projectCanonical(view string) string { cano := CanonicalIdentifier(m.Identifier) base, params, _ := mime.ParseMediaType(cano) if params["view"] != "" { return cano // Already projected } params["view"] = view return mime.FormatMediaType(base, params) }
[ "func", "(", "m", "*", "MediaTypeDefinition", ")", "projectCanonical", "(", "view", "string", ")", "string", "{", "cano", ":=", "CanonicalIdentifier", "(", "m", ".", "Identifier", ")", "\n", "base", ",", "params", ",", "_", ":=", "mime", ".", "ParseMediaType", "(", "cano", ")", "\n", "if", "params", "[", "\"", "\"", "]", "!=", "\"", "\"", "{", "return", "cano", "// Already projected", "\n", "}", "\n", "params", "[", "\"", "\"", "]", "=", "view", "\n", "return", "mime", ".", "FormatMediaType", "(", "base", ",", "params", ")", "\n", "}" ]
// projectIdentifier computes the projected canonical media type identifier by adding the "view" // param if the view is not the default view.
[ "projectIdentifier", "computes", "the", "projected", "canonical", "media", "type", "identifier", "by", "adding", "the", "view", "param", "if", "the", "view", "is", "not", "the", "default", "view", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/types.go#L995-L1003
166,660
goadesign/goa
design/types.go
projectTypeName
func (m *MediaTypeDefinition) projectTypeName(view string) string { typeName := m.TypeName if view != "default" { typeName += strings.Title(view) } return typeName }
go
func (m *MediaTypeDefinition) projectTypeName(view string) string { typeName := m.TypeName if view != "default" { typeName += strings.Title(view) } return typeName }
[ "func", "(", "m", "*", "MediaTypeDefinition", ")", "projectTypeName", "(", "view", "string", ")", "string", "{", "typeName", ":=", "m", ".", "TypeName", "\n", "if", "view", "!=", "\"", "\"", "{", "typeName", "+=", "strings", ".", "Title", "(", "view", ")", "\n", "}", "\n", "return", "typeName", "\n", "}" ]
// projectTypeName appends the view name to the media type name if the view name is not "default".
[ "projectTypeName", "appends", "the", "view", "name", "to", "the", "media", "type", "name", "if", "the", "view", "name", "is", "not", "default", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/types.go#L1006-L1012
166,661
goadesign/goa
design/types.go
walk
func walk(at *AttributeDefinition, walker func(*AttributeDefinition) error, seen map[string]bool) error { if err := walker(at); err != nil { return err } walkUt := func(ut *UserTypeDefinition) error { if _, ok := seen[ut.TypeName]; ok { return nil } seen[ut.TypeName] = true return walk(ut.AttributeDefinition, walker, seen) } switch actual := at.Type.(type) { case Primitive: return nil case *Array: return walk(actual.ElemType, walker, seen) case *Hash: if err := walk(actual.KeyType, walker, seen); err != nil { return err } return walk(actual.ElemType, walker, seen) case Object: for _, cat := range actual { if err := walk(cat, walker, seen); err != nil { return err } } case *UserTypeDefinition: return walkUt(actual) case *MediaTypeDefinition: return walkUt(actual.UserTypeDefinition) default: panic("unknown attribute type") // bug } return nil }
go
func walk(at *AttributeDefinition, walker func(*AttributeDefinition) error, seen map[string]bool) error { if err := walker(at); err != nil { return err } walkUt := func(ut *UserTypeDefinition) error { if _, ok := seen[ut.TypeName]; ok { return nil } seen[ut.TypeName] = true return walk(ut.AttributeDefinition, walker, seen) } switch actual := at.Type.(type) { case Primitive: return nil case *Array: return walk(actual.ElemType, walker, seen) case *Hash: if err := walk(actual.KeyType, walker, seen); err != nil { return err } return walk(actual.ElemType, walker, seen) case Object: for _, cat := range actual { if err := walk(cat, walker, seen); err != nil { return err } } case *UserTypeDefinition: return walkUt(actual) case *MediaTypeDefinition: return walkUt(actual.UserTypeDefinition) default: panic("unknown attribute type") // bug } return nil }
[ "func", "walk", "(", "at", "*", "AttributeDefinition", ",", "walker", "func", "(", "*", "AttributeDefinition", ")", "error", ",", "seen", "map", "[", "string", "]", "bool", ")", "error", "{", "if", "err", ":=", "walker", "(", "at", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "walkUt", ":=", "func", "(", "ut", "*", "UserTypeDefinition", ")", "error", "{", "if", "_", ",", "ok", ":=", "seen", "[", "ut", ".", "TypeName", "]", ";", "ok", "{", "return", "nil", "\n", "}", "\n", "seen", "[", "ut", ".", "TypeName", "]", "=", "true", "\n", "return", "walk", "(", "ut", ".", "AttributeDefinition", ",", "walker", ",", "seen", ")", "\n", "}", "\n", "switch", "actual", ":=", "at", ".", "Type", ".", "(", "type", ")", "{", "case", "Primitive", ":", "return", "nil", "\n", "case", "*", "Array", ":", "return", "walk", "(", "actual", ".", "ElemType", ",", "walker", ",", "seen", ")", "\n", "case", "*", "Hash", ":", "if", "err", ":=", "walk", "(", "actual", ".", "KeyType", ",", "walker", ",", "seen", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "walk", "(", "actual", ".", "ElemType", ",", "walker", ",", "seen", ")", "\n", "case", "Object", ":", "for", "_", ",", "cat", ":=", "range", "actual", "{", "if", "err", ":=", "walk", "(", "cat", ",", "walker", ",", "seen", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "case", "*", "UserTypeDefinition", ":", "return", "walkUt", "(", "actual", ")", "\n", "case", "*", "MediaTypeDefinition", ":", "return", "walkUt", "(", "actual", ".", "UserTypeDefinition", ")", "\n", "default", ":", "panic", "(", "\"", "\"", ")", "// bug", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Recursive implementation of the Walk methods. Takes care of avoiding infinite recursions by // keeping track of types that have already been walked.
[ "Recursive", "implementation", "of", "the", "Walk", "methods", ".", "Takes", "care", "of", "avoiding", "infinite", "recursions", "by", "keeping", "track", "of", "types", "that", "have", "already", "been", "walked", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/types.go#L1037-L1072
166,662
goadesign/goa
design/types.go
toReflectType
func toReflectType(dtype DataType) reflect.Type { switch dtype.Kind() { case BooleanKind: return reflect.TypeOf(true) case IntegerKind: return reflect.TypeOf(int(0)) case NumberKind: return reflect.TypeOf(float64(0)) case UUIDKind, StringKind: return reflect.TypeOf("") case DateTimeKind: return reflect.TypeOf(time.Time{}) case ObjectKind, UserTypeKind, MediaTypeKind: return reflect.TypeOf(map[string]interface{}{}) case ArrayKind: return reflect.SliceOf(toReflectType(dtype.ToArray().ElemType.Type)) case HashKind: hash := dtype.ToHash() // avoid complication: not allow object as the hash key var ktype reflect.Type if !hash.KeyType.Type.IsObject() { ktype = toReflectType(hash.KeyType.Type) } else { ktype = reflect.TypeOf([]interface{}{}).Elem() } return reflect.MapOf(ktype, toReflectType(hash.ElemType.Type)) default: return reflect.TypeOf([]interface{}{}).Elem() } }
go
func toReflectType(dtype DataType) reflect.Type { switch dtype.Kind() { case BooleanKind: return reflect.TypeOf(true) case IntegerKind: return reflect.TypeOf(int(0)) case NumberKind: return reflect.TypeOf(float64(0)) case UUIDKind, StringKind: return reflect.TypeOf("") case DateTimeKind: return reflect.TypeOf(time.Time{}) case ObjectKind, UserTypeKind, MediaTypeKind: return reflect.TypeOf(map[string]interface{}{}) case ArrayKind: return reflect.SliceOf(toReflectType(dtype.ToArray().ElemType.Type)) case HashKind: hash := dtype.ToHash() // avoid complication: not allow object as the hash key var ktype reflect.Type if !hash.KeyType.Type.IsObject() { ktype = toReflectType(hash.KeyType.Type) } else { ktype = reflect.TypeOf([]interface{}{}).Elem() } return reflect.MapOf(ktype, toReflectType(hash.ElemType.Type)) default: return reflect.TypeOf([]interface{}{}).Elem() } }
[ "func", "toReflectType", "(", "dtype", "DataType", ")", "reflect", ".", "Type", "{", "switch", "dtype", ".", "Kind", "(", ")", "{", "case", "BooleanKind", ":", "return", "reflect", ".", "TypeOf", "(", "true", ")", "\n", "case", "IntegerKind", ":", "return", "reflect", ".", "TypeOf", "(", "int", "(", "0", ")", ")", "\n", "case", "NumberKind", ":", "return", "reflect", ".", "TypeOf", "(", "float64", "(", "0", ")", ")", "\n", "case", "UUIDKind", ",", "StringKind", ":", "return", "reflect", ".", "TypeOf", "(", "\"", "\"", ")", "\n", "case", "DateTimeKind", ":", "return", "reflect", ".", "TypeOf", "(", "time", ".", "Time", "{", "}", ")", "\n", "case", "ObjectKind", ",", "UserTypeKind", ",", "MediaTypeKind", ":", "return", "reflect", ".", "TypeOf", "(", "map", "[", "string", "]", "interface", "{", "}", "{", "}", ")", "\n", "case", "ArrayKind", ":", "return", "reflect", ".", "SliceOf", "(", "toReflectType", "(", "dtype", ".", "ToArray", "(", ")", ".", "ElemType", ".", "Type", ")", ")", "\n", "case", "HashKind", ":", "hash", ":=", "dtype", ".", "ToHash", "(", ")", "\n", "// avoid complication: not allow object as the hash key", "var", "ktype", "reflect", ".", "Type", "\n", "if", "!", "hash", ".", "KeyType", ".", "Type", ".", "IsObject", "(", ")", "{", "ktype", "=", "toReflectType", "(", "hash", ".", "KeyType", ".", "Type", ")", "\n", "}", "else", "{", "ktype", "=", "reflect", ".", "TypeOf", "(", "[", "]", "interface", "{", "}", "{", "}", ")", ".", "Elem", "(", ")", "\n", "}", "\n", "return", "reflect", ".", "MapOf", "(", "ktype", ",", "toReflectType", "(", "hash", ".", "ElemType", ".", "Type", ")", ")", "\n", "default", ":", "return", "reflect", ".", "TypeOf", "(", "[", "]", "interface", "{", "}", "{", "}", ")", ".", "Elem", "(", ")", "\n", "}", "\n", "}" ]
// toReflectType converts the DataType to reflect.Type.
[ "toReflectType", "converts", "the", "DataType", "to", "reflect", ".", "Type", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/types.go#L1075-L1104
166,663
goadesign/goa
logging/logrus/adapter.go
New
func New(logger *logrus.Logger) goa.LogAdapter { return FromEntry(logrus.NewEntry(logger)) }
go
func New(logger *logrus.Logger) goa.LogAdapter { return FromEntry(logrus.NewEntry(logger)) }
[ "func", "New", "(", "logger", "*", "logrus", ".", "Logger", ")", "goa", ".", "LogAdapter", "{", "return", "FromEntry", "(", "logrus", ".", "NewEntry", "(", "logger", ")", ")", "\n", "}" ]
// New wraps a logrus logger into a goa logger.
[ "New", "wraps", "a", "logrus", "logger", "into", "a", "goa", "logger", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/logging/logrus/adapter.go#L31-L33
166,664
goadesign/goa
logging/logrus/adapter.go
Entry
func Entry(ctx context.Context) *logrus.Entry { logger := goa.ContextLogger(ctx) if a, ok := logger.(*adapter); ok { return a.Entry } return nil }
go
func Entry(ctx context.Context) *logrus.Entry { logger := goa.ContextLogger(ctx) if a, ok := logger.(*adapter); ok { return a.Entry } return nil }
[ "func", "Entry", "(", "ctx", "context", ".", "Context", ")", "*", "logrus", ".", "Entry", "{", "logger", ":=", "goa", ".", "ContextLogger", "(", "ctx", ")", "\n", "if", "a", ",", "ok", ":=", "logger", ".", "(", "*", "adapter", ")", ";", "ok", "{", "return", "a", ".", "Entry", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Entry returns the logrus log entry stored in the given context if any, nil otherwise.
[ "Entry", "returns", "the", "logrus", "log", "entry", "stored", "in", "the", "given", "context", "if", "any", "nil", "otherwise", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/logging/logrus/adapter.go#L41-L47
166,665
goadesign/goa
logging/logrus/adapter.go
Info
func (a *adapter) Info(msg string, data ...interface{}) { a.Entry.WithFields(data2rus(data)).Info(msg) }
go
func (a *adapter) Info(msg string, data ...interface{}) { a.Entry.WithFields(data2rus(data)).Info(msg) }
[ "func", "(", "a", "*", "adapter", ")", "Info", "(", "msg", "string", ",", "data", "...", "interface", "{", "}", ")", "{", "a", ".", "Entry", ".", "WithFields", "(", "data2rus", "(", "data", ")", ")", ".", "Info", "(", "msg", ")", "\n", "}" ]
// Info logs messages using logrus.
[ "Info", "logs", "messages", "using", "logrus", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/logging/logrus/adapter.go#L50-L52
166,666
goadesign/goa
middleware/recover.go
Recover
func Recover() goa.Middleware { return func(h goa.Handler) goa.Handler { return func(ctx context.Context, rw http.ResponseWriter, req *http.Request) (err error) { defer func() { if r := recover(); r != nil { var msg string switch x := r.(type) { case string: msg = fmt.Sprintf("panic: %s", x) case error: msg = fmt.Sprintf("panic: %s", x) default: msg = "unknown panic" } const size = 64 << 10 // 64KB buf := make([]byte, size) buf = buf[:runtime.Stack(buf, false)] lines := strings.Split(string(buf), "\n") stack := lines[3:] err = fmt.Errorf("%s\n%s", msg, strings.Join(stack, "\n")) } }() return h(ctx, rw, req) } } }
go
func Recover() goa.Middleware { return func(h goa.Handler) goa.Handler { return func(ctx context.Context, rw http.ResponseWriter, req *http.Request) (err error) { defer func() { if r := recover(); r != nil { var msg string switch x := r.(type) { case string: msg = fmt.Sprintf("panic: %s", x) case error: msg = fmt.Sprintf("panic: %s", x) default: msg = "unknown panic" } const size = 64 << 10 // 64KB buf := make([]byte, size) buf = buf[:runtime.Stack(buf, false)] lines := strings.Split(string(buf), "\n") stack := lines[3:] err = fmt.Errorf("%s\n%s", msg, strings.Join(stack, "\n")) } }() return h(ctx, rw, req) } } }
[ "func", "Recover", "(", ")", "goa", ".", "Middleware", "{", "return", "func", "(", "h", "goa", ".", "Handler", ")", "goa", ".", "Handler", "{", "return", "func", "(", "ctx", "context", ".", "Context", ",", "rw", "http", ".", "ResponseWriter", ",", "req", "*", "http", ".", "Request", ")", "(", "err", "error", ")", "{", "defer", "func", "(", ")", "{", "if", "r", ":=", "recover", "(", ")", ";", "r", "!=", "nil", "{", "var", "msg", "string", "\n", "switch", "x", ":=", "r", ".", "(", "type", ")", "{", "case", "string", ":", "msg", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "x", ")", "\n", "case", "error", ":", "msg", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "x", ")", "\n", "default", ":", "msg", "=", "\"", "\"", "\n", "}", "\n", "const", "size", "=", "64", "<<", "10", "// 64KB", "\n", "buf", ":=", "make", "(", "[", "]", "byte", ",", "size", ")", "\n", "buf", "=", "buf", "[", ":", "runtime", ".", "Stack", "(", "buf", ",", "false", ")", "]", "\n", "lines", ":=", "strings", ".", "Split", "(", "string", "(", "buf", ")", ",", "\"", "\\n", "\"", ")", "\n", "stack", ":=", "lines", "[", "3", ":", "]", "\n", "err", "=", "fmt", ".", "Errorf", "(", "\"", "\\n", "\"", ",", "msg", ",", "strings", ".", "Join", "(", "stack", ",", "\"", "\\n", "\"", ")", ")", "\n", "}", "\n", "}", "(", ")", "\n", "return", "h", "(", "ctx", ",", "rw", ",", "req", ")", "\n", "}", "\n", "}", "\n", "}" ]
// Recover is a middleware that recovers panics and maps them to errors.
[ "Recover", "is", "a", "middleware", "that", "recovers", "panics", "and", "maps", "them", "to", "errors", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/middleware/recover.go#L15-L40
166,667
goadesign/goa
goagen/gen_js/options.go
API
func API(API *design.APIDefinition) Option { return func(g *Generator) { g.API = API } }
go
func API(API *design.APIDefinition) Option { return func(g *Generator) { g.API = API } }
[ "func", "API", "(", "API", "*", "design", ".", "APIDefinition", ")", "Option", "{", "return", "func", "(", "g", "*", "Generator", ")", "{", "g", ".", "API", "=", "API", "\n", "}", "\n", "}" ]
//API The API definition
[ "API", "The", "API", "definition" ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/goagen/gen_js/options.go#L10-L14
166,668
goadesign/goa
goagen/gen_js/options.go
Timeout
func Timeout(timeout time.Duration) Option { return func(g *Generator) { g.Timeout = timeout } }
go
func Timeout(timeout time.Duration) Option { return func(g *Generator) { g.Timeout = timeout } }
[ "func", "Timeout", "(", "timeout", "time", ".", "Duration", ")", "Option", "{", "return", "func", "(", "g", "*", "Generator", ")", "{", "g", ".", "Timeout", "=", "timeout", "\n", "}", "\n", "}" ]
//Timeout Timeout used by JavaScript client when making requests
[ "Timeout", "Timeout", "used", "by", "JavaScript", "client", "when", "making", "requests" ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/goagen/gen_js/options.go#L24-L28
166,669
goadesign/goa
metrics.go
NewMetrics
func NewMetrics(conf *metrics.Config, sink metrics.MetricSink) (err error) { m, err := metrics.NewGlobal(conf, sink) SetMetrics(m) return nil }
go
func NewMetrics(conf *metrics.Config, sink metrics.MetricSink) (err error) { m, err := metrics.NewGlobal(conf, sink) SetMetrics(m) return nil }
[ "func", "NewMetrics", "(", "conf", "*", "metrics", ".", "Config", ",", "sink", "metrics", ".", "MetricSink", ")", "(", "err", "error", ")", "{", "m", ",", "err", ":=", "metrics", ".", "NewGlobal", "(", "conf", ",", "sink", ")", "\n", "SetMetrics", "(", "m", ")", "\n\n", "return", "nil", "\n", "}" ]
// NewMetrics initializes goa's metrics instance with the supplied // configuration and metrics sink // This method is deprecated and SetMetrics should be used instead.
[ "NewMetrics", "initializes", "goa", "s", "metrics", "instance", "with", "the", "supplied", "configuration", "and", "metrics", "sink", "This", "method", "is", "deprecated", "and", "SetMetrics", "should", "be", "used", "instead", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/metrics.go#L80-L85
166,670
goadesign/goa
design/definitions.go
NewAPIDefinition
func NewAPIDefinition() *APIDefinition { api := &APIDefinition{ DefaultResponseTemplates: make(map[string]*ResponseTemplateDefinition), DefaultResponses: make(map[string]*ResponseDefinition), } t := func(params ...string) *ResponseDefinition { if len(params) < 1 { dslengine.ReportError("expected media type as argument when invoking response template OK") return nil } return &ResponseDefinition{ Name: OK, Status: 200, MediaType: params[0], } } api.DefaultResponseTemplates[OK] = &ResponseTemplateDefinition{ Name: OK, Template: t, } for _, p := range []struct { status int name string }{ {100, Continue}, {101, SwitchingProtocols}, {200, OK}, {201, Created}, {202, Accepted}, {203, NonAuthoritativeInfo}, {204, NoContent}, {205, ResetContent}, {206, PartialContent}, {300, MultipleChoices}, {301, MovedPermanently}, {302, Found}, {303, SeeOther}, {304, NotModified}, {305, UseProxy}, {307, TemporaryRedirect}, {400, BadRequest}, {401, Unauthorized}, {402, PaymentRequired}, {403, Forbidden}, {404, NotFound}, {405, MethodNotAllowed}, {406, NotAcceptable}, {407, ProxyAuthRequired}, {408, RequestTimeout}, {409, Conflict}, {410, Gone}, {411, LengthRequired}, {412, PreconditionFailed}, {413, RequestEntityTooLarge}, {414, RequestURITooLong}, {415, UnsupportedMediaType}, {416, RequestedRangeNotSatisfiable}, {417, ExpectationFailed}, {418, Teapot}, {422, UnprocessableEntity}, {500, InternalServerError}, {501, NotImplemented}, {502, BadGateway}, {503, ServiceUnavailable}, {504, GatewayTimeout}, {505, HTTPVersionNotSupported}, } { api.DefaultResponses[p.name] = &ResponseDefinition{ Name: p.name, Description: http.StatusText(p.status), Status: p.status, } } return api }
go
func NewAPIDefinition() *APIDefinition { api := &APIDefinition{ DefaultResponseTemplates: make(map[string]*ResponseTemplateDefinition), DefaultResponses: make(map[string]*ResponseDefinition), } t := func(params ...string) *ResponseDefinition { if len(params) < 1 { dslengine.ReportError("expected media type as argument when invoking response template OK") return nil } return &ResponseDefinition{ Name: OK, Status: 200, MediaType: params[0], } } api.DefaultResponseTemplates[OK] = &ResponseTemplateDefinition{ Name: OK, Template: t, } for _, p := range []struct { status int name string }{ {100, Continue}, {101, SwitchingProtocols}, {200, OK}, {201, Created}, {202, Accepted}, {203, NonAuthoritativeInfo}, {204, NoContent}, {205, ResetContent}, {206, PartialContent}, {300, MultipleChoices}, {301, MovedPermanently}, {302, Found}, {303, SeeOther}, {304, NotModified}, {305, UseProxy}, {307, TemporaryRedirect}, {400, BadRequest}, {401, Unauthorized}, {402, PaymentRequired}, {403, Forbidden}, {404, NotFound}, {405, MethodNotAllowed}, {406, NotAcceptable}, {407, ProxyAuthRequired}, {408, RequestTimeout}, {409, Conflict}, {410, Gone}, {411, LengthRequired}, {412, PreconditionFailed}, {413, RequestEntityTooLarge}, {414, RequestURITooLong}, {415, UnsupportedMediaType}, {416, RequestedRangeNotSatisfiable}, {417, ExpectationFailed}, {418, Teapot}, {422, UnprocessableEntity}, {500, InternalServerError}, {501, NotImplemented}, {502, BadGateway}, {503, ServiceUnavailable}, {504, GatewayTimeout}, {505, HTTPVersionNotSupported}, } { api.DefaultResponses[p.name] = &ResponseDefinition{ Name: p.name, Description: http.StatusText(p.status), Status: p.status, } } return api }
[ "func", "NewAPIDefinition", "(", ")", "*", "APIDefinition", "{", "api", ":=", "&", "APIDefinition", "{", "DefaultResponseTemplates", ":", "make", "(", "map", "[", "string", "]", "*", "ResponseTemplateDefinition", ")", ",", "DefaultResponses", ":", "make", "(", "map", "[", "string", "]", "*", "ResponseDefinition", ")", ",", "}", "\n", "t", ":=", "func", "(", "params", "...", "string", ")", "*", "ResponseDefinition", "{", "if", "len", "(", "params", ")", "<", "1", "{", "dslengine", ".", "ReportError", "(", "\"", "\"", ")", "\n", "return", "nil", "\n", "}", "\n", "return", "&", "ResponseDefinition", "{", "Name", ":", "OK", ",", "Status", ":", "200", ",", "MediaType", ":", "params", "[", "0", "]", ",", "}", "\n", "}", "\n", "api", ".", "DefaultResponseTemplates", "[", "OK", "]", "=", "&", "ResponseTemplateDefinition", "{", "Name", ":", "OK", ",", "Template", ":", "t", ",", "}", "\n", "for", "_", ",", "p", ":=", "range", "[", "]", "struct", "{", "status", "int", "\n", "name", "string", "\n", "}", "{", "{", "100", ",", "Continue", "}", ",", "{", "101", ",", "SwitchingProtocols", "}", ",", "{", "200", ",", "OK", "}", ",", "{", "201", ",", "Created", "}", ",", "{", "202", ",", "Accepted", "}", ",", "{", "203", ",", "NonAuthoritativeInfo", "}", ",", "{", "204", ",", "NoContent", "}", ",", "{", "205", ",", "ResetContent", "}", ",", "{", "206", ",", "PartialContent", "}", ",", "{", "300", ",", "MultipleChoices", "}", ",", "{", "301", ",", "MovedPermanently", "}", ",", "{", "302", ",", "Found", "}", ",", "{", "303", ",", "SeeOther", "}", ",", "{", "304", ",", "NotModified", "}", ",", "{", "305", ",", "UseProxy", "}", ",", "{", "307", ",", "TemporaryRedirect", "}", ",", "{", "400", ",", "BadRequest", "}", ",", "{", "401", ",", "Unauthorized", "}", ",", "{", "402", ",", "PaymentRequired", "}", ",", "{", "403", ",", "Forbidden", "}", ",", "{", "404", ",", "NotFound", "}", ",", "{", "405", ",", "MethodNotAllowed", "}", ",", "{", "406", ",", "NotAcceptable", "}", ",", "{", "407", ",", "ProxyAuthRequired", "}", ",", "{", "408", ",", "RequestTimeout", "}", ",", "{", "409", ",", "Conflict", "}", ",", "{", "410", ",", "Gone", "}", ",", "{", "411", ",", "LengthRequired", "}", ",", "{", "412", ",", "PreconditionFailed", "}", ",", "{", "413", ",", "RequestEntityTooLarge", "}", ",", "{", "414", ",", "RequestURITooLong", "}", ",", "{", "415", ",", "UnsupportedMediaType", "}", ",", "{", "416", ",", "RequestedRangeNotSatisfiable", "}", ",", "{", "417", ",", "ExpectationFailed", "}", ",", "{", "418", ",", "Teapot", "}", ",", "{", "422", ",", "UnprocessableEntity", "}", ",", "{", "500", ",", "InternalServerError", "}", ",", "{", "501", ",", "NotImplemented", "}", ",", "{", "502", ",", "BadGateway", "}", ",", "{", "503", ",", "ServiceUnavailable", "}", ",", "{", "504", ",", "GatewayTimeout", "}", ",", "{", "505", ",", "HTTPVersionNotSupported", "}", ",", "}", "{", "api", ".", "DefaultResponses", "[", "p", ".", "name", "]", "=", "&", "ResponseDefinition", "{", "Name", ":", "p", ".", "name", ",", "Description", ":", "http", ".", "StatusText", "(", "p", ".", "status", ")", ",", "Status", ":", "p", ".", "status", ",", "}", "\n", "}", "\n", "return", "api", "\n", "}" ]
// NewAPIDefinition returns a new design with built-in response templates.
[ "NewAPIDefinition", "returns", "a", "new", "design", "with", "built", "-", "in", "response", "templates", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/definitions.go#L370-L444
166,671
goadesign/goa
design/definitions.go
IterateSets
func (a *APIDefinition) IterateSets(iterator dslengine.SetIterator) { // First run the top level API DSL to initialize responses and // response templates needed by resources. iterator([]dslengine.Definition{a}) // Then run the user type DSLs typeAttributes := make([]dslengine.Definition, len(a.Types)) i := 0 a.IterateUserTypes(func(u *UserTypeDefinition) error { u.AttributeDefinition.DSLFunc = u.DSLFunc typeAttributes[i] = u.AttributeDefinition i++ return nil }) iterator(typeAttributes) // Then the media type DSLs mediaTypes := make([]dslengine.Definition, len(a.MediaTypes)) i = 0 a.IterateMediaTypes(func(mt *MediaTypeDefinition) error { mediaTypes[i] = mt i++ return nil }) iterator(mediaTypes) // Then, the Security schemes definitions var securitySchemes []dslengine.Definition for _, scheme := range a.SecuritySchemes { securitySchemes = append(securitySchemes, dslengine.Definition(scheme)) } iterator(securitySchemes) // And now that we have everything - the resources. The resource // lifecycle handlers dispatch to their children elements, like Actions, // etc.. We must process parent resources first to ensure that query // string and path parameters are initialized by the time a child // resource action parameters are categorized. resources := make([]*ResourceDefinition, len(a.Resources)) i = 0 a.IterateResources(func(res *ResourceDefinition) error { resources[i] = res i++ return nil }) sort.Sort(byParent(resources)) defs := make([]dslengine.Definition, len(resources)) for i, r := range resources { defs[i] = r } iterator(defs) }
go
func (a *APIDefinition) IterateSets(iterator dslengine.SetIterator) { // First run the top level API DSL to initialize responses and // response templates needed by resources. iterator([]dslengine.Definition{a}) // Then run the user type DSLs typeAttributes := make([]dslengine.Definition, len(a.Types)) i := 0 a.IterateUserTypes(func(u *UserTypeDefinition) error { u.AttributeDefinition.DSLFunc = u.DSLFunc typeAttributes[i] = u.AttributeDefinition i++ return nil }) iterator(typeAttributes) // Then the media type DSLs mediaTypes := make([]dslengine.Definition, len(a.MediaTypes)) i = 0 a.IterateMediaTypes(func(mt *MediaTypeDefinition) error { mediaTypes[i] = mt i++ return nil }) iterator(mediaTypes) // Then, the Security schemes definitions var securitySchemes []dslengine.Definition for _, scheme := range a.SecuritySchemes { securitySchemes = append(securitySchemes, dslengine.Definition(scheme)) } iterator(securitySchemes) // And now that we have everything - the resources. The resource // lifecycle handlers dispatch to their children elements, like Actions, // etc.. We must process parent resources first to ensure that query // string and path parameters are initialized by the time a child // resource action parameters are categorized. resources := make([]*ResourceDefinition, len(a.Resources)) i = 0 a.IterateResources(func(res *ResourceDefinition) error { resources[i] = res i++ return nil }) sort.Sort(byParent(resources)) defs := make([]dslengine.Definition, len(resources)) for i, r := range resources { defs[i] = r } iterator(defs) }
[ "func", "(", "a", "*", "APIDefinition", ")", "IterateSets", "(", "iterator", "dslengine", ".", "SetIterator", ")", "{", "// First run the top level API DSL to initialize responses and", "// response templates needed by resources.", "iterator", "(", "[", "]", "dslengine", ".", "Definition", "{", "a", "}", ")", "\n\n", "// Then run the user type DSLs", "typeAttributes", ":=", "make", "(", "[", "]", "dslengine", ".", "Definition", ",", "len", "(", "a", ".", "Types", ")", ")", "\n", "i", ":=", "0", "\n", "a", ".", "IterateUserTypes", "(", "func", "(", "u", "*", "UserTypeDefinition", ")", "error", "{", "u", ".", "AttributeDefinition", ".", "DSLFunc", "=", "u", ".", "DSLFunc", "\n", "typeAttributes", "[", "i", "]", "=", "u", ".", "AttributeDefinition", "\n", "i", "++", "\n", "return", "nil", "\n", "}", ")", "\n", "iterator", "(", "typeAttributes", ")", "\n\n", "// Then the media type DSLs", "mediaTypes", ":=", "make", "(", "[", "]", "dslengine", ".", "Definition", ",", "len", "(", "a", ".", "MediaTypes", ")", ")", "\n", "i", "=", "0", "\n", "a", ".", "IterateMediaTypes", "(", "func", "(", "mt", "*", "MediaTypeDefinition", ")", "error", "{", "mediaTypes", "[", "i", "]", "=", "mt", "\n", "i", "++", "\n", "return", "nil", "\n", "}", ")", "\n", "iterator", "(", "mediaTypes", ")", "\n\n", "// Then, the Security schemes definitions", "var", "securitySchemes", "[", "]", "dslengine", ".", "Definition", "\n", "for", "_", ",", "scheme", ":=", "range", "a", ".", "SecuritySchemes", "{", "securitySchemes", "=", "append", "(", "securitySchemes", ",", "dslengine", ".", "Definition", "(", "scheme", ")", ")", "\n", "}", "\n", "iterator", "(", "securitySchemes", ")", "\n\n", "// And now that we have everything - the resources. The resource", "// lifecycle handlers dispatch to their children elements, like Actions,", "// etc.. We must process parent resources first to ensure that query", "// string and path parameters are initialized by the time a child", "// resource action parameters are categorized.", "resources", ":=", "make", "(", "[", "]", "*", "ResourceDefinition", ",", "len", "(", "a", ".", "Resources", ")", ")", "\n", "i", "=", "0", "\n", "a", ".", "IterateResources", "(", "func", "(", "res", "*", "ResourceDefinition", ")", "error", "{", "resources", "[", "i", "]", "=", "res", "\n", "i", "++", "\n", "return", "nil", "\n", "}", ")", "\n", "sort", ".", "Sort", "(", "byParent", "(", "resources", ")", ")", "\n", "defs", ":=", "make", "(", "[", "]", "dslengine", ".", "Definition", ",", "len", "(", "resources", ")", ")", "\n", "for", "i", ",", "r", ":=", "range", "resources", "{", "defs", "[", "i", "]", "=", "r", "\n", "}", "\n", "iterator", "(", "defs", ")", "\n", "}" ]
// IterateSets calls the given iterator possing in the API definition, user types, media types and // finally resources.
[ "IterateSets", "calls", "the", "given", "iterator", "possing", "in", "the", "API", "definition", "user", "types", "media", "types", "and", "finally", "resources", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/definitions.go#L458-L509
166,672
goadesign/goa
design/definitions.go
PathParams
func (a *APIDefinition) PathParams() *AttributeDefinition { names := ExtractWildcards(a.BasePath) obj := make(Object) for _, n := range names { obj[n] = a.Params.Type.ToObject()[n] } return &AttributeDefinition{Type: obj} }
go
func (a *APIDefinition) PathParams() *AttributeDefinition { names := ExtractWildcards(a.BasePath) obj := make(Object) for _, n := range names { obj[n] = a.Params.Type.ToObject()[n] } return &AttributeDefinition{Type: obj} }
[ "func", "(", "a", "*", "APIDefinition", ")", "PathParams", "(", ")", "*", "AttributeDefinition", "{", "names", ":=", "ExtractWildcards", "(", "a", ".", "BasePath", ")", "\n", "obj", ":=", "make", "(", "Object", ")", "\n", "for", "_", ",", "n", ":=", "range", "names", "{", "obj", "[", "n", "]", "=", "a", ".", "Params", ".", "Type", ".", "ToObject", "(", ")", "[", "n", "]", "\n", "}", "\n", "return", "&", "AttributeDefinition", "{", "Type", ":", "obj", "}", "\n", "}" ]
// PathParams returns the base path parameters of a.
[ "PathParams", "returns", "the", "base", "path", "parameters", "of", "a", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/definitions.go#L527-L534
166,673
goadesign/goa
design/definitions.go
IterateMediaTypes
func (a *APIDefinition) IterateMediaTypes(it MediaTypeIterator) error { names := make([]string, len(a.MediaTypes)) i := 0 for n := range a.MediaTypes { names[i] = n i++ } sort.Strings(names) for _, n := range names { if err := it(a.MediaTypes[n]); err != nil { return err } } return nil }
go
func (a *APIDefinition) IterateMediaTypes(it MediaTypeIterator) error { names := make([]string, len(a.MediaTypes)) i := 0 for n := range a.MediaTypes { names[i] = n i++ } sort.Strings(names) for _, n := range names { if err := it(a.MediaTypes[n]); err != nil { return err } } return nil }
[ "func", "(", "a", "*", "APIDefinition", ")", "IterateMediaTypes", "(", "it", "MediaTypeIterator", ")", "error", "{", "names", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "a", ".", "MediaTypes", ")", ")", "\n", "i", ":=", "0", "\n", "for", "n", ":=", "range", "a", ".", "MediaTypes", "{", "names", "[", "i", "]", "=", "n", "\n", "i", "++", "\n", "}", "\n", "sort", ".", "Strings", "(", "names", ")", "\n", "for", "_", ",", "n", ":=", "range", "names", "{", "if", "err", ":=", "it", "(", "a", ".", "MediaTypes", "[", "n", "]", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// IterateMediaTypes calls the given iterator passing in each media type sorted in alphabetical order. // Iteration stops if an iterator returns an error and in this case IterateMediaTypes returns that // error.
[ "IterateMediaTypes", "calls", "the", "given", "iterator", "passing", "in", "each", "media", "type", "sorted", "in", "alphabetical", "order", ".", "Iteration", "stops", "if", "an", "iterator", "returns", "an", "error", "and", "in", "this", "case", "IterateMediaTypes", "returns", "that", "error", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/definitions.go#L539-L553
166,674
goadesign/goa
design/definitions.go
IterateUserTypes
func (a *APIDefinition) IterateUserTypes(it UserTypeIterator) error { names := make([]string, len(a.Types)) i := 0 for n := range a.Types { names[i] = n i++ } sort.Strings(names) for _, n := range names { if err := it(a.Types[n]); err != nil { return err } } return nil }
go
func (a *APIDefinition) IterateUserTypes(it UserTypeIterator) error { names := make([]string, len(a.Types)) i := 0 for n := range a.Types { names[i] = n i++ } sort.Strings(names) for _, n := range names { if err := it(a.Types[n]); err != nil { return err } } return nil }
[ "func", "(", "a", "*", "APIDefinition", ")", "IterateUserTypes", "(", "it", "UserTypeIterator", ")", "error", "{", "names", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "a", ".", "Types", ")", ")", "\n", "i", ":=", "0", "\n", "for", "n", ":=", "range", "a", ".", "Types", "{", "names", "[", "i", "]", "=", "n", "\n", "i", "++", "\n", "}", "\n", "sort", ".", "Strings", "(", "names", ")", "\n", "for", "_", ",", "n", ":=", "range", "names", "{", "if", "err", ":=", "it", "(", "a", ".", "Types", "[", "n", "]", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// IterateUserTypes calls the given iterator passing in each user type sorted in alphabetical order. // Iteration stops if an iterator returns an error and in this case IterateUserTypes returns that // error.
[ "IterateUserTypes", "calls", "the", "given", "iterator", "passing", "in", "each", "user", "type", "sorted", "in", "alphabetical", "order", ".", "Iteration", "stops", "if", "an", "iterator", "returns", "an", "error", "and", "in", "this", "case", "IterateUserTypes", "returns", "that", "error", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/definitions.go#L558-L572
166,675
goadesign/goa
design/definitions.go
IterateResponses
func (a *APIDefinition) IterateResponses(it ResponseIterator) error { names := make([]string, len(a.Responses)) i := 0 for n := range a.Responses { names[i] = n i++ } sort.Strings(names) for _, n := range names { if err := it(a.Responses[n]); err != nil { return err } } return nil }
go
func (a *APIDefinition) IterateResponses(it ResponseIterator) error { names := make([]string, len(a.Responses)) i := 0 for n := range a.Responses { names[i] = n i++ } sort.Strings(names) for _, n := range names { if err := it(a.Responses[n]); err != nil { return err } } return nil }
[ "func", "(", "a", "*", "APIDefinition", ")", "IterateResponses", "(", "it", "ResponseIterator", ")", "error", "{", "names", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "a", ".", "Responses", ")", ")", "\n", "i", ":=", "0", "\n", "for", "n", ":=", "range", "a", ".", "Responses", "{", "names", "[", "i", "]", "=", "n", "\n", "i", "++", "\n", "}", "\n", "sort", ".", "Strings", "(", "names", ")", "\n", "for", "_", ",", "n", ":=", "range", "names", "{", "if", "err", ":=", "it", "(", "a", ".", "Responses", "[", "n", "]", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// IterateResponses calls the given iterator passing in each response sorted in alphabetical order. // Iteration stops if an iterator returns an error and in this case IterateResponses returns that // error.
[ "IterateResponses", "calls", "the", "given", "iterator", "passing", "in", "each", "response", "sorted", "in", "alphabetical", "order", ".", "Iteration", "stops", "if", "an", "iterator", "returns", "an", "error", "and", "in", "this", "case", "IterateResponses", "returns", "that", "error", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/definitions.go#L577-L591
166,676
goadesign/goa
design/definitions.go
RandomGenerator
func (a *APIDefinition) RandomGenerator() *RandomGenerator { if a.rand == nil { a.rand = NewRandomGenerator(a.Name) } return a.rand }
go
func (a *APIDefinition) RandomGenerator() *RandomGenerator { if a.rand == nil { a.rand = NewRandomGenerator(a.Name) } return a.rand }
[ "func", "(", "a", "*", "APIDefinition", ")", "RandomGenerator", "(", ")", "*", "RandomGenerator", "{", "if", "a", ".", "rand", "==", "nil", "{", "a", ".", "rand", "=", "NewRandomGenerator", "(", "a", ".", "Name", ")", "\n", "}", "\n", "return", "a", ".", "rand", "\n", "}" ]
// RandomGenerator is seeded after the API name. It's used to generate examples.
[ "RandomGenerator", "is", "seeded", "after", "the", "API", "name", ".", "It", "s", "used", "to", "generate", "examples", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/definitions.go#L594-L599
166,677
goadesign/goa
design/definitions.go
IterateResources
func (a *APIDefinition) IterateResources(it ResourceIterator) error { res := make([]*ResourceDefinition, len(a.Resources)) i := 0 for _, r := range a.Resources { res[i] = r i++ } // Iterate parent resources first so that action parameters are // finalized prior to child actions needing them. isParent := func(p, c *ResourceDefinition) bool { par := c.Parent() for par != nil { if par == p { return true } par = par.Parent() } return false } sort.Slice(res, func(i, j int) bool { if isParent(res[i], res[j]) { return true } if isParent(res[j], res[i]) { return false } return res[i].Name < res[j].Name }) for _, r := range res { if err := it(r); err != nil { return err } } return nil }
go
func (a *APIDefinition) IterateResources(it ResourceIterator) error { res := make([]*ResourceDefinition, len(a.Resources)) i := 0 for _, r := range a.Resources { res[i] = r i++ } // Iterate parent resources first so that action parameters are // finalized prior to child actions needing them. isParent := func(p, c *ResourceDefinition) bool { par := c.Parent() for par != nil { if par == p { return true } par = par.Parent() } return false } sort.Slice(res, func(i, j int) bool { if isParent(res[i], res[j]) { return true } if isParent(res[j], res[i]) { return false } return res[i].Name < res[j].Name }) for _, r := range res { if err := it(r); err != nil { return err } } return nil }
[ "func", "(", "a", "*", "APIDefinition", ")", "IterateResources", "(", "it", "ResourceIterator", ")", "error", "{", "res", ":=", "make", "(", "[", "]", "*", "ResourceDefinition", ",", "len", "(", "a", ".", "Resources", ")", ")", "\n", "i", ":=", "0", "\n", "for", "_", ",", "r", ":=", "range", "a", ".", "Resources", "{", "res", "[", "i", "]", "=", "r", "\n", "i", "++", "\n", "}", "\n", "// Iterate parent resources first so that action parameters are", "// finalized prior to child actions needing them.", "isParent", ":=", "func", "(", "p", ",", "c", "*", "ResourceDefinition", ")", "bool", "{", "par", ":=", "c", ".", "Parent", "(", ")", "\n", "for", "par", "!=", "nil", "{", "if", "par", "==", "p", "{", "return", "true", "\n", "}", "\n", "par", "=", "par", ".", "Parent", "(", ")", "\n", "}", "\n", "return", "false", "\n", "}", "\n", "sort", ".", "Slice", "(", "res", ",", "func", "(", "i", ",", "j", "int", ")", "bool", "{", "if", "isParent", "(", "res", "[", "i", "]", ",", "res", "[", "j", "]", ")", "{", "return", "true", "\n", "}", "\n", "if", "isParent", "(", "res", "[", "j", "]", ",", "res", "[", "i", "]", ")", "{", "return", "false", "\n", "}", "\n", "return", "res", "[", "i", "]", ".", "Name", "<", "res", "[", "j", "]", ".", "Name", "\n", "}", ")", "\n", "for", "_", ",", "r", ":=", "range", "res", "{", "if", "err", ":=", "it", "(", "r", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// IterateResources calls the given iterator passing in each resource sorted in alphabetical order. // Iteration stops if an iterator returns an error and in this case IterateResources returns that // error.
[ "IterateResources", "calls", "the", "given", "iterator", "passing", "in", "each", "resource", "sorted", "in", "alphabetical", "order", ".", "Iteration", "stops", "if", "an", "iterator", "returns", "an", "error", "and", "in", "this", "case", "IterateResources", "returns", "that", "error", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/definitions.go#L618-L652
166,678
goadesign/goa
design/definitions.go
Finalize
func (a *APIDefinition) Finalize() { if len(a.Consumes) == 0 { a.Consumes = DefaultDecoders } if len(a.Produces) == 0 { a.Produces = DefaultEncoders } a.IterateResources(func(r *ResourceDefinition) error { returnsError := func(resp *ResponseDefinition) bool { if resp.MediaType == ErrorMediaIdentifier { if a.MediaTypes == nil { a.MediaTypes = make(map[string]*MediaTypeDefinition) } a.MediaTypes[CanonicalIdentifier(ErrorMediaIdentifier)] = ErrorMedia return true } return false } for _, resp := range a.Responses { if returnsError(resp) { return errors.New("done") } } for _, resp := range r.Responses { if returnsError(resp) { return errors.New("done") } } return r.IterateActions(func(action *ActionDefinition) error { for _, resp := range action.Responses { if returnsError(resp) { return errors.New("done") } } return nil }) }) }
go
func (a *APIDefinition) Finalize() { if len(a.Consumes) == 0 { a.Consumes = DefaultDecoders } if len(a.Produces) == 0 { a.Produces = DefaultEncoders } a.IterateResources(func(r *ResourceDefinition) error { returnsError := func(resp *ResponseDefinition) bool { if resp.MediaType == ErrorMediaIdentifier { if a.MediaTypes == nil { a.MediaTypes = make(map[string]*MediaTypeDefinition) } a.MediaTypes[CanonicalIdentifier(ErrorMediaIdentifier)] = ErrorMedia return true } return false } for _, resp := range a.Responses { if returnsError(resp) { return errors.New("done") } } for _, resp := range r.Responses { if returnsError(resp) { return errors.New("done") } } return r.IterateActions(func(action *ActionDefinition) error { for _, resp := range action.Responses { if returnsError(resp) { return errors.New("done") } } return nil }) }) }
[ "func", "(", "a", "*", "APIDefinition", ")", "Finalize", "(", ")", "{", "if", "len", "(", "a", ".", "Consumes", ")", "==", "0", "{", "a", ".", "Consumes", "=", "DefaultDecoders", "\n", "}", "\n", "if", "len", "(", "a", ".", "Produces", ")", "==", "0", "{", "a", ".", "Produces", "=", "DefaultEncoders", "\n", "}", "\n", "a", ".", "IterateResources", "(", "func", "(", "r", "*", "ResourceDefinition", ")", "error", "{", "returnsError", ":=", "func", "(", "resp", "*", "ResponseDefinition", ")", "bool", "{", "if", "resp", ".", "MediaType", "==", "ErrorMediaIdentifier", "{", "if", "a", ".", "MediaTypes", "==", "nil", "{", "a", ".", "MediaTypes", "=", "make", "(", "map", "[", "string", "]", "*", "MediaTypeDefinition", ")", "\n", "}", "\n", "a", ".", "MediaTypes", "[", "CanonicalIdentifier", "(", "ErrorMediaIdentifier", ")", "]", "=", "ErrorMedia", "\n", "return", "true", "\n", "}", "\n", "return", "false", "\n", "}", "\n", "for", "_", ",", "resp", ":=", "range", "a", ".", "Responses", "{", "if", "returnsError", "(", "resp", ")", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "}", "\n", "for", "_", ",", "resp", ":=", "range", "r", ".", "Responses", "{", "if", "returnsError", "(", "resp", ")", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "}", "\n", "return", "r", ".", "IterateActions", "(", "func", "(", "action", "*", "ActionDefinition", ")", "error", "{", "for", "_", ",", "resp", ":=", "range", "action", ".", "Responses", "{", "if", "returnsError", "(", "resp", ")", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}", ")", "\n", "}", ")", "\n", "}" ]
// Finalize sets the Consumes and Produces fields to the defaults if empty. // Also it records built-in media types that are used by the user design.
[ "Finalize", "sets", "the", "Consumes", "and", "Produces", "fields", "to", "the", "defaults", "if", "empty", ".", "Also", "it", "records", "built", "-", "in", "media", "types", "that", "are", "used", "by", "the", "user", "design", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/definitions.go#L661-L698
166,679
goadesign/goa
design/definitions.go
NewResourceDefinition
func NewResourceDefinition(name string, dsl func()) *ResourceDefinition { return &ResourceDefinition{ Name: name, MediaType: "text/plain", DSLFunc: dsl, } }
go
func NewResourceDefinition(name string, dsl func()) *ResourceDefinition { return &ResourceDefinition{ Name: name, MediaType: "text/plain", DSLFunc: dsl, } }
[ "func", "NewResourceDefinition", "(", "name", "string", ",", "dsl", "func", "(", ")", ")", "*", "ResourceDefinition", "{", "return", "&", "ResourceDefinition", "{", "Name", ":", "name", ",", "MediaType", ":", "\"", "\"", ",", "DSLFunc", ":", "dsl", ",", "}", "\n", "}" ]
// NewResourceDefinition creates a resource definition but does not // execute the DSL.
[ "NewResourceDefinition", "creates", "a", "resource", "definition", "but", "does", "not", "execute", "the", "DSL", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/definitions.go#L702-L708
166,680
goadesign/goa
design/definitions.go
PathParams
func (r *ResourceDefinition) PathParams() *AttributeDefinition { names := ExtractWildcards(r.BasePath) obj := make(Object) if r.Params != nil { for _, n := range names { if p, ok := r.Params.Type.ToObject()[n]; ok { obj[n] = p } } } return &AttributeDefinition{Type: obj} }
go
func (r *ResourceDefinition) PathParams() *AttributeDefinition { names := ExtractWildcards(r.BasePath) obj := make(Object) if r.Params != nil { for _, n := range names { if p, ok := r.Params.Type.ToObject()[n]; ok { obj[n] = p } } } return &AttributeDefinition{Type: obj} }
[ "func", "(", "r", "*", "ResourceDefinition", ")", "PathParams", "(", ")", "*", "AttributeDefinition", "{", "names", ":=", "ExtractWildcards", "(", "r", ".", "BasePath", ")", "\n", "obj", ":=", "make", "(", "Object", ")", "\n", "if", "r", ".", "Params", "!=", "nil", "{", "for", "_", ",", "n", ":=", "range", "names", "{", "if", "p", ",", "ok", ":=", "r", ".", "Params", ".", "Type", ".", "ToObject", "(", ")", "[", "n", "]", ";", "ok", "{", "obj", "[", "n", "]", "=", "p", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "&", "AttributeDefinition", "{", "Type", ":", "obj", "}", "\n", "}" ]
// PathParams returns the base path parameters of r.
[ "PathParams", "returns", "the", "base", "path", "parameters", "of", "r", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/definitions.go#L719-L730
166,681
goadesign/goa
design/definitions.go
IterateActions
func (r *ResourceDefinition) IterateActions(it ActionIterator) error { names := make([]string, len(r.Actions)) i := 0 for n := range r.Actions { names[i] = n i++ } sort.Strings(names) for _, n := range names { if err := it(r.Actions[n]); err != nil { return err } } return nil }
go
func (r *ResourceDefinition) IterateActions(it ActionIterator) error { names := make([]string, len(r.Actions)) i := 0 for n := range r.Actions { names[i] = n i++ } sort.Strings(names) for _, n := range names { if err := it(r.Actions[n]); err != nil { return err } } return nil }
[ "func", "(", "r", "*", "ResourceDefinition", ")", "IterateActions", "(", "it", "ActionIterator", ")", "error", "{", "names", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "r", ".", "Actions", ")", ")", "\n", "i", ":=", "0", "\n", "for", "n", ":=", "range", "r", ".", "Actions", "{", "names", "[", "i", "]", "=", "n", "\n", "i", "++", "\n", "}", "\n", "sort", ".", "Strings", "(", "names", ")", "\n", "for", "_", ",", "n", ":=", "range", "names", "{", "if", "err", ":=", "it", "(", "r", ".", "Actions", "[", "n", "]", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// IterateActions calls the given iterator passing in each resource action sorted in alphabetical order. // Iteration stops if an iterator returns an error and in this case IterateActions returns that // error.
[ "IterateActions", "calls", "the", "given", "iterator", "passing", "in", "each", "resource", "action", "sorted", "in", "alphabetical", "order", ".", "Iteration", "stops", "if", "an", "iterator", "returns", "an", "error", "and", "in", "this", "case", "IterateActions", "returns", "that", "error", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/definitions.go#L735-L749
166,682
goadesign/goa
design/definitions.go
IterateFileServers
func (r *ResourceDefinition) IterateFileServers(it FileServerIterator) error { sort.Sort(ByFilePath(r.FileServers)) for _, f := range r.FileServers { if err := it(f); err != nil { return err } } return nil }
go
func (r *ResourceDefinition) IterateFileServers(it FileServerIterator) error { sort.Sort(ByFilePath(r.FileServers)) for _, f := range r.FileServers { if err := it(f); err != nil { return err } } return nil }
[ "func", "(", "r", "*", "ResourceDefinition", ")", "IterateFileServers", "(", "it", "FileServerIterator", ")", "error", "{", "sort", ".", "Sort", "(", "ByFilePath", "(", "r", ".", "FileServers", ")", ")", "\n", "for", "_", ",", "f", ":=", "range", "r", ".", "FileServers", "{", "if", "err", ":=", "it", "(", "f", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// IterateFileServers calls the given iterator passing each resource file server sorted by file // path. Iteration stops if an iterator returns an error and in this case IterateFileServers returns // that error.
[ "IterateFileServers", "calls", "the", "given", "iterator", "passing", "each", "resource", "file", "server", "sorted", "by", "file", "path", ".", "Iteration", "stops", "if", "an", "iterator", "returns", "an", "error", "and", "in", "this", "case", "IterateFileServers", "returns", "that", "error", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/definitions.go#L754-L762
166,683
goadesign/goa
design/definitions.go
IterateHeaders
func (r *ResourceDefinition) IterateHeaders(it HeaderIterator) error { return iterateHeaders(r.Headers, r.Headers.IsRequired, it) }
go
func (r *ResourceDefinition) IterateHeaders(it HeaderIterator) error { return iterateHeaders(r.Headers, r.Headers.IsRequired, it) }
[ "func", "(", "r", "*", "ResourceDefinition", ")", "IterateHeaders", "(", "it", "HeaderIterator", ")", "error", "{", "return", "iterateHeaders", "(", "r", ".", "Headers", ",", "r", ".", "Headers", ".", "IsRequired", ",", "it", ")", "\n", "}" ]
// IterateHeaders calls the given iterator passing in each response sorted in alphabetical order. // Iteration stops if an iterator returns an error and in this case IterateHeaders returns that // error.
[ "IterateHeaders", "calls", "the", "given", "iterator", "passing", "in", "each", "response", "sorted", "in", "alphabetical", "order", ".", "Iteration", "stops", "if", "an", "iterator", "returns", "an", "error", "and", "in", "this", "case", "IterateHeaders", "returns", "that", "error", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/definitions.go#L767-L769
166,684
goadesign/goa
design/definitions.go
CanonicalAction
func (r *ResourceDefinition) CanonicalAction() *ActionDefinition { name := r.CanonicalActionName if name == "" { name = "show" } ca, _ := r.Actions[name] return ca }
go
func (r *ResourceDefinition) CanonicalAction() *ActionDefinition { name := r.CanonicalActionName if name == "" { name = "show" } ca, _ := r.Actions[name] return ca }
[ "func", "(", "r", "*", "ResourceDefinition", ")", "CanonicalAction", "(", ")", "*", "ActionDefinition", "{", "name", ":=", "r", ".", "CanonicalActionName", "\n", "if", "name", "==", "\"", "\"", "{", "name", "=", "\"", "\"", "\n", "}", "\n", "ca", ",", "_", ":=", "r", ".", "Actions", "[", "name", "]", "\n", "return", "ca", "\n", "}" ]
// CanonicalAction returns the canonical action of the resource if any. // The canonical action is used to compute hrefs to resources.
[ "CanonicalAction", "returns", "the", "canonical", "action", "of", "the", "resource", "if", "any", ".", "The", "canonical", "action", "is", "used", "to", "compute", "hrefs", "to", "resources", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/definitions.go#L773-L780
166,685
goadesign/goa
design/definitions.go
URITemplate
func (r *ResourceDefinition) URITemplate() string { ca := r.CanonicalAction() if ca == nil || len(ca.Routes) == 0 { return "" } return ca.Routes[0].FullPath() }
go
func (r *ResourceDefinition) URITemplate() string { ca := r.CanonicalAction() if ca == nil || len(ca.Routes) == 0 { return "" } return ca.Routes[0].FullPath() }
[ "func", "(", "r", "*", "ResourceDefinition", ")", "URITemplate", "(", ")", "string", "{", "ca", ":=", "r", ".", "CanonicalAction", "(", ")", "\n", "if", "ca", "==", "nil", "||", "len", "(", "ca", ".", "Routes", ")", "==", "0", "{", "return", "\"", "\"", "\n", "}", "\n", "return", "ca", ".", "Routes", "[", "0", "]", ".", "FullPath", "(", ")", "\n", "}" ]
// URITemplate returns a URI template to this resource. // The result is the empty string if the resource does not have a "show" action // and does not define a different canonical action.
[ "URITemplate", "returns", "a", "URI", "template", "to", "this", "resource", ".", "The", "result", "is", "the", "empty", "string", "if", "the", "resource", "does", "not", "have", "a", "show", "action", "and", "does", "not", "define", "a", "different", "canonical", "action", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/definitions.go#L785-L791
166,686
goadesign/goa
design/definitions.go
FullPath
func (r *ResourceDefinition) FullPath() string { if strings.HasPrefix(r.BasePath, "//") { return httppath.Clean(r.BasePath) } var basePath string if p := r.Parent(); p != nil { if ca := p.CanonicalAction(); ca != nil { if routes := ca.Routes; len(routes) > 0 { // Note: all these tests should be true at code generation time // as DSL validation makes sure that parent resources have a // canonical path. basePath = path.Join(routes[0].FullPath()) } } } else { basePath = Design.BasePath } return httppath.Clean(path.Join(basePath, r.BasePath)) }
go
func (r *ResourceDefinition) FullPath() string { if strings.HasPrefix(r.BasePath, "//") { return httppath.Clean(r.BasePath) } var basePath string if p := r.Parent(); p != nil { if ca := p.CanonicalAction(); ca != nil { if routes := ca.Routes; len(routes) > 0 { // Note: all these tests should be true at code generation time // as DSL validation makes sure that parent resources have a // canonical path. basePath = path.Join(routes[0].FullPath()) } } } else { basePath = Design.BasePath } return httppath.Clean(path.Join(basePath, r.BasePath)) }
[ "func", "(", "r", "*", "ResourceDefinition", ")", "FullPath", "(", ")", "string", "{", "if", "strings", ".", "HasPrefix", "(", "r", ".", "BasePath", ",", "\"", "\"", ")", "{", "return", "httppath", ".", "Clean", "(", "r", ".", "BasePath", ")", "\n", "}", "\n", "var", "basePath", "string", "\n", "if", "p", ":=", "r", ".", "Parent", "(", ")", ";", "p", "!=", "nil", "{", "if", "ca", ":=", "p", ".", "CanonicalAction", "(", ")", ";", "ca", "!=", "nil", "{", "if", "routes", ":=", "ca", ".", "Routes", ";", "len", "(", "routes", ")", ">", "0", "{", "// Note: all these tests should be true at code generation time", "// as DSL validation makes sure that parent resources have a", "// canonical path.", "basePath", "=", "path", ".", "Join", "(", "routes", "[", "0", "]", ".", "FullPath", "(", ")", ")", "\n", "}", "\n", "}", "\n", "}", "else", "{", "basePath", "=", "Design", ".", "BasePath", "\n", "}", "\n", "return", "httppath", ".", "Clean", "(", "path", ".", "Join", "(", "basePath", ",", "r", ".", "BasePath", ")", ")", "\n", "}" ]
// FullPath computes the base path to the resource actions concatenating the API and parent resource // base paths as needed.
[ "FullPath", "computes", "the", "base", "path", "to", "the", "resource", "actions", "concatenating", "the", "API", "and", "parent", "resource", "base", "paths", "as", "needed", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/definitions.go#L795-L813
166,687
goadesign/goa
design/definitions.go
Parent
func (r *ResourceDefinition) Parent() *ResourceDefinition { if r.ParentName != "" { if parent, ok := Design.Resources[r.ParentName]; ok { return parent } } return nil }
go
func (r *ResourceDefinition) Parent() *ResourceDefinition { if r.ParentName != "" { if parent, ok := Design.Resources[r.ParentName]; ok { return parent } } return nil }
[ "func", "(", "r", "*", "ResourceDefinition", ")", "Parent", "(", ")", "*", "ResourceDefinition", "{", "if", "r", ".", "ParentName", "!=", "\"", "\"", "{", "if", "parent", ",", "ok", ":=", "Design", ".", "Resources", "[", "r", ".", "ParentName", "]", ";", "ok", "{", "return", "parent", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Parent returns the parent resource if any, nil otherwise.
[ "Parent", "returns", "the", "parent", "resource", "if", "any", "nil", "otherwise", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/definitions.go#L816-L823
166,688
goadesign/goa
design/definitions.go
AllOrigins
func (r *ResourceDefinition) AllOrigins() []*CORSDefinition { all := make(map[string]*CORSDefinition) for n, o := range Design.Origins { all[n] = o } for n, o := range r.Origins { all[n] = o } names := make([]string, len(all)) i := 0 for n := range all { names[i] = n i++ } sort.Strings(names) cors := make([]*CORSDefinition, len(names)) for i, n := range names { cors[i] = all[n] } return cors }
go
func (r *ResourceDefinition) AllOrigins() []*CORSDefinition { all := make(map[string]*CORSDefinition) for n, o := range Design.Origins { all[n] = o } for n, o := range r.Origins { all[n] = o } names := make([]string, len(all)) i := 0 for n := range all { names[i] = n i++ } sort.Strings(names) cors := make([]*CORSDefinition, len(names)) for i, n := range names { cors[i] = all[n] } return cors }
[ "func", "(", "r", "*", "ResourceDefinition", ")", "AllOrigins", "(", ")", "[", "]", "*", "CORSDefinition", "{", "all", ":=", "make", "(", "map", "[", "string", "]", "*", "CORSDefinition", ")", "\n", "for", "n", ",", "o", ":=", "range", "Design", ".", "Origins", "{", "all", "[", "n", "]", "=", "o", "\n", "}", "\n", "for", "n", ",", "o", ":=", "range", "r", ".", "Origins", "{", "all", "[", "n", "]", "=", "o", "\n", "}", "\n", "names", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "all", ")", ")", "\n", "i", ":=", "0", "\n", "for", "n", ":=", "range", "all", "{", "names", "[", "i", "]", "=", "n", "\n", "i", "++", "\n", "}", "\n", "sort", ".", "Strings", "(", "names", ")", "\n", "cors", ":=", "make", "(", "[", "]", "*", "CORSDefinition", ",", "len", "(", "names", ")", ")", "\n", "for", "i", ",", "n", ":=", "range", "names", "{", "cors", "[", "i", "]", "=", "all", "[", "n", "]", "\n", "}", "\n", "return", "cors", "\n", "}" ]
// AllOrigins compute all CORS policies for the resource taking into account any API policy. // The result is sorted alphabetically by policy origin.
[ "AllOrigins", "compute", "all", "CORS", "policies", "for", "the", "resource", "taking", "into", "account", "any", "API", "policy", ".", "The", "result", "is", "sorted", "alphabetically", "by", "policy", "origin", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/definitions.go#L827-L847
166,689
goadesign/goa
design/definitions.go
PreflightPaths
func (r *ResourceDefinition) PreflightPaths() []string { var paths []string r.IterateActions(func(a *ActionDefinition) error { for _, r := range a.Routes { if r.Verb == "OPTIONS" { continue } found := false fp := r.FullPath() for _, p := range paths { if fp == p { found = true break } } if !found { paths = append(paths, fp) } } return nil }) r.IterateFileServers(func(fs *FileServerDefinition) error { found := false fp := fs.RequestPath for _, p := range paths { if fp == p { found = true break } } if !found { paths = append(paths, fp) } return nil }) return paths }
go
func (r *ResourceDefinition) PreflightPaths() []string { var paths []string r.IterateActions(func(a *ActionDefinition) error { for _, r := range a.Routes { if r.Verb == "OPTIONS" { continue } found := false fp := r.FullPath() for _, p := range paths { if fp == p { found = true break } } if !found { paths = append(paths, fp) } } return nil }) r.IterateFileServers(func(fs *FileServerDefinition) error { found := false fp := fs.RequestPath for _, p := range paths { if fp == p { found = true break } } if !found { paths = append(paths, fp) } return nil }) return paths }
[ "func", "(", "r", "*", "ResourceDefinition", ")", "PreflightPaths", "(", ")", "[", "]", "string", "{", "var", "paths", "[", "]", "string", "\n", "r", ".", "IterateActions", "(", "func", "(", "a", "*", "ActionDefinition", ")", "error", "{", "for", "_", ",", "r", ":=", "range", "a", ".", "Routes", "{", "if", "r", ".", "Verb", "==", "\"", "\"", "{", "continue", "\n", "}", "\n", "found", ":=", "false", "\n", "fp", ":=", "r", ".", "FullPath", "(", ")", "\n", "for", "_", ",", "p", ":=", "range", "paths", "{", "if", "fp", "==", "p", "{", "found", "=", "true", "\n", "break", "\n", "}", "\n", "}", "\n", "if", "!", "found", "{", "paths", "=", "append", "(", "paths", ",", "fp", ")", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}", ")", "\n", "r", ".", "IterateFileServers", "(", "func", "(", "fs", "*", "FileServerDefinition", ")", "error", "{", "found", ":=", "false", "\n", "fp", ":=", "fs", ".", "RequestPath", "\n", "for", "_", ",", "p", ":=", "range", "paths", "{", "if", "fp", "==", "p", "{", "found", "=", "true", "\n", "break", "\n", "}", "\n", "}", "\n", "if", "!", "found", "{", "paths", "=", "append", "(", "paths", ",", "fp", ")", "\n", "}", "\n", "return", "nil", "\n", "}", ")", "\n", "return", "paths", "\n", "}" ]
// PreflightPaths returns the paths that should handle OPTIONS requests.
[ "PreflightPaths", "returns", "the", "paths", "that", "should", "handle", "OPTIONS", "requests", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/definitions.go#L850-L886
166,690
goadesign/goa
design/definitions.go
Finalize
func (r *ResourceDefinition) Finalize() { meta := r.Metadata["swagger:generate"] r.IterateFileServers(func(f *FileServerDefinition) error { if meta != nil { if _, ok := f.Metadata["swagger:generate"]; !ok { f.Metadata["swagger:generate"] = meta } } f.Finalize() return nil }) r.IterateActions(func(a *ActionDefinition) error { if meta != nil { if _, ok := a.Metadata["swagger:generate"]; !ok { a.Metadata["swagger:generate"] = meta } } a.Finalize() return nil }) }
go
func (r *ResourceDefinition) Finalize() { meta := r.Metadata["swagger:generate"] r.IterateFileServers(func(f *FileServerDefinition) error { if meta != nil { if _, ok := f.Metadata["swagger:generate"]; !ok { f.Metadata["swagger:generate"] = meta } } f.Finalize() return nil }) r.IterateActions(func(a *ActionDefinition) error { if meta != nil { if _, ok := a.Metadata["swagger:generate"]; !ok { a.Metadata["swagger:generate"] = meta } } a.Finalize() return nil }) }
[ "func", "(", "r", "*", "ResourceDefinition", ")", "Finalize", "(", ")", "{", "meta", ":=", "r", ".", "Metadata", "[", "\"", "\"", "]", "\n", "r", ".", "IterateFileServers", "(", "func", "(", "f", "*", "FileServerDefinition", ")", "error", "{", "if", "meta", "!=", "nil", "{", "if", "_", ",", "ok", ":=", "f", ".", "Metadata", "[", "\"", "\"", "]", ";", "!", "ok", "{", "f", ".", "Metadata", "[", "\"", "\"", "]", "=", "meta", "\n", "}", "\n", "}", "\n", "f", ".", "Finalize", "(", ")", "\n", "return", "nil", "\n", "}", ")", "\n", "r", ".", "IterateActions", "(", "func", "(", "a", "*", "ActionDefinition", ")", "error", "{", "if", "meta", "!=", "nil", "{", "if", "_", ",", "ok", ":=", "a", ".", "Metadata", "[", "\"", "\"", "]", ";", "!", "ok", "{", "a", ".", "Metadata", "[", "\"", "\"", "]", "=", "meta", "\n", "}", "\n", "}", "\n", "a", ".", "Finalize", "(", ")", "\n", "return", "nil", "\n", "}", ")", "\n", "}" ]
// Finalize is run post DSL execution. It merges response definitions, creates implicit action // parameters, initializes querystring parameters, sets path parameters as non zero attributes // and sets the fallbacks for security schemes.
[ "Finalize", "is", "run", "post", "DSL", "execution", ".", "It", "merges", "response", "definitions", "creates", "implicit", "action", "parameters", "initializes", "querystring", "parameters", "sets", "path", "parameters", "as", "non", "zero", "attributes", "and", "sets", "the", "fallbacks", "for", "security", "schemes", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/definitions.go#L896-L916
166,691
goadesign/goa
design/definitions.go
UserTypes
func (r *ResourceDefinition) UserTypes() map[string]*UserTypeDefinition { types := make(map[string]*UserTypeDefinition) for _, a := range r.Actions { for n, ut := range a.UserTypes() { types[n] = ut } } if len(types) == 0 { return nil } return types }
go
func (r *ResourceDefinition) UserTypes() map[string]*UserTypeDefinition { types := make(map[string]*UserTypeDefinition) for _, a := range r.Actions { for n, ut := range a.UserTypes() { types[n] = ut } } if len(types) == 0 { return nil } return types }
[ "func", "(", "r", "*", "ResourceDefinition", ")", "UserTypes", "(", ")", "map", "[", "string", "]", "*", "UserTypeDefinition", "{", "types", ":=", "make", "(", "map", "[", "string", "]", "*", "UserTypeDefinition", ")", "\n", "for", "_", ",", "a", ":=", "range", "r", ".", "Actions", "{", "for", "n", ",", "ut", ":=", "range", "a", ".", "UserTypes", "(", ")", "{", "types", "[", "n", "]", "=", "ut", "\n", "}", "\n", "}", "\n", "if", "len", "(", "types", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n", "return", "types", "\n", "}" ]
// UserTypes returns all the user types used by the resource action payloads and parameters.
[ "UserTypes", "returns", "all", "the", "user", "types", "used", "by", "the", "resource", "action", "payloads", "and", "parameters", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/definitions.go#L919-L930
166,692
goadesign/goa
design/definitions.go
IsRequired
func (a *AttributeDefinition) IsRequired(attName string) bool { for _, name := range a.AllRequired() { if name == attName { return true } } return false }
go
func (a *AttributeDefinition) IsRequired(attName string) bool { for _, name := range a.AllRequired() { if name == attName { return true } } return false }
[ "func", "(", "a", "*", "AttributeDefinition", ")", "IsRequired", "(", "attName", "string", ")", "bool", "{", "for", "_", ",", "name", ":=", "range", "a", ".", "AllRequired", "(", ")", "{", "if", "name", "==", "attName", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// IsRequired returns true if the given string matches the name of a required // attribute, false otherwise.
[ "IsRequired", "returns", "true", "if", "the", "given", "string", "matches", "the", "name", "of", "a", "required", "attribute", "false", "otherwise", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/definitions.go#L980-L987
166,693
goadesign/goa
design/definitions.go
HasDefaultValue
func (a *AttributeDefinition) HasDefaultValue(attName string) bool { if a.Type.IsObject() { att := a.Type.ToObject()[attName] return att.DefaultValue != nil } return false }
go
func (a *AttributeDefinition) HasDefaultValue(attName string) bool { if a.Type.IsObject() { att := a.Type.ToObject()[attName] return att.DefaultValue != nil } return false }
[ "func", "(", "a", "*", "AttributeDefinition", ")", "HasDefaultValue", "(", "attName", "string", ")", "bool", "{", "if", "a", ".", "Type", ".", "IsObject", "(", ")", "{", "att", ":=", "a", ".", "Type", ".", "ToObject", "(", ")", "[", "attName", "]", "\n", "return", "att", ".", "DefaultValue", "!=", "nil", "\n", "}", "\n", "return", "false", "\n", "}" ]
// HasDefaultValue returns true if the given attribute has a default value.
[ "HasDefaultValue", "returns", "true", "if", "the", "given", "attribute", "has", "a", "default", "value", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/definitions.go#L990-L996
166,694
goadesign/goa
design/definitions.go
SetDefault
func (a *AttributeDefinition) SetDefault(def interface{}) { switch actual := def.(type) { case HashVal: a.DefaultValue = actual.ToMap() case ArrayVal: a.DefaultValue = actual.ToSlice() default: a.DefaultValue = actual } }
go
func (a *AttributeDefinition) SetDefault(def interface{}) { switch actual := def.(type) { case HashVal: a.DefaultValue = actual.ToMap() case ArrayVal: a.DefaultValue = actual.ToSlice() default: a.DefaultValue = actual } }
[ "func", "(", "a", "*", "AttributeDefinition", ")", "SetDefault", "(", "def", "interface", "{", "}", ")", "{", "switch", "actual", ":=", "def", ".", "(", "type", ")", "{", "case", "HashVal", ":", "a", ".", "DefaultValue", "=", "actual", ".", "ToMap", "(", ")", "\n", "case", "ArrayVal", ":", "a", ".", "DefaultValue", "=", "actual", ".", "ToSlice", "(", ")", "\n", "default", ":", "a", ".", "DefaultValue", "=", "actual", "\n", "}", "\n", "}" ]
// SetDefault sets the default for the attribute. It also converts HashVal // and ArrayVal to map and slice respectively.
[ "SetDefault", "sets", "the", "default", "for", "the", "attribute", ".", "It", "also", "converts", "HashVal", "and", "ArrayVal", "to", "map", "and", "slice", "respectively", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/definitions.go#L1000-L1009
166,695
goadesign/goa
design/definitions.go
AddValues
func (a *AttributeDefinition) AddValues(values []interface{}) { if a.Validation == nil { a.Validation = &dslengine.ValidationDefinition{} } a.Validation.Values = make([]interface{}, len(values)) for i, v := range values { switch actual := v.(type) { case HashVal: a.Validation.Values[i] = actual.ToMap() case ArrayVal: a.Validation.Values[i] = actual.ToSlice() default: a.Validation.Values[i] = actual } } }
go
func (a *AttributeDefinition) AddValues(values []interface{}) { if a.Validation == nil { a.Validation = &dslengine.ValidationDefinition{} } a.Validation.Values = make([]interface{}, len(values)) for i, v := range values { switch actual := v.(type) { case HashVal: a.Validation.Values[i] = actual.ToMap() case ArrayVal: a.Validation.Values[i] = actual.ToSlice() default: a.Validation.Values[i] = actual } } }
[ "func", "(", "a", "*", "AttributeDefinition", ")", "AddValues", "(", "values", "[", "]", "interface", "{", "}", ")", "{", "if", "a", ".", "Validation", "==", "nil", "{", "a", ".", "Validation", "=", "&", "dslengine", ".", "ValidationDefinition", "{", "}", "\n", "}", "\n", "a", ".", "Validation", ".", "Values", "=", "make", "(", "[", "]", "interface", "{", "}", ",", "len", "(", "values", ")", ")", "\n", "for", "i", ",", "v", ":=", "range", "values", "{", "switch", "actual", ":=", "v", ".", "(", "type", ")", "{", "case", "HashVal", ":", "a", ".", "Validation", ".", "Values", "[", "i", "]", "=", "actual", ".", "ToMap", "(", ")", "\n", "case", "ArrayVal", ":", "a", ".", "Validation", ".", "Values", "[", "i", "]", "=", "actual", ".", "ToSlice", "(", ")", "\n", "default", ":", "a", ".", "Validation", ".", "Values", "[", "i", "]", "=", "actual", "\n", "}", "\n", "}", "\n", "}" ]
// AddValues adds the Enum values to the attribute's validation definition. // It also performs any conversion needed for HashVal and ArrayVal types.
[ "AddValues", "adds", "the", "Enum", "values", "to", "the", "attribute", "s", "validation", "definition", ".", "It", "also", "performs", "any", "conversion", "needed", "for", "HashVal", "and", "ArrayVal", "types", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/definitions.go#L1013-L1028
166,696
goadesign/goa
design/definitions.go
AllNonZero
func (a *AttributeDefinition) AllNonZero() []string { nzs := make([]string, len(a.NonZeroAttributes)) i := 0 for n := range a.NonZeroAttributes { nzs[i] = n i++ } return nzs }
go
func (a *AttributeDefinition) AllNonZero() []string { nzs := make([]string, len(a.NonZeroAttributes)) i := 0 for n := range a.NonZeroAttributes { nzs[i] = n i++ } return nzs }
[ "func", "(", "a", "*", "AttributeDefinition", ")", "AllNonZero", "(", ")", "[", "]", "string", "{", "nzs", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "a", ".", "NonZeroAttributes", ")", ")", "\n", "i", ":=", "0", "\n", "for", "n", ":=", "range", "a", ".", "NonZeroAttributes", "{", "nzs", "[", "i", "]", "=", "n", "\n", "i", "++", "\n", "}", "\n", "return", "nzs", "\n", "}" ]
// AllNonZero returns the complete list of all non-zero attribute name.
[ "AllNonZero", "returns", "the", "complete", "list", "of", "all", "non", "-", "zero", "attribute", "name", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/definitions.go#L1031-L1039
166,697
goadesign/goa
design/definitions.go
IsPrimitivePointer
func (a *AttributeDefinition) IsPrimitivePointer(attName string) bool { if !a.Type.IsObject() { panic("checking pointer field on non-object") // bug } att := a.Type.ToObject()[attName] if att == nil { return false } if att.Type.IsPrimitive() { return (!a.IsRequired(attName) && !a.HasDefaultValue(attName) && !a.IsNonZero(attName) && !a.IsInterface(attName)) || a.IsFile(attName) } return false }
go
func (a *AttributeDefinition) IsPrimitivePointer(attName string) bool { if !a.Type.IsObject() { panic("checking pointer field on non-object") // bug } att := a.Type.ToObject()[attName] if att == nil { return false } if att.Type.IsPrimitive() { return (!a.IsRequired(attName) && !a.HasDefaultValue(attName) && !a.IsNonZero(attName) && !a.IsInterface(attName)) || a.IsFile(attName) } return false }
[ "func", "(", "a", "*", "AttributeDefinition", ")", "IsPrimitivePointer", "(", "attName", "string", ")", "bool", "{", "if", "!", "a", ".", "Type", ".", "IsObject", "(", ")", "{", "panic", "(", "\"", "\"", ")", "// bug", "\n", "}", "\n", "att", ":=", "a", ".", "Type", ".", "ToObject", "(", ")", "[", "attName", "]", "\n", "if", "att", "==", "nil", "{", "return", "false", "\n", "}", "\n", "if", "att", ".", "Type", ".", "IsPrimitive", "(", ")", "{", "return", "(", "!", "a", ".", "IsRequired", "(", "attName", ")", "&&", "!", "a", ".", "HasDefaultValue", "(", "attName", ")", "&&", "!", "a", ".", "IsNonZero", "(", "attName", ")", "&&", "!", "a", ".", "IsInterface", "(", "attName", ")", ")", "||", "a", ".", "IsFile", "(", "attName", ")", "\n", "}", "\n", "return", "false", "\n", "}" ]
// IsPrimitivePointer returns true if the field generated for the given attribute should be a // pointer to a primitive type. The target attribute must be an object.
[ "IsPrimitivePointer", "returns", "true", "if", "the", "field", "generated", "for", "the", "given", "attribute", "should", "be", "a", "pointer", "to", "a", "primitive", "type", ".", "The", "target", "attribute", "must", "be", "an", "object", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/definitions.go#L1049-L1061
166,698
goadesign/goa
design/definitions.go
SetExample
func (a *AttributeDefinition) SetExample(example interface{}) bool { if example == nil { a.Example = "-" // set it to something else than nil so we know not to generate one return true } if a.Type == nil || a.Type.IsCompatible(example) { a.Example = example return true } return false }
go
func (a *AttributeDefinition) SetExample(example interface{}) bool { if example == nil { a.Example = "-" // set it to something else than nil so we know not to generate one return true } if a.Type == nil || a.Type.IsCompatible(example) { a.Example = example return true } return false }
[ "func", "(", "a", "*", "AttributeDefinition", ")", "SetExample", "(", "example", "interface", "{", "}", ")", "bool", "{", "if", "example", "==", "nil", "{", "a", ".", "Example", "=", "\"", "\"", "// set it to something else than nil so we know not to generate one", "\n", "return", "true", "\n", "}", "\n", "if", "a", ".", "Type", "==", "nil", "||", "a", ".", "Type", ".", "IsCompatible", "(", "example", ")", "{", "a", ".", "Example", "=", "example", "\n", "return", "true", "\n", "}", "\n", "return", "false", "\n", "}" ]
// SetExample sets the custom example. SetExample also handles the case when the user doesn't // want any example or any auto-generated example.
[ "SetExample", "sets", "the", "custom", "example", ".", "SetExample", "also", "handles", "the", "case", "when", "the", "user", "doesn", "t", "want", "any", "example", "or", "any", "auto", "-", "generated", "example", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/definitions.go#L1091-L1101
166,699
goadesign/goa
design/definitions.go
GenerateExample
func (a *AttributeDefinition) GenerateExample(rand *RandomGenerator, seen []string) interface{} { if a.Example != nil { return a.Example } if Design.NoExamples { return nil } // Avoid infinite loops var key string if mt, ok := a.Type.(*MediaTypeDefinition); ok { key = mt.Identifier } else if ut, ok := a.Type.(*UserTypeDefinition); ok { key = ut.TypeName } if key != "" { count := 0 for _, k := range seen { if k == key { count++ } } if count > 1 { // Only go a couple of levels deep return nil } seen = append(seen, key) } switch { case a.Type.IsArray(): a.Example = a.arrayExample(rand, seen) case a.Type.IsHash(): a.Example = a.hashExample(rand, seen) case a.Type.IsObject(): a.Example = a.objectExample(rand, seen) default: a.Example = newExampleGenerator(a, rand).Generate(seen) } return a.Example }
go
func (a *AttributeDefinition) GenerateExample(rand *RandomGenerator, seen []string) interface{} { if a.Example != nil { return a.Example } if Design.NoExamples { return nil } // Avoid infinite loops var key string if mt, ok := a.Type.(*MediaTypeDefinition); ok { key = mt.Identifier } else if ut, ok := a.Type.(*UserTypeDefinition); ok { key = ut.TypeName } if key != "" { count := 0 for _, k := range seen { if k == key { count++ } } if count > 1 { // Only go a couple of levels deep return nil } seen = append(seen, key) } switch { case a.Type.IsArray(): a.Example = a.arrayExample(rand, seen) case a.Type.IsHash(): a.Example = a.hashExample(rand, seen) case a.Type.IsObject(): a.Example = a.objectExample(rand, seen) default: a.Example = newExampleGenerator(a, rand).Generate(seen) } return a.Example }
[ "func", "(", "a", "*", "AttributeDefinition", ")", "GenerateExample", "(", "rand", "*", "RandomGenerator", ",", "seen", "[", "]", "string", ")", "interface", "{", "}", "{", "if", "a", ".", "Example", "!=", "nil", "{", "return", "a", ".", "Example", "\n", "}", "\n", "if", "Design", ".", "NoExamples", "{", "return", "nil", "\n", "}", "\n\n", "// Avoid infinite loops", "var", "key", "string", "\n", "if", "mt", ",", "ok", ":=", "a", ".", "Type", ".", "(", "*", "MediaTypeDefinition", ")", ";", "ok", "{", "key", "=", "mt", ".", "Identifier", "\n", "}", "else", "if", "ut", ",", "ok", ":=", "a", ".", "Type", ".", "(", "*", "UserTypeDefinition", ")", ";", "ok", "{", "key", "=", "ut", ".", "TypeName", "\n", "}", "\n", "if", "key", "!=", "\"", "\"", "{", "count", ":=", "0", "\n", "for", "_", ",", "k", ":=", "range", "seen", "{", "if", "k", "==", "key", "{", "count", "++", "\n", "}", "\n", "}", "\n", "if", "count", ">", "1", "{", "// Only go a couple of levels deep", "return", "nil", "\n", "}", "\n", "seen", "=", "append", "(", "seen", ",", "key", ")", "\n", "}", "\n\n", "switch", "{", "case", "a", ".", "Type", ".", "IsArray", "(", ")", ":", "a", ".", "Example", "=", "a", ".", "arrayExample", "(", "rand", ",", "seen", ")", "\n\n", "case", "a", ".", "Type", ".", "IsHash", "(", ")", ":", "a", ".", "Example", "=", "a", ".", "hashExample", "(", "rand", ",", "seen", ")", "\n\n", "case", "a", ".", "Type", ".", "IsObject", "(", ")", ":", "a", ".", "Example", "=", "a", ".", "objectExample", "(", "rand", ",", "seen", ")", "\n\n", "default", ":", "a", ".", "Example", "=", "newExampleGenerator", "(", "a", ",", "rand", ")", ".", "Generate", "(", "seen", ")", "\n", "}", "\n\n", "return", "a", ".", "Example", "\n", "}" ]
// GenerateExample returns the value of the Example field if not nil. Otherwise it traverses the // attribute type and recursively generates an example. The result is saved in the Example field.
[ "GenerateExample", "returns", "the", "value", "of", "the", "Example", "field", "if", "not", "nil", ".", "Otherwise", "it", "traverses", "the", "attribute", "type", "and", "recursively", "generates", "an", "example", ".", "The", "result", "is", "saved", "in", "the", "Example", "field", "." ]
90bd33edff1a4f17fab06d1f9e14e659075d1328
https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/design/definitions.go#L1105-L1149