cors

package
v2.0.0-alpha.115 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetGlobalPolicy

func SetGlobalPolicy(h Handler)

Sets a global CORS policy that will be applied to incoming requests. The input parameter `h` is an implementation of the Handler interface used to add CORS headers to responses.

Types

type Handler

type Handler func(http.ResponseWriter, *http.Request)

func AllowAll

func AllowAll() Handler

Creates a CORS Handler that allows all origins by setting "Access-Control-Allow-Origin" header to the requester's 'Origin' value. This means any domain can access resources on your server. Use of this function in production is discouraged.

func GetGlobalPolicy

func GetGlobalPolicy() Handler

Retrieves the currently set global CORS policy handler.

func PublicDomain

func PublicDomain() Handler

Creates a CORS handler that allows unrestricted cross-origin access to public APIs. Designed for completely open endpoints WITHOUT authentication/authorization requirements. Example usage:

- Public weather data APIs - Non-sensitive product catalogs - Static asset delivery

func SameOrigin

func SameOrigin(origin ...string) Handler

Creates a CORS Handler that allows requests from origins whose domain is a suffix match for any of the provided domains. Examples:

- SameOrigin("domain1.com") allows http://app.domain1.com, https://api.sub.domain1.com - SameOrigin("sub.domain1.com") allows http://app.sub.domain1.com, https://sub.domain1.com

Jump to

Keyboard shortcuts

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