Documentation
¶
Overview ¶
Example ¶
package main import ( "context" database "github.com/coopnorge/go-redis-facade" ) func main() { encryptionConfig := database.EncryptionConfig{ RedisKeyURI: "", Aad: []byte{}, } encryptor, err := database.NewEncryptionClient(encryptionConfig) if err != nil { panic(err) } redisConfig := database.Config{ Address: "", Password: "", Database: 0, DialTimeout: 0, WriteTimeout: 0, ReadTimeout: 0, MaxRetries: 0, PoolSize: 0, PoolTimeout: 0, EncryptionEnabled: false, } redFacade, err := database.NewRedisFacade(redisConfig, encryptor) if err != nil { panic(err) } value, err := redFacade.Find(context.Background(), "key") if err != nil { panic(err) } println(value) }
Output:
Index ¶
- type Config
- type Encryption
- type EncryptionClient
- type EncryptionConfig
- type ErrorType
- type KeyValueStorage
- type RedisFacade
- func (rf *RedisFacade) Close() error
- func (rf *RedisFacade) Delete(ctx context.Context, key string) (count int64, err error)
- func (rf *RedisFacade) Find(ctx context.Context, key string) (v string, err error)
- func (rf *RedisFacade) FindKeys(ctx context.Context, pattern string) (redisKeysVal []string, err error)
- func (rf *RedisFacade) IsAvailable(ctx context.Context) error
- func (rf *RedisFacade) Save(ctx context.Context, key string, value string, expiration time.Duration) (err error)
- func (rf *RedisFacade) Update(ctx context.Context, key string, value string, expiration time.Duration) (err error)
- type StorageFacadeError
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { Address string Password string Database int DialTimeout time.Duration WriteTimeout time.Duration ReadTimeout time.Duration MaxRetries int PoolSize int PoolTimeout time.Duration EncryptionEnabled bool }
Config has all data to connect to redis
type Encryption ¶
type Encryption interface { Encrypt(value []byte) ([]byte, error) Decrypt(ciphertext []byte) ([]byte, error) }
Encryption defines interface
type EncryptionClient ¶
type EncryptionClient struct {
// contains filtered or unexported fields
}
EncryptionClient handles encryption and decryption tasks
func NewEncryptionClient ¶
func NewEncryptionClient(c EncryptionConfig) (*EncryptionClient, error)
NewEncryptionClient creates a new client for encrypting and decrypting data
type EncryptionConfig ¶
EncryptionConfig is configuration needed to set up the encryption client
type ErrorType ¶
type ErrorType int
ErrorType is the type of error that is returned
const ( // ErrorTypeInvalid invalid error type ErrorTypeInvalid ErrorType = iota // KeyMissing error type KeyMissing // KeyExist error type KeyExist // SyncError will occur with resource locking SyncError // CommandError error type CommandError // OperationError error type OperationError // BytesConversionError error type BytesConversionError )
type KeyValueStorage ¶
type KeyValueStorage interface { // Save value in storage by key with expiration Save(ctx context.Context, key string, value string, expiration time.Duration) error // Update value in storage by key and update expiration Update(ctx context.Context, key string, value string, expiration time.Duration) error // Delete value in storage by key Delete(ctx context.Context, key string) (count int64, err error) // Find in storage by key Find(ctx context.Context, key string) (string, error) // FindKeys in storage by given pattern FindKeys(ctx context.Context, pattern string) ([]string, error) // IsAvailable will return error if there is trouble to access storage IsAvailable(ctx context.Context) error // Close connection Close() error }
KeyValueStorage defines interface
type RedisFacade ¶
RedisFacade storage
func NewRedisFacade ¶
func NewRedisFacade(config Config, encryption Encryption) (*RedisFacade, error)
NewRedisFacade makes new connection to key value storage
func (*RedisFacade) FindKeys ¶
func (rf *RedisFacade) FindKeys(ctx context.Context, pattern string) (redisKeysVal []string, err error)
FindKeys in storage by given pattern
func (*RedisFacade) IsAvailable ¶
func (rf *RedisFacade) IsAvailable(ctx context.Context) error
IsAvailable will return error if there is trouble to access storage
type StorageFacadeError ¶
StorageFacadeError is a custom error type used for error handling
func (*StorageFacadeError) Error ¶
func (e *StorageFacadeError) Error() string
Directories
¶
Path | Synopsis |
---|---|
internal
|
|
generated/mocks
Package mock_database is a generated GoMock package.
|
Package mock_database is a generated GoMock package. |
Click to show internal directories.
Click to hide internal directories.