cors

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2026 License: MPL-2.0 Imports: 3 Imported by: 2

README

CORS

Middleware to manage CORS.

Usage

Import

import "github.com/ngamux/middleware/cors"

Instance With Default Config

corsMiddleware := cors.New()

Instance With Custom Config

corsMiddleware := cors.New(cors.Config{
  AllowOrigins: "https://github.com, https://apps.github.com",
  AllowHeaders:  "Origin, Content-Type, Accept",
  AllowMethods:     "GET,POST,HEAD,PUT,DELETE,PATCH",
})

Mount Instance to Ngamux

Global Middleware
mux := ngamux.New()
mux.Use(corsMiddleware)
Route Middleware
mux := ngamux.New()
mux.Get("/", corsMiddleware(handler))

or

mux := ngamux.New()
mux.Get("/", ngamux.WithMiddlewares(corsMiddleware)(handler))

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(config ...Config) func(next http.HandlerFunc) http.HandlerFunc

Types

type Config

type Config struct {
	AllowOrigins string
	AllowMethods string
	AllowHeaders string
}

Jump to

Keyboard shortcuts

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