middleware

package
v0.8.3 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CORS

func CORS(cfg *CORSConfig) func(http.Handler) http.Handler

CORS returns an HTTP middleware that handles CORS preflight requests and sets CORS headers. This is an HTTP middleware, not an RPC interceptor, so it wraps the entire http.Handler.

func LoggingInterceptor

func LoggingInterceptor(logger *slog.Logger) tygor.UnaryInterceptor

LoggingInterceptor creates an interceptor that logs service calls using slog. It logs the start and end of each call, including duration and error status.

Types

type CORSConfig

type CORSConfig struct {
	// AllowOrigins is a list of origins a cross-domain request can be executed from.
	// If the list contains "*", all origins are allowed.
	// Default: ["*"]
	AllowOrigins []string

	// AllowMethods is a list of methods the client is allowed to use.
	// Default: ["GET", "POST", "OPTIONS"]
	AllowMethods []string

	// AllowHeaders is a list of headers the client is allowed to use.
	// Default: ["Content-Type", "Authorization"]
	AllowHeaders []string

	// ExposeHeaders indicates which headers are safe to expose.
	// Default: []
	ExposeHeaders []string

	// AllowCredentials indicates whether the request can include credentials.
	// Default: false
	AllowCredentials bool

	// MaxAge indicates how long (in seconds) the results of a preflight request can be cached.
	// Default: 0 (not set)
	MaxAge int
}

CORSConfig holds the configuration for CORS middleware.

var CORSAllowAll *CORSConfig = nil

CORSAllowAll is a permissive CORS configuration suitable for development. It allows all origins (*), standard methods (GET, POST, OPTIONS), and common headers (Content-Type, Authorization).

Jump to

Keyboard shortcuts

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