memory

package
v0.0.0-...-d11a8a1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 7, 2023 License: MIT Imports: 13 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Delete

func Delete(key string) error

func Get

func Get(key string, obj any) error

func Init

func Init(cfg any) error

func KeyFromEnv

func KeyFromEnv() (*rsa.PrivateKey, error)

func KeyFromTTY

func KeyFromTTY() (*rsa.PrivateKey, error)

func Marshal

func Marshal(v interface{}) ([]byte, error)

func New

func New(t BackendType, cfg any, key *rsa.PrivateKey) error

func ReadKey

func ReadKey(path *string, remove bool) (*rsa.PrivateKey, error)

ReadKey will read a private key, parse it, and return a *rsa.PrivateKey If path is provided, the key will be read from the file at that path If a MEMORY_KEY environment variable is set, the key will be read from that If path is nil and MEMORY_KEY is not set, the user will be prompted to enter a key If remove is true, the file at path will be removed after reading

func Set

func Set(key string, value any) error

func Unmarshal

func Unmarshal(data []byte, v interface{}) error

Types

type Backend

type Backend interface {
	Init(cfg any) error
	Get(key string) ([]byte, error)
	Set(key string, value []byte) error
	Delete(key string) error
}
var (
	B   Backend
	Key *rsa.PrivateKey
)

type BackendType

type BackendType string
const (
	MemoryBackendType  BackendType = "memory"
	MemoryBackendRedis BackendType = "redis"
	MemoryBackendFile  BackendType = "file"
)

type FileBackend

type FileBackend struct {
	Dir string `json:"dir"`
}

func (*FileBackend) Delete

func (b *FileBackend) Delete(key string) error

func (*FileBackend) Get

func (b *FileBackend) Get(key string) ([]byte, error)

func (*FileBackend) Init

func (b *FileBackend) Init(cfg any) error

func (*FileBackend) Set

func (b *FileBackend) Set(key string, value []byte) error

type MemoryBackend

type MemoryBackend struct {
	D map[string][]byte
}

func (*MemoryBackend) Delete

func (m *MemoryBackend) Delete(key string) error

func (*MemoryBackend) Get

func (m *MemoryBackend) Get(key string) ([]byte, error)

func (*MemoryBackend) Init

func (m *MemoryBackend) Init(cfg any) error

func (*MemoryBackend) Set

func (m *MemoryBackend) Set(key string, value []byte) error

type RedisBackend

type RedisBackend struct {
	Host     string `json:"host"`
	Port     int    `json:"port"`
	Password string `json:"password"`
	Db       int    `json:"db"`
	TlsCa    string `json:"tls_ca"`
	TlsCert  string `json:"tls_cert"`
	TlsKey   string `json:"tls_key"`
	// contains filtered or unexported fields
}

func (*RedisBackend) Delete

func (m *RedisBackend) Delete(key string) error

func (*RedisBackend) Get

func (m *RedisBackend) Get(key string) ([]byte, error)

func (*RedisBackend) Init

func (m *RedisBackend) Init(cfg any) error

func (*RedisBackend) Set

func (m *RedisBackend) Set(key string, value []byte) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL