github.com/shogo82148/goa-v1@v1.6.2/design/apidsl/current.go (about) 1 package apidsl 2 3 import ( 4 "github.com/shogo82148/goa-v1/design" 5 "github.com/shogo82148/goa-v1/dslengine" 6 ) 7 8 // NOTE: the following functions are in this file so that IncompatibleDSL can compute the stack 9 // depth correctly when looking up the name of the caller DSL function. IncompatibleDSL in used in 10 // two scenarios: in a type switch statement or via one of the functions below. In the case of a 11 // switch statement the name of the DSL function is 2 levels up the call to IncompatibleDSL while in 12 // the case of the functions below it's 3 levels up. Using a different file allows IncompatibleDSL 13 // to correctly compute the stack depth. A little bit dirty but seems to be the lesser evil. 14 15 // apiDefinition returns true and current context if it is an APIDefinition, 16 // nil and false otherwise. 17 func apiDefinition() (*design.APIDefinition, bool) { 18 a, ok := dslengine.CurrentDefinition().(*design.APIDefinition) 19 if !ok { 20 dslengine.IncompatibleDSL() 21 } 22 return a, ok 23 } 24 25 // encodingDefinition returns true and current context if it is an EncodingDefinition, 26 // nil and false otherwise. 27 func encodingDefinition() (*design.EncodingDefinition, bool) { 28 e, ok := dslengine.CurrentDefinition().(*design.EncodingDefinition) 29 if !ok { 30 dslengine.IncompatibleDSL() 31 } 32 return e, ok 33 } 34 35 // contactDefinition returns true and current context if it is an ContactDefinition, 36 // nil and false otherwise. 37 func contactDefinition() (*design.ContactDefinition, bool) { 38 a, ok := dslengine.CurrentDefinition().(*design.ContactDefinition) 39 if !ok { 40 dslengine.IncompatibleDSL() 41 } 42 return a, ok 43 } 44 45 // mediaTypeDefinition returns true and current context if it is a MediaTypeDefinition, 46 // nil and false otherwise. 47 func mediaTypeDefinition() (*design.MediaTypeDefinition, bool) { 48 m, ok := dslengine.CurrentDefinition().(*design.MediaTypeDefinition) 49 if !ok { 50 dslengine.IncompatibleDSL() 51 } 52 return m, ok 53 } 54 55 // attributeDefinition returns true and current context if it is an Attribute, 56 // nil and false otherwise. 57 func attributeDefinition() (*design.AttributeDefinition, bool) { 58 a, ok := dslengine.CurrentDefinition().(*design.AttributeDefinition) 59 if !ok { 60 dslengine.IncompatibleDSL() 61 } 62 return a, ok 63 } 64 65 // resourceDefinition returns true and current context if it is a ResourceDefinition, 66 // nil and false otherwise. 67 func resourceDefinition() (*design.ResourceDefinition, bool) { 68 r, ok := dslengine.CurrentDefinition().(*design.ResourceDefinition) 69 if !ok { 70 dslengine.IncompatibleDSL() 71 } 72 return r, ok 73 } 74 75 // corsDefinition returns true and current context if it is a CORSDefinition, nil And 76 // false otherwise. 77 func corsDefinition() (*design.CORSDefinition, bool) { 78 cors, ok := dslengine.CurrentDefinition().(*design.CORSDefinition) 79 if !ok { 80 dslengine.IncompatibleDSL() 81 } 82 return cors, ok 83 } 84 85 // actionDefinition returns true and current context if it is an ActionDefinition, 86 // nil and false otherwise. 87 func actionDefinition() (*design.ActionDefinition, bool) { 88 a, ok := dslengine.CurrentDefinition().(*design.ActionDefinition) 89 if !ok { 90 dslengine.IncompatibleDSL() 91 } 92 return a, ok 93 } 94 95 // responseDefinition returns true and current context if it is a ResponseDefinition, 96 // nil and false otherwise. 97 func responseDefinition() (*design.ResponseDefinition, bool) { 98 r, ok := dslengine.CurrentDefinition().(*design.ResponseDefinition) 99 if !ok { 100 dslengine.IncompatibleDSL() 101 } 102 return r, ok 103 }