Documentation
¶
Index ¶
- func AtomicWriteFile(filePath string, data []byte, perm os.FileMode) error
- func CheckHTTPResponse(resp *http.Response, url string) error
- func EnsureDir(dir string, perm os.FileMode) error
- func MarshalJSONIndentString(data interface{}, indent string) (string, error)
- func MarshalJSONString(data interface{}) (string, error)
- func NewDefaultHTTPClient() *http.Client
- func NewHTTPClient(config HTTPClientConfig) *http.Client
- func ReadJSONFile(filePath string, target interface{}) error
- func SafeClose(file *os.File, fileName string)
- func SafeCloseResponse(resp *http.Response)
- func WriteJSONFile(filePath string, data interface{}, options JSONWriteOptions) error
- func WriteJSONFileDefault(filePath string, data interface{}) error
- type HTTPClientConfig
- type HTTPError
- type JSONWriteOptions
- type TTLCache
- func (c *TTLCache) CleanupExpired() int
- func (c *TTLCache) Clear()
- func (c *TTLCache) Delete(key string)
- func (c *TTLCache) Get(key string) (interface{}, bool)
- func (c *TTLCache) Set(key string, value interface{})
- func (c *TTLCache) SetWithTTL(key string, value interface{}, ttl time.Duration)
- func (c *TTLCache) Size() int
- func (c *TTLCache) StartCleanupGoroutine(interval time.Duration)
- type TTLCacheItem
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AtomicWriteFile ¶
AtomicWriteFile writes data to a file atomically using a temporary file This prevents corruption if the process is interrupted during writing
func CheckHTTPResponse ¶
CheckHTTPResponse checks if HTTP response indicates an error
func MarshalJSONIndentString ¶
MarshalJSONIndentString marshals a Go object to an indented JSON string
func MarshalJSONString ¶
MarshalJSONString marshals a Go object to a JSON string
func NewDefaultHTTPClient ¶
NewDefaultHTTPClient creates a new HTTP client with default configuration
func NewHTTPClient ¶
func NewHTTPClient(config HTTPClientConfig) *http.Client
NewHTTPClient creates a new HTTP client with the given configuration
func ReadJSONFile ¶
ReadJSONFile reads a JSON file into a Go object
func SafeCloseResponse ¶
SafeCloseResponse safely closes HTTP response body with error logging
func WriteJSONFile ¶
func WriteJSONFile(filePath string, data interface{}, options JSONWriteOptions) error
WriteJSONFile writes a Go object to a JSON file with the given options
func WriteJSONFileDefault ¶
WriteJSONFileDefault writes a Go object to a JSON file with default options
Types ¶
type HTTPClientConfig ¶
HTTPClientConfig holds configuration for HTTP client creation
func DefaultHTTPClientConfig ¶
func DefaultHTTPClientConfig() HTTPClientConfig
DefaultHTTPClientConfig returns default HTTP client configuration
type JSONWriteOptions ¶
JSONWriteOptions holds options for JSON writing
func DefaultJSONWriteOptions ¶
func DefaultJSONWriteOptions() JSONWriteOptions
DefaultJSONWriteOptions returns default options for JSON writing
type TTLCache ¶
type TTLCache struct {
// contains filtered or unexported fields
}
TTLCache is a thread-safe cache with TTL (Time To Live) support
func NewTTLCache ¶
NewTTLCache creates a new TTL cache with the specified default TTL
func (*TTLCache) CleanupExpired ¶
CleanupExpired removes all expired items from the cache
func (*TTLCache) Get ¶
Get retrieves a value from the cache Returns the value and true if found and not expired, nil and false otherwise
func (*TTLCache) SetWithTTL ¶
SetWithTTL stores a value in the cache with a custom TTL
func (*TTLCache) StartCleanupGoroutine ¶
StartCleanupGoroutine starts a background goroutine that periodically cleans up expired items
type TTLCacheItem ¶
TTLCacheItem represents a cache item with expiration
func (TTLCacheItem) IsExpired ¶
func (item TTLCacheItem) IsExpired() bool
IsExpired checks if the cache item has expired