plugins: github.com/goadesign/plugins/cors Index | Files | Directories

package cors

import "github.com/goadesign/plugins/cors"

Index

Package Files

cors.go generate.go

Variables

var ServicesData = make(map[string]*ServiceData)

ServicesData holds the all the ServiceData indexed by service name.

func Generate Uses

func Generate(genpkg string, roots []eval.Root, files []*codegen.File) ([]*codegen.File, error)

Generate produces server code that handle preflight requests and updates the HTTP responses with the appropriate CORS headers.

func MatchOrigin Uses

func MatchOrigin(origin, spec string) bool

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 Uses

func MatchOriginRegexp(origin string, spec *regexp.Regexp) bool

MatchOriginRegexp returns true if the given Origin header value matches the origin specification. Spec must be a valid regex

func TweakExample Uses

func TweakExample(genpkg string, roots []eval.Root, files []*codegen.File) ([]*codegen.File, error)

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.

type ServiceData Uses

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

Directories

PathSynopsis
dsl
expr

Package cors imports 8 packages (graph). Updated 2019-09-21. Refresh now. Tools for package owners.