cors

package module
v0.3.8 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New() middleware.Configurable[Options]

New creates a new instance of the CORS middleware, implementing middleware.Configurable. If CORS.Settings isn't called, then the CORS.Handler function will hydrate the middleware's configuration with sane default(s) if applicable.

func Value

func Value(ctx context.Context) (enabled bool)

Value retrieves a boolean value from the provided context, indicating if the CORS middleware is enabled, based on predefined context keys, and logs warnings for invalid or missing key evaluation.

Types

type CORS

type CORS struct {
	middleware.Configurable[Options]
	// contains filtered or unexported fields
}

CORS represents a middleware component that applies configurable Options settings to HTTP requests. It embeds middleware.Configurable for Options configuration.

func (*CORS) Handler

func (c *CORS) Handler(next http.Handler) http.Handler

Handler is a middleware method that wraps the provided http.Handler, applying CORS settings and injecting context with predefined values.

func (*CORS) Settings

func (c *CORS) Settings(configuration ...func(o *Options)) middleware.Configurable[Options]

Settings applies configuration functions to modify the [Service] middleware's Options and returns the updated middleware instance.

type Options

type Options struct {
	// Debug represents a boolean flag to enable debug-related logging. Defaults to false.
	Debug bool
}

Options represents the configuration settings for the CORS middleware component.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳