cors

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package cors provides CORS middleware for HTTP handlers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Middleware

func Middleware(opts ...Option) func(http.Handler) http.Handler

Middleware returns CORS middleware with the given options. Defaults: allow all origins, common methods, common headers, 1 hour max age.

Types

type Config

type Config struct {
	AllowOrigins     []string
	AllowMethods     []string
	AllowHeaders     []string
	ExposeHeaders    []string
	AllowCredentials bool
	MaxAge           int // preflight cache duration in seconds
}

Config holds CORS configuration.

type Option

type Option func(*Config)

Option configures CORS behavior.

func WithCredentials

func WithCredentials(allow bool) Option

WithCredentials enables credentials (cookies, auth headers).

func WithHeaders

func WithHeaders(headers ...string) Option

WithHeaders sets the allowed request headers.

func WithMaxAge

func WithMaxAge(seconds int) Option

WithMaxAge sets the preflight cache duration in seconds.

func WithMethods

func WithMethods(methods ...string) Option

WithMethods sets the allowed HTTP methods.

func WithOrigins

func WithOrigins(origins ...string) Option

WithOrigins sets the allowed origins. Use "*" to allow all.

Jump to

Keyboard shortcuts

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