本文整理汇总了Golang中github.com/goadesign/goa/dslengine.IncompatibleDSL函数的典型用法代码示例。如果您正苦于以下问题:Golang IncompatibleDSL函数的具体用法?Golang IncompatibleDSL怎么用?Golang IncompatibleDSL使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IncompatibleDSL函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Headers
// Headers implements the DSL for describing HTTP headers. The DSL syntax is identical to the one
// of Attribute. Here is an example defining a couple of headers with validations:
//
// Headers(func() {
// Header("Authorization")
// Header("X-Account", Integer, func() {
// Minimum(1)
// })
// Required("Authorization")
// })
//
// Headers can be used inside Action to define the action request headers, Response to define the
// response headers or Resource to define common request headers to all the resource actions.
func Headers(params ...interface{}) {
if len(params) == 0 {
dslengine.ReportError("missing parameter")
return
}
dsl, ok := params[0].(func())
if ok {
switch def := dslengine.CurrentDefinition().(type) {
case *design.ActionDefinition:
headers := newAttribute(def.Parent.MediaType)
if dslengine.Execute(dsl, headers) {
def.Headers = headers
}
case *design.ResourceDefinition:
headers := newAttribute(def.MediaType)
if dslengine.Execute(dsl, headers) {
def.Headers = headers
}
case *design.ResponseDefinition:
if def.Headers != nil {
dslengine.ReportError("headers already defined")
return
}
var h *design.AttributeDefinition
switch actual := def.Parent.(type) {
case *design.ResourceDefinition:
h = newAttribute(actual.MediaType)
case *design.ActionDefinition:
h = newAttribute(actual.Parent.MediaType)
case nil: // API ResponseTemplate
h = &design.AttributeDefinition{}
default:
dslengine.ReportError("invalid use of Response or ResponseTemplate")
}
if dslengine.Execute(dsl, h) {
def.Headers = h
}
default:
dslengine.IncompatibleDSL()
}
} else if cors, ok := corsDefinition(); ok {
vals := make([]string, len(params))
for i, p := range params {
if v, ok := p.(string); ok {
vals[i] = v
} else {
dslengine.ReportError("invalid parameter at position %d: must be a string", i)
return
}
}
cors.Headers = vals
} else {
dslengine.IncompatibleDSL()
}
}
示例2: responseDefinition
// responseDefinition returns true and current context if it is a ResponseDefinition,
// nil and false otherwise.
func responseDefinition(failIfNotResponse bool) (*design.ResponseDefinition, bool) {
r, ok := dslengine.CurrentDefinition().(*design.ResponseDefinition)
if !ok && failIfNotResponse {
dslengine.IncompatibleDSL(dslengine.Caller())
}
return r, ok
}
示例3: actionDefinition
// actionDefinition returns true and current context if it is an ActionDefinition,
// nil and false otherwise.
func actionDefinition(failIfNotAction bool) (*design.ActionDefinition, bool) {
a, ok := dslengine.CurrentDefinition().(*design.ActionDefinition)
if !ok && failIfNotAction {
dslengine.IncompatibleDSL(dslengine.Caller())
}
return a, ok
}
示例4: typeDefinition
// typeDefinition returns true and current context if it is a UserTypeDefinition,
// nil and false otherwise.
func typeDefinition(failIfNotMT bool) (*design.UserTypeDefinition, bool) {
m, ok := dslengine.CurrentDefinition().(*design.UserTypeDefinition)
if !ok && failIfNotMT {
dslengine.IncompatibleDSL(dslengine.Caller())
}
return m, ok
}
示例5: docsDefinition
// docsDefinition returns true and current context if it is a DocsDefinition,
// nil and false otherwise.
func docsDefinition(failIfNotDocs bool) (*design.DocsDefinition, bool) {
a, ok := dslengine.CurrentDefinition().(*design.DocsDefinition)
if !ok && failIfNotDocs {
dslengine.IncompatibleDSL(dslengine.Caller())
}
return a, ok
}
示例6: licenseDefinition
// licenseDefinition returns true and current context if it is an APIDefinition,
// nil and false otherwise.
func licenseDefinition(failIfNotLicense bool) (*design.LicenseDefinition, bool) {
l, ok := dslengine.CurrentDefinition().(*design.LicenseDefinition)
if !ok && failIfNotLicense {
dslengine.IncompatibleDSL(dslengine.Caller())
}
return l, ok
}
示例7: Scope
// Scope defines an authorization scope. Used within SecurityScheme, a description may be provided
// explaining what the scope means. Within a Security block, only a scope is needed.
func Scope(name string, desc ...string) {
switch current := dslengine.CurrentDefinition().(type) {
case *design.SecurityDefinition:
if len(desc) >= 1 {
dslengine.ReportError("too many arguments")
return
}
current.Scopes = append(current.Scopes, name)
case *design.SecuritySchemeDefinition:
if len(desc) > 1 {
dslengine.ReportError("too many arguments")
return
}
if current.Scopes == nil {
current.Scopes = make(map[string]string)
}
d := "no description"
if len(desc) == 1 {
d = desc[0]
}
current.Scopes[name] = d
default:
dslengine.IncompatibleDSL()
}
}
示例8: buildSourceDefinition
// buildSourceDefinition returns true and current context if it is an BuildSource
// nil and false otherwise.
func buildSourceDefinition(failIfNotSD bool) (*gorma.BuildSource, bool) {
a, ok := dslengine.CurrentDefinition().(*gorma.BuildSource)
if !ok && failIfNotSD {
dslengine.IncompatibleDSL()
}
return a, ok
}
示例9: responseDefinition
// responseDefinition returns true and current context if it is a ResponseDefinition,
// nil and false otherwise.
func responseDefinition() (*design.ResponseDefinition, bool) {
r, ok := dslengine.CurrentDefinition().(*design.ResponseDefinition)
if !ok {
dslengine.IncompatibleDSL()
}
return r, ok
}
示例10: Metadata
// Metadata is a set of key/value pairs that can be assigned to an object. Each value consists of a
// slice of strings so that multiple invocation of the Metadata function on the same target using
// the same key builds up the slice. Metadata may be set on attributes, media types, actions,
// responses, resources and API definitions.
//
// While keys can have any value the following names are handled explicitly by goagen when set on
// attributes.
//
// `struct:field:name`: overrides the Go struct field name generated by default by goagen.
// Applicable to attributes only.
//
// Metadata("struct:field:name", "MyName")
//
// `struct:tag:xxx`: sets the struct field tag xxx on generated Go structs. Overrides tags that
// goagen would otherwise set. If the metadata value is a slice then the strings are joined with
// the space character as separator.
// Applicable to attributes only.
//
// Metadata("struct:tag:json", "myName,omitempty")
// Metadata("struct:tag:xml", "myName,attr")
//
// `swagger:generate`: specifies whether Swagger specification should be generated. Defaults to
// true.
// Applicable to resources, actions and file servers.
//
// Metadata("swagger:generate", "false")
//
// `swagger:summary`: sets the Swagger operation summary field.
// Applicable to actions.
//
// Metadata("swagger:summary", "Short summary of what action does")
//
// `swagger:tag:xxx`: sets the Swagger object field tag xxx.
// Applicable to resources and actions.
//
// Metadata("swagger:tag:Backend")
// Metadata("swagger:tag:Backend:desc", "Quick description of what 'Backend' is")
// Metadata("swagger:tag:Backend:url", "http://example.com")
// Metadata("swagger:tag:Backend:url:desc", "See more docs here")
//
// `swagger:extension:xxx`: sets the Swagger extensions xxx. It can have any valid JSON format value.
// Applicable to
// api as within the info and tag object,
// resource as within the paths object,
// action as within the path-item object,
// route as within the operation object,
// param as within the parameter object,
// response as within the response object
// and security as within the security-scheme object.
// See https://github.com/OAI/OpenAPI-Specification/blob/master/guidelines/EXTENSIONS.md.
//
// Metadata("swagger:extension:x-api", `{"foo":"bar"}`)
//
// The special key names listed above may be used as follows:
//
// var Account = Type("Account", func() {
// Attribute("service", String, "Name of service", func() {
// // Override default name to avoid clash with built-in 'Service' field.
// Metadata("struct:field:name", "ServiceName")
// })
// })
//
func Metadata(name string, value ...string) {
appendMetadata := func(metadata dslengine.MetadataDefinition, name string, value ...string) dslengine.MetadataDefinition {
if metadata == nil {
metadata = make(map[string][]string)
}
metadata[name] = append(metadata[name], value...)
return metadata
}
switch def := dslengine.CurrentDefinition().(type) {
case design.ContainerDefinition:
att := def.Attribute()
att.Metadata = appendMetadata(att.Metadata, name, value...)
case *design.AttributeDefinition:
def.Metadata = appendMetadata(def.Metadata, name, value...)
case *design.MediaTypeDefinition:
def.Metadata = appendMetadata(def.Metadata, name, value...)
case *design.ActionDefinition:
def.Metadata = appendMetadata(def.Metadata, name, value...)
case *design.FileServerDefinition:
def.Metadata = appendMetadata(def.Metadata, name, value...)
case *design.ResourceDefinition:
def.Metadata = appendMetadata(def.Metadata, name, value...)
case *design.ResponseDefinition:
def.Metadata = appendMetadata(def.Metadata, name, value...)
case *design.APIDefinition:
def.Metadata = appendMetadata(def.Metadata, name, value...)
case *design.RouteDefinition:
def.Metadata = appendMetadata(def.Metadata, name, value...)
case *design.SecurityDefinition:
def.Scheme.Metadata = appendMetadata(def.Scheme.Metadata, name, value...)
default:
dslengine.IncompatibleDSL()
}
}
示例11: actionDefinition
// actionDefinition returns true and current context if it is an ActionDefinition,
// nil and false otherwise.
func actionDefinition() (*design.ActionDefinition, bool) {
a, ok := dslengine.CurrentDefinition().(*design.ActionDefinition)
if !ok {
dslengine.IncompatibleDSL()
}
return a, ok
}
示例12: corsDefinition
// corsDefinition returns true and current context if it is a CORSDefinition, nil And
// false otherwise.
func corsDefinition() (*design.CORSDefinition, bool) {
cors, ok := dslengine.CurrentDefinition().(*design.CORSDefinition)
if !ok {
dslengine.IncompatibleDSL()
}
return cors, ok
}
示例13: typeDefinition
// typeDefinition returns true and current context if it is a UserTypeDefinition,
// nil and false otherwise.
func typeDefinition() (*design.UserTypeDefinition, bool) {
m, ok := dslengine.CurrentDefinition().(*design.UserTypeDefinition)
if !ok {
dslengine.IncompatibleDSL()
}
return m, ok
}
示例14: licenseDefinition
// licenseDefinition returns true and current context if it is an APIDefinition,
// nil and false otherwise.
func licenseDefinition() (*design.LicenseDefinition, bool) {
l, ok := dslengine.CurrentDefinition().(*design.LicenseDefinition)
if !ok {
dslengine.IncompatibleDSL()
}
return l, ok
}
示例15: encodingDefinition
// encodingDefinition returns true and current context if it is an EncodingDefinition,
// nil and false otherwise.
func encodingDefinition(failIfNotEnc bool) (*design.EncodingDefinition, bool) {
e, ok := dslengine.CurrentDefinition().(*design.EncodingDefinition)
if !ok && failIfNotEnc {
dslengine.IncompatibleDSL(dslengine.Caller())
}
return e, ok
}