Documentation ¶
Index ¶
- Variables
- func Generate(genpkg string, roots []eval.Root, files []*codegen.File) ([]*codegen.File, error)
- func MatchOrigin(origin, spec string) bool
- func MatchOriginRegexp(origin string, spec *regexp.Regexp) bool
- func TweakExample(genpkg string, roots []eval.Root, files []*codegen.File) ([]*codegen.File, error)
- type ServiceData
Constants ¶
This section is empty.
Variables ¶
var ServicesData = make(map[string]*ServiceData)
ServicesData holds the all the ServiceData indexed by service name.
Functions ¶
func Generate ¶
Generate produces server code that handle preflight requests and updates the HTTP responses with the appropriate CORS headers.
func MatchOrigin ¶
MatchOrigin returns true if the given Origin header value matches the origin specification. Spec can be one of: - a plain string identifying an origin. eg http://swagger.goa.design - a plain string containing a wildcard. eg *.goa.design - the special string * that matches every host
func MatchOriginRegexp ¶
MatchOriginRegexp returns true if the given Origin header value matches the origin specification. Spec must be a valid regex
func TweakExample ¶ added in v3.0.4
TweakExample handles the special case where a service only has file servers and no method in which case the Goa generator generate a Mount method that does not take a second argument but this plugin generates one that does. The second argument is the actual HTTP server which is needed so it can be configured with the CORS endpoint. So this method simply removes the special case from the Goa template generating the example.
Types ¶
type ServiceData ¶
type ServiceData struct { // Name is the name of the service. Name string // Origins is a list of origin expressions defined in API and service levels. Origins []*expr.OriginExpr // OriginHandler is the name of the handler function that sets CORS headers. OriginHandler string // PreflightPaths is the list of paths that should handle OPTIONS requests. PreflightPaths []string // Endpoint is the CORS endpoint data. Endpoint *httpcodegen.EndpointData }
ServiceData contains the data necessary to generate origin handlers