Documentation
¶
Index ¶
- Variables
- func BuildAbsoluteReference(baseRef, jsonPtr string) string
- func BuildString(parts ...string) string
- func ClearGlobalURLCache()
- func IsFilePath(ref string) bool
- func IsFragment(ref string) bool
- func IsURL(ref string) bool
- func JoinReference(base, relative string) (string, error)
- func JoinWithSeparator(separator string, parts ...string) string
- func MapSlice[T any, U any](slice []T, fn func(T) U) []U
- func ParseURLCached(rawURL string) (*url.URL, error)
- func ParseVersion(version string) (int, int, int, error)
- type ReferenceClassification
- type ReferenceType
- type URLCache
- type URLCacheStats
Constants ¶
This section is empty.
Variables ¶
var StringBuilderPool = sync.Pool{ New: func() interface{} { return &strings.Builder{} }, }
StringBuilderPool provides a pool of string builders to reduce allocations when building strings, especially for repeated operations like reference resolution.
Functions ¶
func BuildAbsoluteReference ¶ added in v1.0.0
BuildAbsoluteReference efficiently builds an absolute reference string by combining a base reference with a JSON pointer. For this specific 3-string concatenation pattern, Go's optimized string concatenation is faster than string builders.
func BuildString ¶ added in v1.0.0
BuildString efficiently builds a string from multiple parts using a pooled string builder. This is useful for any string concatenation operations that happen frequently.
func ClearGlobalURLCache ¶ added in v1.0.0
func ClearGlobalURLCache()
ClearGlobalURLCache clears the global URL cache
func IsFilePath ¶ added in v1.0.0
IsFilePath returns true if the reference string represents a file path
func IsFragment ¶ added in v1.0.0
IsFragment returns true if the reference string represents a JSON Pointer fragment
func JoinReference ¶ added in v1.0.0
JoinReference is a convenience function that classifies the base reference and joins it with a relative reference. For better performance when you already have a classification, use ReferenceClassification.JoinWith() instead.
func JoinWithSeparator ¶ added in v1.0.0
JoinWithSeparator efficiently joins strings with a separator using a pooled string builder. This is more efficient than strings.Join for frequently called operations.
func ParseURLCached ¶ added in v1.0.0
ParseURLCached parses a URL string using a cache to avoid repeated parsing of the same URLs. This is particularly beneficial when the same base URLs are parsed thousands of times.
Types ¶
type ReferenceClassification ¶ added in v1.0.0
type ReferenceClassification struct { Type ReferenceType IsURL bool IsFile bool IsFragment bool Original string ParsedURL *url.URL // Cached parsed URL to avoid re-parsing }
ReferenceClassification holds the result of classifying a reference string
func ClassifyReference ¶ added in v1.0.0
func ClassifyReference(ref string) (*ReferenceClassification, error)
ClassifyReference determines if a string represents a URL, file path, or JSON Pointer fragment. It returns detailed classification information and any parsing errors.
func (*ReferenceClassification) JoinWith ¶ added in v1.0.0
func (rc *ReferenceClassification) JoinWith(relative string) (string, error)
JoinWith joins this classified reference with a relative reference. It uses the cached classification and parsed URL (if available) to avoid re-parsing. For URLs, it uses the cached ParsedURL and ResolveReference. For file paths, it uses filepath.Join. Fragments are handled specially and can be combined with both URLs and file paths.
type ReferenceType ¶ added in v1.0.0
type ReferenceType int
ReferenceType represents the type of reference string
const ( ReferenceTypeUnknown ReferenceType = iota ReferenceTypeURL ReferenceTypeFilePath ReferenceTypeFragment )
type URLCache ¶ added in v1.0.0
type URLCache struct {
// contains filtered or unexported fields
}
URLCache provides a thread-safe cache for parsed URLs to avoid repeated parsing
type URLCacheStats ¶ added in v1.0.0
type URLCacheStats struct {
Size int64
}
Stats returns basic statistics about the cache
func GetURLCacheStats ¶ added in v1.0.0
func GetURLCacheStats() URLCacheStats
GetStats returns statistics about the global URL cache