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 RPC calls using slog. It logs the start and end of each RPC call, including duration and error status.
Types ¶
type CORSConfig ¶
type CORSConfig struct {
// AllowedOrigins is a list of origins a cross-domain request can be executed from.
// If the list contains "*", all origins are allowed.
// Default: ["*"]
AllowedOrigins []string
// AllowedMethods is a list of methods the client is allowed to use.
// Default: ["GET", "POST", "OPTIONS"]
AllowedMethods []string
// AllowedHeaders is a list of headers the client is allowed to use.
// Default: ["Content-Type", "Authorization"]
AllowedHeaders []string
// ExposedHeaders indicates which headers are safe to expose.
// Default: []
ExposedHeaders []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.
func DefaultCORSConfig ¶
func DefaultCORSConfig() *CORSConfig
DefaultCORSConfig returns a permissive CORS configuration suitable for development.
Click to show internal directories.
Click to hide internal directories.