Documentation
¶
Overview ¶
Package core re-exports error types from the canonical errors package for backward compatibility. New code should import modules/errors directly.
Package core provides object pool implementation to reduce GC pressure ¶
Package core provides memory pool monitoring metrics ¶
Package core provides core interface definitions ¶
Package core provides core types and fundamental definitions for the fingerprint library This is the base dependency for all modules, does not depend on any other internal packages
Package core provides utility functions ¶
Package core provides input validation utilities
Index ¶
- Constants
- Variables
- func AcquireBuffer() *bytes.Buffer
- func AcquireMap() map[string]interface{}
- func AcquireSlice() []byte
- func AcquireStringBuilder() *strings.Builder
- func CalculateJA3Hash(tlsVersion uint16, cipherSuites, extensions, curves, points []uint16) string
- func CalculateMD5(data []byte) string
- func CalculateSHA256(data []byte) string
- func Contains[T comparable](slice []T, elem T) bool
- func CopyMap(m map[string]string) map[string]string
- func Filter[T any](slice []T, predicate func(T) bool) []T
- func ForceGC() runtime.MemStats
- func GenerateRandomID() string
- func GetAllPoolStats() map[string]PoolStats
- func GetMemoryStats() runtime.MemStats
- func HexSliceToString(data []byte) string
- func InitPools()
- func InitPoolsWithConfig(config *PoolConfig)
- func IsCoreError(err error) bool
- func IsErrorCode(err error, code ErrorCode) bool
- func Map[T, U any](slice []T, mapper func(T) U) []U
- func MergeMaps(maps ...map[string]string) map[string]string
- func NormalizeString(s string) string
- func ParseTLSVersion(version string) uint16
- func PtrBool(b bool) *bool
- func PtrInt(i int) *int
- func PtrString(s string) *string
- func RandomChoice[T any](slice []T) T
- func RandomChoiceWithSeed[T any](slice []T, seed int64) T
- func ReleaseBuffer(b *bytes.Buffer)
- func ReleaseFeatureVector(fv *FeatureVector)
- func ReleaseHTTPHeaders(h *HTTPHeaders)
- func ReleaseMap(m map[string]interface{})
- func ReleaseSlice(s []byte)
- func ReleaseStringBuilder(sb *strings.Builder)
- func ResetPoolMetrics()
- func SafeDereference(ptr *int, defaultVal int) int
- func SafeSliceAccess(slice []interface{}, index int) (interface{}, bool)
- func SafeString(s *string) string
- func SanitizeString(s string, maxLen int) string
- func Shuffle[T any](slice []T)
- func StringSliceToString(slice []string) string
- func TLSVersionToString(version uint16) string
- func TruncateString(s string, maxLen int) string
- func Uint16SliceToString(slice []uint16) string
- func Unique[T comparable](slice []T) []T
- func ValidateJA3Hash(hash string) error
- func ValidateTLSVersion(version uint16) error
- type BrowserType
- type BufferPool
- type ClassificationResult
- type ClientHelloSpec
- type CoreError
- func NewCodedError(code ErrorCode, op string, err error) *CoreError
- func NewCodedErrorf(code ErrorCode, op, format string, args ...interface{}) *CoreError
- func WrapError(code ErrorCode, op string, err error, context string) *CoreError
- func WrapErrorf(code ErrorCode, op string, err error, format string, args ...interface{}) *CoreError
- type CurveID
- type ErrorCode
- type FeatureType
- type FeatureVector
- type FeatureVectorPool
- type FingerprintResult
- type FingerprintSpec
- type GlobalPools
- type HTTP2Priority
- type HTTP2Settings
- type HTTP3Settings
- type HTTPHeaders
- func (h *HTTPHeaders) Clone() *HTTPHeaders
- func (h *HTTPHeaders) Merge(customHeaders map[string]string) *HTTPHeaders
- func (h *HTTPHeaders) Set(key, value string)
- func (h *HTTPHeaders) SetHeaders(customHeaders map[string]string)
- func (h *HTTPHeaders) ToMap() map[string]string
- func (h *HTTPHeaders) ToMapWithCustom(customHeaders map[string]string) map[string]string
- type HTTPHeadersPool
- type Logger
- type LogrusAdapter
- type LogrusLogger
- type MapPool
- type NoOpLogger
- type OperatingSystem
- type PoolConfig
- type PoolMonitor
- type PoolStats
- type PoolSummary
- type ProtocolType
- type RiskAssessment
- type RiskFactor
- type RiskLevel
- type SlicePool
- type SlogAdapter
- type StdLoggerAdapter
- type StringBuilderPool
- type TLSClient
- type TLSExtension
- type UserAgentTemplate
- type Validator
- func (v *Validator) AddError(err error)
- func (v *Validator) AddErrorf(format string, args ...interface{})
- func (v *Validator) Error() error
- func (v *Validator) Errors() []error
- func (v *Validator) HasErrors() bool
- func (v *Validator) InRange(n, min, max int, name string) *Validator
- func (v *Validator) Matches(s string, pattern *regexp.Regexp, name string) *Validator
- func (v *Validator) MaxLength(s string, max int, name string) *Validator
- func (v *Validator) MinLength(s string, min int, name string) *Validator
- func (v *Validator) NotEmpty(s string, name string) *Validator
- func (v *Validator) NotNil(val interface{}, name string) *Validator
- func (v *Validator) NotZero(n int, name string) *Validator
- func (v *Validator) Positive(n int, name string) *Validator
- func (v *Validator) ValidBrowserType(bt BrowserType, name string) *Validator
- func (v *Validator) ValidOS(os OperatingSystem, name string) *Validator
- type ZapAdapter
- type ZapLogger
Constants ¶
const ( // DefaultTimeout default timeout duration DefaultTimeout = 30 * time.Second // DefaultDialTimeout default connection timeout DefaultDialTimeout = 10 * time.Second // DefaultTLSTimeout default TLS handshake timeout DefaultTLSTimeout = 15 * time.Second // DefaultDNSTimeout default DNS resolution timeout DefaultDNSTimeout = 5 * time.Second // DefaultReadTimeout default read timeout DefaultReadTimeout = 10 * time.Second )
const ( // DefaultCacheSize default cache size DefaultCacheSize = 10000 // DefaultCacheTTL default cache expiration time DefaultCacheTTL = 5 * time.Minute // MaxCacheKeySize maximum cache key length MaxCacheKeySize = 1024 )
const ( // DefaultRateLimit default requests per second limit DefaultRateLimit = 1000 // DefaultRateLimitBurst default burst request count DefaultRateLimitBurst = 2000 // DefaultRateLimitWindow default rate limit window DefaultRateLimitWindow = time.Second // DefaultVisitorTTL default visitor log expiration time DefaultVisitorTTL = 5 * time.Minute )
const ( // MaxRequestBodySize maximum request body size (5MB) MaxRequestBodySize = 5 * 1024 * 1024 // MaxRedirects maximum redirect count MaxRedirects = 10 // MaxHeaderSize maximum header size (1MB) MaxHeaderSize = 1 * 1024 * 1024 )
const ( // RiskThresholdLow low risk threshold RiskThresholdLow = 0.1 // RiskThresholdMedium medium risk threshold RiskThresholdMedium = 0.4 // RiskThresholdHigh high risk threshold RiskThresholdHigh = 0.7 // RiskThresholdCritical critical risk threshold RiskThresholdCritical = 0.9 )
const ( // TLSVersion13 TLS 1.3 TLSVersion13 = 0x0304 // TLSVersion12 TLS 1.2 TLSVersion12 = 0x0303 // TLSVersion11 TLS 1.1 TLSVersion11 = 0x0302 // TLSVersion10 TLS 1.0 TLSVersion10 = 0x0301 )
const ( // DefaultHTTPTimeout default HTTP timeout DefaultHTTPTimeout = 30 * time.Second // DefaultHTTPReadTimeout HTTP read timeout DefaultHTTPReadTimeout = 10 * time.Second // DefaultHTTPWriteTimeout HTTP write timeout DefaultHTTPWriteTimeout = 10 * time.Second // DefaultIdleConnTimeout idle connection timeout DefaultIdleConnTimeout = 30 * time.Second // DefaultResponseHeaderTimeout response header timeout DefaultResponseHeaderTimeout = 8 * time.Second // DefaultExpectContinueTimeout ExpectContinue timeout DefaultExpectContinueTimeout = 1 * time.Second // DefaultKeepAliveInterval TCP keep-alive interval DefaultKeepAliveInterval = 30 * time.Second )
const ( // DefaultScanTimeout default scan timeout DefaultScanTimeout = 20 * time.Second // MinScanTimeout minimum scan timeout MinScanTimeout = 10 * time.Second // MaxScanTimeout maximum scan timeout MaxScanTimeout = 120 * time.Second // DefaultBrowserTimeout default browser scraping timeout DefaultBrowserTimeout = 25 * time.Second // DefaultBrowserWaitMs browser wait milliseconds DefaultBrowserWaitMs = 1200 // MaxBrowserWaitMs maximum browser wait milliseconds MaxBrowserWaitMs = 3500 // DefaultRemainingBudget default remaining time budget DefaultRemainingBudget = 12 * time.Second // MinRequestTimeout minimumrequesttimeout MinRequestTimeout = 3 * time.Second // MaxRequestTimeout maximumrequesttimeout MaxRequestTimeout = 20 * time.Second )
const ( // DefaultSessionTimeout default session timeout DefaultSessionTimeout = 30 * time.Minute // DefaultPoolIdleTime connection pool idle time DefaultPoolIdleTime = 10 * time.Minute )
const ( // Size1KB 1 KB Size1KB = 1024 // Size1MB 1 MB Size1MB = 1024 * 1024 // Size5MB 5 MB Size5MB = 5 * 1024 * 1024 // Size10MB 10 MB Size10MB = 10 * 1024 * 1024 // MaxCapturedScriptBytes maximum captured script bytes MaxCapturedScriptBytes = 1 * 1024 * 1024 // MaxConfigDataSize maximumconfigurationdatasize MaxConfigDataSize = 1 * 1024 * 1024 )
const ( ErrCodeInvalidInput = errs.ErrCodeInvalidInput ErrCodeRequiredField = errs.ErrCodeRequiredField ErrCodeInvalidFormat = errs.ErrCodeInvalidFormat ErrCodeOutOfRange = errs.ErrCodeOutOfRange ErrCodeNilPointer = errs.ErrCodeNilPointer ErrCodeInvalidType = errs.ErrCodeInvalidType ErrCodeEmptyValue = errs.ErrCodeEmptyValue ErrCodeInvalidLength = errs.ErrCodeInvalidLength ErrCodeInvalidCharset = errs.ErrCodeInvalidCharset ErrCodeInvalidPattern = errs.ErrCodeInvalidPattern )
Validation error codes (VAL001-VAL010)
const ( ErrCodeProfileNotFound = errs.ErrCodeProfileNTF ErrCodeResourceNotFound = errs.ErrCodeResourceNTF ErrCodeKeyNotFound = errs.ErrCodeKeyNTF ErrCodeFileNotFound = errs.ErrCodeFileNTF ErrCodeRouteNotFound = errs.ErrCodeRouteNTF )
Not Found error codes (NTF001-NTF005)
const ( ErrCodeSecurityError = errs.ErrCodeSecurityError ErrCodeAuthFailed = errs.ErrCodeAuthFailed ErrCodeForbidden = errs.ErrCodeForbidden ErrCodeInvalidToken = errs.ErrCodeInvalidToken ErrCodeReplayAttack = errs.ErrCodeReplayAttack ErrCodeFingerprintMismatch = errs.ErrCodeFingerprintMismatch ErrCodeInvalidTLSVersion = errs.ErrCodeInvalidTLSVersion ErrCodeInvalidJA3Hash = errs.ErrCodeInvalidJA3Hash ErrCodeInvalidJA4Hash = errs.ErrCodeInvalidJA4Hash )
Security error codes (SEC001-SEC010)
const ( QUICVersion1 uint32 = 0x00000001 // RFC 9000 QUICVersionDraft29 uint32 = 0xff00001d // Draft 29 QUICVersionDraft30 uint32 = 0xff00001e // Draft 30 QUICVersionDraft31 uint32 = 0xff00001f // Draft 31 QUICVersionDraft32 uint32 = 0xff000020 // Draft 32 )
QUICVersion defines known QUIC versions
Variables ¶
var ( ErrInvalidProfile = errs.ErrInvalidProfile ErrProfileNotFound = errs.ErrProfileNotFound ErrUnsupportedBrowser = errs.ErrUnsupportedBrowser ErrInvalidTLSVersion = errs.ErrInvalidTLSVersion ErrInvalidJA3Hash = errs.ErrInvalidJA3Hash ErrInvalidJA4Hash = errs.ErrInvalidJA4Hash ErrFeatureExtractionFailed = errs.ErrFeatureExtractionFailed ErrClassificationFailed = errs.ErrClassificationFailed ErrRiskAssessmentFailed = errs.ErrRiskAssessmentFailed ErrNilPointer = errs.ErrNilPointer ErrInvalidInput = errs.ErrInvalidInput ErrOutOfRange = errs.ErrOutOfRange ErrEmptyValue = errs.ErrEmptyValue ErrAlreadyExists = errs.ErrAlreadyExists )
Sentinel errors re-exported from errors package
var DefaultPoolConfig = PoolConfig{ MaxSize: 10000, InitialSize: 100, EnableMetrics: true, }
DefaultPoolConfig default pool configuration
var GlobalMonitor = NewPoolMonitor()
GlobalMonitor global monitor instance
var GlobalPoolMetrics = struct { // individual pool statistics FeatureVectorGets int64 FeatureVectorPuts int64 FeatureVectorHits int64 HTTPHeadersGets int64 HTTPHeadersPuts int64 HTTPHeadersHits int64 StringBuilderGets int64 StringBuilderPuts int64 MapPoolGets int64 MapPoolPuts int64 SlicePoolGets int64 SlicePoolPuts int64 // summaries TotalAllocations int64 TotalReleases int64 }{}
GlobalPoolMetrics global pool metrics (atomic operations)
var OperatingSystems = []OperatingSystem{ OSWindows10, OSMacOS13, OSMacOS14, OSMacOS15, OSLinux, OSiOS, OSiPadOS, OSAndroid, }
OperatingSystems operating system list (for random selection, deduplicated to avoid probability bias)
var Pools = &GlobalPools{}
Pools global pool instances
Functions ¶
func AcquireStringBuilder ¶
AcquireStringBuilder get strings.Builder
func CalculateJA3Hash ¶
CalculateJA3Hash calculates JA3 hash (simplified version)
func CalculateSHA256 ¶
CalculateSHA256 calculates SHA256 hash
func Contains ¶
func Contains[T comparable](slice []T, elem T) bool
Contains checks if slice contains element
func GetAllPoolStats ¶
GetAllPoolStats gets all pool statistics
func HexSliceToString ¶
HexSliceToString converts byte slice to hexadecimal string
func InitPoolsWithConfig ¶
func InitPoolsWithConfig(config *PoolConfig)
InitPoolsWithConfig initializes global object pools with custom configuration
func IsCoreError ¶
func IsErrorCode ¶
func NormalizeString ¶
NormalizeString normalizes string (lowercase, trim spaces)
func ParseTLSVersion ¶
ParseTLSVersion parses TLS version string
func RandomChoice ¶
func RandomChoice[T any](slice []T) T
RandomChoice randomly selects one element from slice
func RandomChoiceWithSeed ¶
RandomChoiceWithSeed randomly selects from slice using specified seed
func ReleaseBuffer ¶
ReleaseBuffer releases bytes.Buffer back to pool
func ReleaseFeatureVector ¶
func ReleaseFeatureVector(fv *FeatureVector)
ReleaseFeatureVector releases FeatureVector back to pool
func ReleaseHTTPHeaders ¶
func ReleaseHTTPHeaders(h *HTTPHeaders)
ReleaseHTTPHeaders releases HTTPHeaders back to pool
func ReleaseStringBuilder ¶
ReleaseStringBuilder releases strings.Builder back to pool
func SafeDereference ¶
SafeDereference safely dereferences pointer
func SafeSliceAccess ¶
SafeSliceAccess safely accesses slice
func SanitizeString ¶
SanitizeString sanitizes string input
func StringSliceToString ¶
StringSliceToString converts string slice to comma-separated string
func TLSVersionToString ¶
TLSVersionToString converts TLS version to string
func TruncateString ¶
TruncateString truncates string to specified length
func Uint16SliceToString ¶
Uint16SliceToString converts uint16 slice to comma-separated string
func ValidateTLSVersion ¶
ValidateTLSVersion validates TLS version
Types ¶
type BrowserType ¶
type BrowserType string
BrowserType browser type
const ( BrowserChrome BrowserType = "chrome" BrowserFirefox BrowserType = "firefox" BrowserSafari BrowserType = "safari" BrowserOpera BrowserType = "opera" BrowserEdge BrowserType = "edge" BrowserBrave BrowserType = "brave" BrowserSamsung BrowserType = "samsung" )
type BufferPool ¶
type BufferPool struct {
// contains filtered or unexported fields
}
BufferPool bytes.Buffer object pool
func NewBufferPool ¶
func NewBufferPool(config *PoolConfig) *BufferPool
NewBufferPool creates a new Buffer pool
func (*BufferPool) Get ¶
func (p *BufferPool) Get() *bytes.Buffer
Get fetches bytes.Buffer from pool
func (*BufferPool) Put ¶
func (p *BufferPool) Put(b *bytes.Buffer)
Put returns bytes.Buffer back to pool
type ClassificationResult ¶
type ClassificationResult struct {
Protocol ProtocolType
Family BrowserType
Version string
Confidence float64
Labels map[string]string
}
ClassificationResult classifyresult
type ClientHelloSpec ¶
type ClientHelloSpec struct {
CipherSuites []uint16
Extensions []TLSExtension
SupportedCurves []CurveID
SupportedPoints []uint8
TLSVersion uint16
CompressionMethods []uint8
}
ClientHelloSpec TLS ClientHello specification
type CoreError ¶
func NewCodedError ¶
Error creation functions re-exported from errors package
func NewCodedErrorf ¶
type FeatureType ¶
type FeatureType string
FeatureType featuretype
const ( FeatureTLSVersion FeatureType = "tls_version" FeatureCipherSuites FeatureType = "cipher_suites" FeatureExtensions FeatureType = "extensions" FeatureHTTP2Settings FeatureType = "http2_settings" FeatureHTTPHeaders FeatureType = "http_headers" FeatureUserAgent FeatureType = "user_agent" FeatureCanvas FeatureType = "canvas" FeatureWebGL FeatureType = "webgl" FeatureAudio FeatureType = "audio" FeatureFonts FeatureType = "fonts" FeatureStorage FeatureType = "storage" FeatureWebRTC FeatureType = "webrtc" FeatureHardware FeatureType = "hardware" FeatureTiming FeatureType = "timing" FeatureHeadlessBrowser FeatureType = "headless_browser" FeatureEntropy FeatureType = "entropy" FeatureToolMarker FeatureType = "tool_marker" FeatureBehaviorPattern FeatureType = "behavior_pattern" )
type FeatureVector ¶
type FeatureVector struct {
Features map[FeatureType]float64
Metadata map[string]interface{}
}
FeatureVector feature vector
func AcquireFeatureVector ¶
func AcquireFeatureVector() *FeatureVector
AcquireFeatureVector get FeatureVector
func NewFeatureVector ¶
func NewFeatureVector() *FeatureVector
NewFeatureVector creates new feature vector
func (*FeatureVector) Get ¶
func (fv *FeatureVector) Get(feature FeatureType) float64
Get gets feature value
func (*FeatureVector) Set ¶
func (fv *FeatureVector) Set(feature FeatureType, value float64)
Set sets feature value
type FeatureVectorPool ¶
type FeatureVectorPool struct {
// contains filtered or unexported fields
}
FeatureVectorPool FeatureVector object pool
func NewFeatureVectorPool ¶
func NewFeatureVectorPool(config *PoolConfig) *FeatureVectorPool
NewFeatureVectorPool creates a new FeatureVector pool
func (*FeatureVectorPool) Get ¶
func (p *FeatureVectorPool) Get() *FeatureVector
Get fetches FeatureVector from pool
func (*FeatureVectorPool) Put ¶
func (p *FeatureVectorPool) Put(fv *FeatureVector)
Put returns FeatureVector back to pool
func (*FeatureVectorPool) Stats ¶
func (p *FeatureVectorPool) Stats() PoolStats
Stats gets pool statistics
type FingerprintResult ¶
type FingerprintResult interface {
// GetUserAgent return User-Agent
GetUserAgent() string
// GetHeaders return HTTP Headers
GetHeaders() *HTTPHeaders
// GetSpec returns fingerprint specification
GetSpec() FingerprintSpec
}
FingerprintResult fingerprint result interface
type FingerprintSpec ¶
type FingerprintSpec interface {
// GetID returns unique fingerprint identifier
GetID() string
// GetBrowserType returns browser type
GetBrowserType() BrowserType
// GetOS returns operating system
GetOS() OperatingSystem
}
FingerprintSpec fingerprint specification interface
type GlobalPools ¶
type GlobalPools struct {
FeatureVectors *FeatureVectorPool
HTTPHeaders *HTTPHeadersPool
Strings *StringBuilderPool
Buffers *BufferPool
Maps *MapPool
Slices *SlicePool
}
type HTTP2Priority ¶
HTTP2Priority HTTP/2 Priority
type HTTP2Settings ¶
type HTTP2Settings struct {
HeaderTableSize uint32
EnablePush uint32
MaxConcurrentStreams uint32
InitialWindowSize uint32
MaxFrameSize uint32
MaxHeaderListSize uint32
}
HTTP2Settings HTTP/2 Settings
type HTTP3Settings ¶ added in v1.0.5
type HTTP3Settings struct {
QUICVersion uint32 // QUIC version (e.g., 0x00000001 for RFC 9000)
InitialMaxData uint64 // initial maximum data
InitialMaxStreamData uint64 // initial maximum stream data
InitialMaxStreamsBidi uint64 // initial maximum bidirectional streams
InitialMaxStreamsUni uint64 // initial maximum unidirectional streams
MaxUDPPayloadSize uint64 // maximum UDP payload size
AckDelayExponent uint8 // ACK delay exponent
MaxAckDelay uint16 // maximum ACK delay (ms)
DisableActiveMigration bool // disable active connection migration
}
HTTP3Settings HTTP/3 (QUIC) Settings
type HTTPHeaders ¶
type HTTPHeaders struct {
Accept string // Accept header
AcceptLanguage string // Accept-Language header (supports global languages)
AcceptEncoding string // Accept-Encoding header
UserAgent string // User-Agent header
SecFetchSite string // Sec-Fetch-Site header
SecFetchMode string // Sec-Fetch-Mode header
SecFetchUser string // Sec-Fetch-User header
SecFetchDest string // Sec-Fetch-Dest header
SecCHUA string // Sec-CH-UA header
SecCHUAMobile string // Sec-CH-UA-Mobile header
SecCHUAPlatform string // Sec-CH-UA-Platform header
UpgradeInsecureRequests string // Upgrade-Insecure-Requests header
Custom map[string]string // user-defined headers
}
HTTPHeaders standard HTTP request headers
func (*HTTPHeaders) Clone ¶
func (h *HTTPHeaders) Clone() *HTTPHeaders
Clone clones HTTPHeaders object, returns a new copy
func (*HTTPHeaders) Merge ¶
func (h *HTTPHeaders) Merge(customHeaders map[string]string) *HTTPHeaders
Merge merges user-defined headers
func (*HTTPHeaders) SetHeaders ¶
func (h *HTTPHeaders) SetHeaders(customHeaders map[string]string)
SetHeaders batch sets user-defined headers
func (*HTTPHeaders) ToMap ¶
func (h *HTTPHeaders) ToMap() map[string]string
ToMap converts HTTPHeaders to map[string]string
func (*HTTPHeaders) ToMapWithCustom ¶
func (h *HTTPHeaders) ToMapWithCustom(customHeaders map[string]string) map[string]string
ToMapWithCustom converts HTTPHeaders to map[string]string and merges user-defined headers
type HTTPHeadersPool ¶
type HTTPHeadersPool struct {
// contains filtered or unexported fields
}
HTTPHeadersPool HTTPHeaders object pool
func NewHTTPHeadersPool ¶
func NewHTTPHeadersPool(config *PoolConfig) *HTTPHeadersPool
NewHTTPHeadersPool creates a new HTTPHeaders pool
func (*HTTPHeadersPool) Get ¶
func (p *HTTPHeadersPool) Get() *HTTPHeaders
Get fetches HTTPHeaders from pool
func (*HTTPHeadersPool) Put ¶
func (p *HTTPHeadersPool) Put(h *HTTPHeaders)
Put returns HTTPHeaders back to pool
func (*HTTPHeadersPool) Stats ¶
func (p *HTTPHeadersPool) Stats() PoolStats
Stats gets pool statistics
type Logger ¶ added in v1.0.5
type Logger interface {
// Debug logdebuginfo
Debug(msg string, keysAndValues ...any)
// Info logs general information
Info(msg string, keysAndValues ...any)
// Warn logwarninginfo
Warn(msg string, keysAndValues ...any)
// Error logerrorinfo
Error(msg string, keysAndValues ...any)
}
Logger standard logging interface design principle: minimal interface, adapts to most logging libraries
func NewDefaultLogger ¶ added in v1.0.5
NewDefaultLogger creates default slog logger
func NewLogrusAdapter ¶ added in v1.0.5
func NewLogrusAdapter(logger LogrusLogger) Logger
NewLogrusAdapter create logrus adapter
func NewSlogAdapter ¶ added in v1.0.5
NewSlogAdapter create slog adapter
func NewStdLoggerAdapter ¶ added in v1.0.5
NewStdLoggerAdapter creates standard library log adapter
func NewZapAdapter ¶ added in v1.0.5
NewZapAdapter create zap adapter
type LogrusAdapter ¶ added in v1.0.5
type LogrusAdapter struct {
// contains filtered or unexported fields
}
LogrusAdapter adapts logrus.Logger
func (*LogrusAdapter) Debug ¶ added in v1.0.5
func (a *LogrusAdapter) Debug(msg string, keysAndValues ...any)
func (*LogrusAdapter) Error ¶ added in v1.0.5
func (a *LogrusAdapter) Error(msg string, keysAndValues ...any)
func (*LogrusAdapter) Info ¶ added in v1.0.5
func (a *LogrusAdapter) Info(msg string, keysAndValues ...any)
func (*LogrusAdapter) Warn ¶ added in v1.0.5
func (a *LogrusAdapter) Warn(msg string, keysAndValues ...any)
type LogrusLogger ¶ added in v1.0.5
type LogrusLogger interface {
Debug(args ...any)
Info(args ...any)
Warn(args ...any)
Error(args ...any)
WithFields(fields map[string]any) LogrusLogger
}
LogrusLogger interface definition (avoid direct dependency on logrus)
type MapPool ¶
type MapPool struct {
// contains filtered or unexported fields
}
MapPool map object pool
type NoOpLogger ¶ added in v1.0.5
type NoOpLogger struct{}
NoOpLogger empty log implementation, used for default values or testing
func (NoOpLogger) Debug ¶ added in v1.0.5
func (l NoOpLogger) Debug(msg string, keysAndValues ...any)
func (NoOpLogger) Error ¶ added in v1.0.5
func (l NoOpLogger) Error(msg string, keysAndValues ...any)
func (NoOpLogger) Info ¶ added in v1.0.5
func (l NoOpLogger) Info(msg string, keysAndValues ...any)
func (NoOpLogger) Warn ¶ added in v1.0.5
func (l NoOpLogger) Warn(msg string, keysAndValues ...any)
type OperatingSystem ¶
type OperatingSystem string
OperatingSystem operating system type
const ( OSWindows10 OperatingSystem = "Windows NT 10.0; Win64; x64" // OSWindows11 UA is same as Win10 (actual browser behavior), distinguished by Sec-CH-UA-Platform-Version OSWindows11 OperatingSystem = "Windows NT 10.0; Win64; x64" OSMacOS13 OperatingSystem = "Macintosh; Intel Mac OS X 13_0_0" OSMacOS14 OperatingSystem = "Macintosh; Intel Mac OS X 14_0_0" OSMacOS15 OperatingSystem = "Macintosh; Intel Mac OS X 15_0_0" OSLinux OperatingSystem = "X11; Linux x86_64" // Following Linux distributions have same UA (actual browser behavior), aliases kept for semantic distinction OSLinuxUbuntu OperatingSystem = "X11; Linux x86_64" OSLinuxDebian OperatingSystem = "X11; Linux x86_64" OSLinuxFedora OperatingSystem = "X11; Linux x86_64" OSiOS OperatingSystem = "iPhone; CPU iPhone OS 17_0" OSiPadOS OperatingSystem = "iPad; CPU OS 17_0" OSAndroid OperatingSystem = "Linux; Android 14" )
type PoolConfig ¶
type PoolConfig struct {
// MaxSize maximum number of objects in pool (0 = unlimited)
MaxSize int
// InitialSize initial number of objects
InitialSize int
// EnableMetrics whether to enable monitoring
EnableMetrics bool
}
PoolConfig pool configuration
type PoolMonitor ¶
type PoolMonitor struct {
// contains filtered or unexported fields
}
PoolMonitor pool monitoring manager
func (*PoolMonitor) AllStats ¶
func (pm *PoolMonitor) AllStats() map[string]PoolStats
AllStats gets all pool statistics
func (*PoolMonitor) Get ¶
func (pm *PoolMonitor) Get(name string) (*poolMetrics, bool)
Get gets pool metrics
func (*PoolMonitor) Register ¶
func (pm *PoolMonitor) Register(name string) *poolMetrics
Register registers pool metrics
func (*PoolMonitor) Summary ¶
func (pm *PoolMonitor) Summary() PoolSummary
Summary gets summary statistics
type PoolStats ¶
type PoolStats struct {
Name string `json:"name"`
HitRate float64 `json:"hit_rate"` // cache hit rate
ObjectsInUse int64 `json:"objects_in_use"` // number of objects in use
TotalGets int64 `json:"total_gets"` // total get count
TotalPuts int64 `json:"total_puts"` // total put count
CacheHits int64 `json:"cache_hits"` // cache hit count
CacheMisses int64 `json:"cache_misses"` // cache miss count
ActiveObjects int64 `json:"active_objects"` // current active object count (estimated)
}
PoolStats memory pool statistics info
func GetPoolStats ¶
GetPoolStats gets statistics for specified pool
type PoolSummary ¶
type PoolSummary struct {
PoolCount int `json:"pool_count"`
TotalGets int64 `json:"total_gets"`
TotalPuts int64 `json:"total_puts"`
TotalHits int64 `json:"total_hits"`
TotalMisses int64 `json:"total_misses"`
TotalInUse int64 `json:"total_in_use"`
OverallHitRate float64 `json:"overall_hit_rate"`
Pools map[string]PoolStats `json:"pools"`
}
PoolSummary pool summary statistics
type ProtocolType ¶
type ProtocolType string
ProtocolType protocoltype
const ( ProtocolTLS ProtocolType = "tls" ProtocolHTTP ProtocolType = "http" ProtocolHTTP2 ProtocolType = "http2" ProtocolQUIC ProtocolType = "quic" ProtocolHTTP3 ProtocolType = "http3" )
type RiskAssessment ¶
type RiskAssessment struct {
Score float64
Level RiskLevel
Factors []RiskFactor
Suggestions []string
}
RiskAssessment risk assessment result
type RiskFactor ¶
RiskFactor risk factor
type RiskLevel ¶
type RiskLevel int
RiskLevel risk level
func RiskLevelFromScore ¶ added in v1.0.5
RiskLevelFromScore calculates risk level from risk score score range: 0.0-1.0
type SlicePool ¶
type SlicePool struct {
// contains filtered or unexported fields
}
SlicePool byte slice object pool
func NewSlicePool ¶
func NewSlicePool(size int, config *PoolConfig) *SlicePool
NewSlicePool creates a new Slice pool
type SlogAdapter ¶ added in v1.0.5
type SlogAdapter struct {
// contains filtered or unexported fields
}
SlogAdapter adapts slog.Logger
func (*SlogAdapter) Debug ¶ added in v1.0.5
func (a *SlogAdapter) Debug(msg string, keysAndValues ...any)
func (*SlogAdapter) Error ¶ added in v1.0.5
func (a *SlogAdapter) Error(msg string, keysAndValues ...any)
func (*SlogAdapter) Info ¶ added in v1.0.5
func (a *SlogAdapter) Info(msg string, keysAndValues ...any)
func (*SlogAdapter) Warn ¶ added in v1.0.5
func (a *SlogAdapter) Warn(msg string, keysAndValues ...any)
type StdLoggerAdapter ¶ added in v1.0.5
type StdLoggerAdapter struct {
// contains filtered or unexported fields
}
StdLoggerAdapter adapts standard library log.Logger
func (*StdLoggerAdapter) Debug ¶ added in v1.0.5
func (a *StdLoggerAdapter) Debug(msg string, keysAndValues ...any)
func (*StdLoggerAdapter) Error ¶ added in v1.0.5
func (a *StdLoggerAdapter) Error(msg string, keysAndValues ...any)
func (*StdLoggerAdapter) Info ¶ added in v1.0.5
func (a *StdLoggerAdapter) Info(msg string, keysAndValues ...any)
func (*StdLoggerAdapter) Warn ¶ added in v1.0.5
func (a *StdLoggerAdapter) Warn(msg string, keysAndValues ...any)
type StringBuilderPool ¶
type StringBuilderPool struct {
// contains filtered or unexported fields
}
StringBuilderPool strings.Builder object pool
func NewStringBuilderPool ¶
func NewStringBuilderPool(config *PoolConfig) *StringBuilderPool
NewStringBuilderPool creates a new StringBuilder pool
func (*StringBuilderPool) Get ¶
func (p *StringBuilderPool) Get() *strings.Builder
Get fetches strings.Builder from pool
func (*StringBuilderPool) Put ¶
func (p *StringBuilderPool) Put(sb *strings.Builder)
Put returns strings.Builder back to pool
func (*StringBuilderPool) Stats ¶
func (p *StringBuilderPool) Stats() PoolStats
Stats gets pool statistics
type TLSClient ¶
type TLSClient interface {
// GetClientHelloSpec returns ClientHello specification
GetClientHelloSpec() (ClientHelloSpec, error)
// GetJA3 returns JA3 fingerprint string
GetJA3() string
// GetJA4 returns JA4 fingerprint string
GetJA4() string
}
TLSClient defines TLS client capabilities
type TLSExtension ¶
TLSExtension TLS extension definition
type UserAgentTemplate ¶
type UserAgentTemplate struct {
Browser BrowserType
Version string
Template string // template string, use %s placeholder for operating system
Mobile bool // whether it is mobile
OSRequired bool // whether operating system info is required
}
UserAgentTemplate User-Agent template
type Validator ¶
type Validator struct {
// contains filtered or unexported fields
}
Validator input validator
func (*Validator) ValidBrowserType ¶
func (v *Validator) ValidBrowserType(bt BrowserType, name string) *Validator
ValidBrowserType validates browser type
type ZapAdapter ¶ added in v1.0.5
type ZapAdapter struct {
// contains filtered or unexported fields
}
ZapAdapter adapts zap.Logger
func (*ZapAdapter) Debug ¶ added in v1.0.5
func (a *ZapAdapter) Debug(msg string, keysAndValues ...any)
func (*ZapAdapter) Error ¶ added in v1.0.5
func (a *ZapAdapter) Error(msg string, keysAndValues ...any)
func (*ZapAdapter) Info ¶ added in v1.0.5
func (a *ZapAdapter) Info(msg string, keysAndValues ...any)
func (*ZapAdapter) Warn ¶ added in v1.0.5
func (a *ZapAdapter) Warn(msg string, keysAndValues ...any)