github.com/brycereitano/goa@v0.0.0-20170315073847-8ffa6c85e265/design/apidsl/current.go (about) 1 package apidsl 2 3 import ( 4 "github.com/goadesign/goa/design" 5 "github.com/goadesign/goa/dslengine" 6 ) 7 8 // NOTE: the following functions are in this file so that IncompatibleDSL can compute the stack 9 // depth correcly 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 // licenseDefinition returns true and current context if it is an APIDefinition, 46 // nil and false otherwise. 47 func licenseDefinition() (*design.LicenseDefinition, bool) { 48 l, ok := dslengine.CurrentDefinition().(*design.LicenseDefinition) 49 if !ok { 50 dslengine.IncompatibleDSL() 51 } 52 return l, ok 53 } 54 55 // docsDefinition returns true and current context if it is a DocsDefinition, 56 // nil and false otherwise. 57 func docsDefinition() (*design.DocsDefinition, bool) { 58 a, ok := dslengine.CurrentDefinition().(*design.DocsDefinition) 59 if !ok { 60 dslengine.IncompatibleDSL() 61 } 62 return a, ok 63 } 64 65 // mediaTypeDefinition returns true and current context if it is a MediaTypeDefinition, 66 // nil and false otherwise. 67 func mediaTypeDefinition() (*design.MediaTypeDefinition, bool) { 68 m, ok := dslengine.CurrentDefinition().(*design.MediaTypeDefinition) 69 if !ok { 70 dslengine.IncompatibleDSL() 71 } 72 return m, ok 73 } 74 75 // typeDefinition returns true and current context if it is a UserTypeDefinition, 76 // nil and false otherwise. 77 func typeDefinition() (*design.UserTypeDefinition, bool) { 78 m, ok := dslengine.CurrentDefinition().(*design.UserTypeDefinition) 79 if !ok { 80 dslengine.IncompatibleDSL() 81 } 82 return m, ok 83 } 84 85 // attributeDefinition returns true and current context if it is an Attribute, 86 // nil and false otherwise. 87 func attributeDefinition() (*design.AttributeDefinition, bool) { 88 a, ok := dslengine.CurrentDefinition().(*design.AttributeDefinition) 89 if !ok { 90 dslengine.IncompatibleDSL() 91 } 92 return a, ok 93 } 94 95 // resourceDefinition returns true and current context if it is a ResourceDefinition, 96 // nil and false otherwise. 97 func resourceDefinition() (*design.ResourceDefinition, bool) { 98 r, ok := dslengine.CurrentDefinition().(*design.ResourceDefinition) 99 if !ok { 100 dslengine.IncompatibleDSL() 101 } 102 return r, ok 103 } 104 105 // corsDefinition returns true and current context if it is a CORSDefinition, nil And 106 // false otherwise. 107 func corsDefinition() (*design.CORSDefinition, bool) { 108 cors, ok := dslengine.CurrentDefinition().(*design.CORSDefinition) 109 if !ok { 110 dslengine.IncompatibleDSL() 111 } 112 return cors, ok 113 } 114 115 // actionDefinition returns true and current context if it is an ActionDefinition, 116 // nil and false otherwise. 117 func actionDefinition() (*design.ActionDefinition, bool) { 118 a, ok := dslengine.CurrentDefinition().(*design.ActionDefinition) 119 if !ok { 120 dslengine.IncompatibleDSL() 121 } 122 return a, ok 123 } 124 125 // responseDefinition returns true and current context if it is a ResponseDefinition, 126 // nil and false otherwise. 127 func responseDefinition() (*design.ResponseDefinition, bool) { 128 r, ok := dslengine.CurrentDefinition().(*design.ResponseDefinition) 129 if !ok { 130 dslengine.IncompatibleDSL() 131 } 132 return r, ok 133 }