cors.go — fiber Source File
Architecture documentation for cors.go, a go file in the fiber codebase. 1 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 44855f15_c1df_ce6b_695f_24aa3cc78dd0["cors.go"] e9b3c682_1f19_c962_6398_ff9f102d5615["slices"] 44855f15_c1df_ce6b_695f_24aa3cc78dd0 --> e9b3c682_1f19_c962_6398_ff9f102d5615 style 44855f15_c1df_ce6b_695f_24aa3cc78dd0 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
package cors
import (
"slices"
"strconv"
"strings"
"github.com/gofiber/fiber/v3"
"github.com/gofiber/fiber/v3/log"
"github.com/gofiber/utils/v2"
)
const redactedValue = "[redacted]"
// isOriginSerializedOrNull checks if the origin is a serialized origin or the literal "null".
// It returns two booleans: (isSerialized, isNull).
func isOriginSerializedOrNull(originHeaderRaw string) (isSerialized, isNull bool) { //nolint:nonamedreturns // gocritic unnamedResult prefers naming serialization and null status results
if originHeaderRaw == "null" {
return false, true
}
originIsSerialized, _ := normalizeOrigin(originHeaderRaw)
return originIsSerialized, false
}
// New creates a new middleware handler
func New(config ...Config) fiber.Handler {
// Set default config
cfg := ConfigDefault
// Override config if provided
if len(config) > 0 {
cfg = config[0]
// Set default values
if len(cfg.AllowMethods) == 0 {
cfg.AllowMethods = ConfigDefault.AllowMethods
}
}
redactValues := !cfg.DisableValueRedaction
maskValue := func(value string) string {
if redactValues {
return redactedValue
}
return value
}
// Warning logs if both AllowOrigins and AllowOriginsFunc are set
if len(cfg.AllowOrigins) > 0 && cfg.AllowOriginsFunc != nil {
log.Warn("[CORS] Both 'AllowOrigins' and 'AllowOriginsFunc' have been defined.")
}
// allowOrigins is a slice of strings that contains the allowed origins
// defined in the 'AllowOrigins' configuration.
allowOrigins := []string{}
allowSubOrigins := []subdomain{}
// Validate and normalize static AllowOrigins
// ... (190 more lines)
Domain
Subdomains
Dependencies
- slices
Source
Frequently Asked Questions
What does cors.go do?
cors.go is a source file in the fiber codebase, written in go. It belongs to the FiberCore domain, Adapters subdomain.
What functions are defined in cors.go?
cors.go defines 4 function(s): New, isOriginSerializedOrNull, setPreflightHeaders, setSimpleHeaders.
What does cors.go depend on?
cors.go imports 1 module(s): slices.
Where is cors.go in the architecture?
cors.go is located at middleware/cors/cors.go (domain: FiberCore, subdomain: Adapters, directory: middleware/cors).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free