middleware

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package middleware provides reusable middleware for Gorbit.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllowAllCORS

func AllowAllCORS() gb.Handler

AllowAllCORS returns a middleware that allows requests from any origin.

This is primarily intended for development or trusted environments.

func CORS

func CORS(options ...CORSOptions) gb.Handler

CORS creates a configurable Cross-Origin Resource Sharing (CORS) middleware.

When no options are provided, the default configuration from DefaultCORS is used.

Example:

app.Use(middleware.CORS())

app.Use(middleware.CORS(middleware.CORSOptions{
    AllowOrigins: []string{"https://example.com"},
    AllowMethods: []string{
        http.MethodGet,
        http.MethodPost,
    },
    AllowHeaders: []string{
        "Content-Type",
        "Authorization",
    },
    AllowCredentials: true,
}))

Types

type CORSOptions

type CORSOptions struct {
	AllowOrigins     []string
	AllowMethods     []string
	AllowHeaders     []string
	ExposeHeaders    []string
	AllowCredentials bool
	MaxAge           int
}

CORSOptions configures Cross-Origin Resource Sharing (CORS) behavior for the CORS middleware.

Example:

app.Use(middleware.CORS(middleware.CORSOptions{
    AllowOrigins: []string{"http://localhost:5173"},
    AllowCredentials: true,
}))

func DefaultCORS

func DefaultCORS() CORSOptions

DefaultCORS returns the default CORS configuration.

By default, all origins are allowed and common HTTP methods and headers are enabled.

type Handler

type Handler func(http.Handler) http.Handler

Handler represents a standard HTTP middleware.

It wraps an http.Handler with additional functionality.

Jump to

Keyboard shortcuts

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