rkmidcors

package
v2.2.22 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 9, 2024 License: Apache-2.0 Imports: 5 Imported by: 16

Documentation

Overview

Package rkmidcors provide cors related options

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BeforeCtx

type BeforeCtx struct {
	Input struct {
		UrlPath                     string
		OriginHeader                string
		IsPreflight                 bool
		AccessControlRequestHeaders string
	}
	Output struct {
		HeadersToReturn map[string]string
		HeaderVary      []string
		Abort           bool
	}
}

BeforeCtx context for Before() function

func NewBeforeCtx

func NewBeforeCtx() *BeforeCtx

NewBeforeCtx create new BeforeCtx with fields initialized

type BootConfig

type BootConfig struct {
	Enabled          bool     `yaml:"enabled" json:"enabled"`
	AllowOrigins     []string `yaml:"allowOrigins" json:"allowOrigins"`
	AllowCredentials bool     `yaml:"allowCredentials" json:"allowCredentials"`
	AllowHeaders     []string `yaml:"allowHeaders" json:"allowHeaders"`
	AllowMethods     []string `yaml:"allowMethods" json:"allowMethods"`
	ExposeHeaders    []string `yaml:"exposeHeaders" json:"exposeHeaders"`
	MaxAge           int      `yaml:"maxAge" json:"maxAge"`
	Ignore           []string `yaml:"ignore" json:"ignore"`
}

BootConfig for YAML

type Option

type Option func(*optionSet)

Option

func ToOptions

func ToOptions(config *BootConfig, entryName, entryType string) []Option

ToOptions convert BootConfig into Option list

func WithAllowCredentials

func WithAllowCredentials(allow bool) Option

WithAllowCredentials allow credentials or not

func WithAllowHeaders

func WithAllowHeaders(headers ...string) Option

WithAllowHeaders provide allowed headers

func WithAllowMethods

func WithAllowMethods(methods ...string) Option

WithAllowMethods provide allowed http methods

func WithAllowOrigins

func WithAllowOrigins(origins ...string) Option

WithAllowOrigins provide allowed origins.

func WithEntryNameAndType

func WithEntryNameAndType(entryName, entryType string) Option

WithEntryNameAndType provide entry name and entry type.

func WithExposeHeaders

func WithExposeHeaders(headers ...string) Option

WithExposeHeaders provide expose headers

func WithMaxAge

func WithMaxAge(age int) Option

WithMaxAge provide max age

func WithMockOptionSet

func WithMockOptionSet(mock OptionSetInterface) Option

WithMockOptionSet provide mock OptionSetInterface

func WithPathToIgnore

func WithPathToIgnore(paths ...string) Option

WithPathToIgnore provide paths prefix that will ignore.

type OptionSetInterface

type OptionSetInterface interface {
	GetEntryName() string

	GetEntryType() string

	Before(*BeforeCtx)

	BeforeCtx(*http.Request) *BeforeCtx

	ShouldIgnore(string) bool
}

OptionSetInterface mainly for testing purpose

func NewOptionSet

func NewOptionSet(opts ...Option) OptionSetInterface

NewOptionSet Create new optionSet with options.

func NewOptionSetMock

func NewOptionSetMock(before *BeforeCtx) OptionSetInterface

NewOptionSetMock for testing purpose

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL