Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config[T interface{}] struct {
Fallback FallbackFunc[T] // The fallback function for timed-out data.
IdentityChecker IdentityChecker[T] // The function to check the identity of data.
Now NowFunc // The function to get the current time. default: time.Now
DefaultTTL time.Duration // The default time-to-live for data. default: 5 minutes. (time.Minute * 5)
Interval time.Duration // The interval for checking timeouts. default: 1 minute. (time.Minute * 1)
Storage Storage // The storage backend. default: memoryStorage
StorageKey string // The key under which data will be stored. default: "tguard_default_key"
WithStandardTTL bool // Whether to use all data with the same expiration time. default: true
}
Config defines the configuration for the service.
type Data ¶
type Data[T interface{}] struct {
Original T `json:"original"` // The original data.
ExpireTime int64 `json:"expire_time"` // The expiration time for the data.
}
Data is the fundamental structure for managing data over time.
type FallbackFunc ¶
type FallbackFunc[T interface{}] func(data T)
FallbackFunc defines the fallback mechanism for timed-out data.
type IdentityChecker ¶
IdentityChecker is a function type used to authenticate data.
type Service ¶
type Service[T interface{}] interface {
Start(ctx context.Context, data T, ttl ...time.Duration) error
Cancel(ctx context.Context, id string) error
GetData(ctx context.Context) ([]Data[T], error)
Connect(ctx context.Context)
}
Service is the interface that defines the core functionality.
type Storage ¶
type Storage interface {
Get(ctx context.Context, key string) (string, error)
Set(ctx context.Context, key string, value interface{}) error
Exist(ctx context.Context, key string) (bool, error)
}
Storage defines where the data will be stored.
func NewMemoryStorage ¶
func NewMemoryStorage() Storage
NewMemoryStorage creates a new Storage instance for in-memory storage.
Click to show internal directories.
Click to hide internal directories.