Documentation ¶
Overview ¶
Package cors implements functions to enable New support for the mock server.
Index ¶
- Variables
- func New(options Config) func(http.Handler) http.Handler
- type Config
- type OptionsBuilder
- func (b *OptionsBuilder) AllowCredentials(allow bool) *OptionsBuilder
- func (b *OptionsBuilder) AllowMethods(methods ...string) *OptionsBuilder
- func (b *OptionsBuilder) AllowOrigin(origin ...string) *OptionsBuilder
- func (b *OptionsBuilder) AllowedHeaders(headers ...string) *OptionsBuilder
- func (b *OptionsBuilder) Build() Config
- func (b *OptionsBuilder) ExposeHeaders(headers ...string) *OptionsBuilder
- func (b *OptionsBuilder) MaxAge(maxAge int) *OptionsBuilder
- func (b *OptionsBuilder) SuccessStatusCode(code int) *OptionsBuilder
Constants ¶
This section is empty.
Variables ¶
var ConfigDefault = Config{ AllowedOrigin: "*", AllowedMethods: strings.Join([]string{ http.MethodGet, http.MethodPost, http.MethodHead, http.MethodPut, http.MethodDelete, http.MethodPatch, }, ","), AllowedHeaders: "", AllowCredentials: false, ExposeHeaders: "", MaxAge: 0, SuccessStatusCode: http.StatusNoContent, }
ConfigDefault is the default config.
Functions ¶
Types ¶
type Config ¶
type Config struct { AllowedOrigin string AllowCredentials bool AllowedMethods string AllowedHeaders string ExposeHeaders string MaxAge int SuccessStatusCode int }
Config represents the possible options to configure New for the mock server.
type OptionsBuilder ¶
type OptionsBuilder struct {
// contains filtered or unexported fields
}
OptionsBuilder facilitates building New options.
func (*OptionsBuilder) AllowCredentials ¶
func (b *OptionsBuilder) AllowCredentials(allow bool) *OptionsBuilder
AllowCredentials sets "Access-Control-Allow-Credentials" header.
func (*OptionsBuilder) AllowMethods ¶
func (b *OptionsBuilder) AllowMethods(methods ...string) *OptionsBuilder
AllowMethods sets the allowed HTTP methods. The header "Access-Control-Allow-Methods" will be used.
func (*OptionsBuilder) AllowOrigin ¶
func (b *OptionsBuilder) AllowOrigin(origin ...string) *OptionsBuilder
AllowOrigin sets allowed origins.
func (*OptionsBuilder) AllowedHeaders ¶
func (b *OptionsBuilder) AllowedHeaders(headers ...string) *OptionsBuilder
AllowedHeaders sets allowed headers. It will set the header "Access-Control-Allow-Header".
func (*OptionsBuilder) Build ¶
func (b *OptionsBuilder) Build() Config
Build returns an Option with previously configured values.
func (*OptionsBuilder) ExposeHeaders ¶
func (b *OptionsBuilder) ExposeHeaders(headers ...string) *OptionsBuilder
ExposeHeaders sets "Access-Control-Expose-Header" header.
func (*OptionsBuilder) MaxAge ¶
func (b *OptionsBuilder) MaxAge(maxAge int) *OptionsBuilder
MaxAge sets New max age.
func (*OptionsBuilder) SuccessStatusCode ¶
func (b *OptionsBuilder) SuccessStatusCode(code int) *OptionsBuilder
SuccessStatusCode sets a custom status code returned on New Options request. If none is specified, the default status code is http.StatusNoContent.