Documentation
ΒΆ
Index ΒΆ
- Constants
- func IsToken(s string) bool
- type NewStoreOptions
- type RecordInterface
- type RecordQueryInterface
- type Store
- func (st *Store) AutoMigrate() error
- func (st *Store) EnableDebug(debug bool)
- func (st *Store) GetDbDriverName() string
- func (st *Store) GetVaultTableName() string
- func (store *Store) RecordCount(ctx context.Context, query RecordQueryInterface) (int64, error)
- func (store *Store) RecordCreate(ctx context.Context, record RecordInterface) error
- func (store *Store) RecordDeleteByID(ctx context.Context, recordID string) error
- func (store *Store) RecordDeleteByToken(ctx context.Context, token string) error
- func (st *Store) RecordFindByID(ctx context.Context, id string) (RecordInterface, error)
- func (st *Store) RecordFindByToken(ctx context.Context, token string) (RecordInterface, error)
- func (store *Store) RecordList(ctx context.Context, query RecordQueryInterface) ([]RecordInterface, error)
- func (store *Store) RecordSoftDelete(ctx context.Context, record RecordInterface) error
- func (store *Store) RecordSoftDeleteByID(ctx context.Context, recordID string) error
- func (store *Store) RecordSoftDeleteByToken(ctx context.Context, token string) error
- func (store *Store) RecordUpdate(ctx context.Context, record RecordInterface) error
- func (store *Store) SqlCreateTable() string
- func (st *Store) TokenCreate(ctx context.Context, data string, password string, tokenLength int) (token string, err error)
- func (store *Store) TokenCreateCustom(ctx context.Context, token string, data string, password string) (err error)
- func (st *Store) TokenDelete(ctx context.Context, token string) error
- func (store *Store) TokenExists(ctx context.Context, token string) (bool, error)
- func (st *Store) TokenRead(ctx context.Context, token string, password string) (value string, err error)
- func (st *Store) TokenSoftDelete(ctx context.Context, token string) error
- func (st *Store) TokenUpdate(ctx context.Context, token string, value string, password string) (err error)
- func (st *Store) TokensRead(ctx context.Context, tokens []string, password string) (values map[string]string, err error)
- type StoreInterface
Constants ΒΆ
const COLUMN_CREATED_AT = "created_at"
const COLUMN_ID = "id"
const COLUMN_SOFT_DELETED_AT = "soft_deleted_at"
const COLUMN_UPDATED_AT = "updated_at"
const COLUMN_VAULT_TOKEN = "vault_token"
const COLUMN_VAULT_VALUE = "vault_value"
const TOKEN_PREFIX = "tk_"
Variables ΒΆ
This section is empty.
Functions ΒΆ
Types ΒΆ
type NewStoreOptions ΒΆ
type NewStoreOptions struct { VaultTableName string DB *sql.DB DbDriverName string AutomigrateEnabled bool DebugEnabled bool }
NewStoreOptions define the options for creating a new session store
type RecordInterface ΒΆ added in v0.25.0
type RecordInterface interface { Data() map[string]string DataChanged() map[string]string // Getters GetCreatedAt() string GetSoftDeletedAt() string GetID() string GetToken() string GetUpdatedAt() string GetValue() string // Setters SetCreatedAt(createdAt string) RecordInterface SetSoftDeletedAt(softDeletedAt string) RecordInterface SetID(id string) RecordInterface SetToken(token string) RecordInterface SetUpdatedAt(updatedAt string) RecordInterface SetValue(value string) RecordInterface }
RecordInterface defines the methods that a Record must implement
func NewRecord ΒΆ
func NewRecord() RecordInterface
func NewRecordFromExistingData ΒΆ
func NewRecordFromExistingData(data map[string]string) RecordInterface
type RecordQueryInterface ΒΆ added in v0.25.0
type RecordQueryInterface interface { Validate() error GetColumns() []string SetColumns(columns []string) RecordQueryInterface IsIDSet() bool GetID() string SetID(id string) RecordQueryInterface IsIDInSet() bool GetIDIn() []string SetIDIn(idIn []string) RecordQueryInterface IsTokenSet() bool GetToken() string SetToken(token string) RecordQueryInterface IsTokenInSet() bool GetTokenIn() []string SetTokenIn(tokenIn []string) RecordQueryInterface IsOffsetSet() bool GetOffset() int SetOffset(offset int) RecordQueryInterface IsOrderBySet() bool GetOrderBy() string SetOrderBy(orderBy string) RecordQueryInterface IsLimitSet() bool GetLimit() int SetLimit(limit int) RecordQueryInterface IsCountOnlySet() bool GetCountOnly() bool SetCountOnly(countOnly bool) RecordQueryInterface IsSortOrderSet() bool GetSortOrder() string SetSortOrder(sortOrder string) RecordQueryInterface IsSoftDeletedIncludeSet() bool GetSoftDeletedInclude() bool SetSoftDeletedInclude(softDeletedInclude bool) RecordQueryInterface // contains filtered or unexported methods }
func RecordQuery ΒΆ added in v0.25.0
func RecordQuery() RecordQueryInterface
RecordQuery creates a new record query
type Store ΒΆ
type Store struct {
// contains filtered or unexported fields
}
Store defines a session store
func NewStore ΒΆ
func NewStore(opts NewStoreOptions) (*Store, error)
NewStore creates a new entity store
func (*Store) EnableDebug ΒΆ
EnableDebug - enables the debug option
func (*Store) GetDbDriverName ΒΆ added in v0.25.0
func (*Store) GetVaultTableName ΒΆ added in v0.25.0
func (*Store) RecordCount ΒΆ
func (*Store) RecordCreate ΒΆ
func (store *Store) RecordCreate(ctx context.Context, record RecordInterface) error
func (*Store) RecordDeleteByID ΒΆ
func (*Store) RecordDeleteByToken ΒΆ
func (*Store) RecordFindByID ΒΆ
FindByID finds an entry by ID
func (*Store) RecordFindByToken ΒΆ
RecordFindByToken finds a record entity by token
If the supplied token is empty, an error is returned ΒΆ
Parameters: - ctx: The context - token: The token to find
Returns: - record: The record found - err: An error if something went wrong
func (*Store) RecordList ΒΆ
func (store *Store) RecordList(ctx context.Context, query RecordQueryInterface) ([]RecordInterface, error)
func (*Store) RecordSoftDelete ΒΆ added in v0.25.0
func (store *Store) RecordSoftDelete(ctx context.Context, record RecordInterface) error
RecordSoftDelete soft deletes a record by setting the soft_deleted_at column to the current time
func (*Store) RecordSoftDeleteByID ΒΆ added in v0.25.0
RecordSoftDeleteByID soft deletes a record by ID by setting the soft_deleted_at column to the current time
func (*Store) RecordSoftDeleteByToken ΒΆ added in v0.25.0
RecordSoftDeleteByToken soft deletes a record by token by setting the soft_deleted_at column to the current time
func (*Store) RecordUpdate ΒΆ
func (store *Store) RecordUpdate(ctx context.Context, record RecordInterface) error
func (*Store) SqlCreateTable ΒΆ
SqlCreateTable returns a SQL string for creating the setting table
func (*Store) TokenCreate ΒΆ
func (st *Store) TokenCreate(ctx context.Context, data string, password string, tokenLength int) (token string, err error)
TokenCreate creates a new record and returns the token
func (*Store) TokenCreateCustom ΒΆ
func (*Store) TokenDelete ΒΆ
TokenDelete deletes a token from the store
If the supplied token is empty, an error is returned ΒΆ
Parameters: - ctx: The context - token: The token to delete
Returns: - err: An error if something went wrong
func (*Store) TokenExists ΒΆ
TokenExists checks if a token exists
If the supplied token is empty, an error is returned ΒΆ
Parameters: - ctx: The context - token: The token to check
Returns: - exists: A boolean indicating if the token exists - err: An error if something went wrong
func (*Store) TokenRead ΒΆ
func (st *Store) TokenRead(ctx context.Context, token string, password string) (value string, err error)
TokenRead retrieves the value of a token
If the token does not exist, an error is returned ΒΆ
Parameters: - ctx: The context - token: The token to retrieve - password: The password to use for decryption
Returns: - value: The value of the token - err: An error if something went wrong
func (*Store) TokenSoftDelete ΒΆ added in v0.25.0
TokenSoftDelete soft deletes a token from the store
Soft deleting keeps the record in the database but marks it as soft deleted and soft deleted records are not returned by default
If the supplied token is empty, an error is returned ΒΆ
Parameters: - ctx: The context - token: The token to soft delete
Returns: - err: An error if something went wrong
func (*Store) TokenUpdate ΒΆ
func (st *Store) TokenUpdate(ctx context.Context, token string, value string, password string) (err error)
TokenUpdate updates the value of a token
If the token does not exist, an error is returned ΒΆ
Parameters: - ctx: The context - token: The token to update - value: The new value - password: The password to use for encryption
Returns: - err: An error if something went wrong
func (*Store) TokensRead ΒΆ
func (st *Store) TokensRead(ctx context.Context, tokens []string, password string) (values map[string]string, err error)
TokensRead reads a list of tokens, returns a map of token to value
If a token is not found, it is not included in the map ΒΆ
Parameters: - ctx: The context - tokens: The list of tokens to read - password: The password to use for decryption
Returns: - values: A map of token to value - err: An error if something went wrong
type StoreInterface ΒΆ
type StoreInterface interface { AutoMigrate() error EnableDebug(debug bool) GetDbDriverName() string GetVaultTableName() string RecordCount(ctx context.Context, query RecordQueryInterface) (int64, error) RecordCreate(ctx context.Context, record RecordInterface) error RecordDeleteByID(ctx context.Context, recordID string) error RecordDeleteByToken(ctx context.Context, token string) error RecordFindByID(ctx context.Context, recordID string) (RecordInterface, error) RecordFindByToken(ctx context.Context, token string) (RecordInterface, error) RecordList(ctx context.Context, query RecordQueryInterface) ([]RecordInterface, error) RecordSoftDelete(ctx context.Context, record RecordInterface) error RecordSoftDeleteByID(ctx context.Context, recordID string) error RecordSoftDeleteByToken(ctx context.Context, token string) error RecordUpdate(ctx context.Context, record RecordInterface) error TokenCreate(ctx context.Context, value string, password string, tokenLength int) (token string, err error) TokenCreateCustom(ctx context.Context, token string, value string, password string) (err error) TokenDelete(ctx context.Context, token string) error TokenExists(ctx context.Context, token string) (bool, error) TokenRead(ctx context.Context, token string, password string) (string, error) TokenSoftDelete(ctx context.Context, token string) error TokenUpdate(ctx context.Context, token string, value string, password string) error TokensRead(ctx context.Context, tokens []string, password string) (map[string]string, error) }