Versions in this module Expand all Collapse all v1 v1.0.0 Jan 28, 2026 Changes in this version + var ErrAlreadyExists = errors.New("record already exists") + var ErrConflict = errors.New("conflict") + var ErrDatabaseError = errors.New("database error") + var ErrInvalidInput = errors.New("invalid input") + var ErrNotFound = errors.New("record not found") + var ErrUnauthorized = errors.New("unauthorized") + func GenericCreate[T any](base *Repository, ctx context.Context, table string, model *T, ...) error + func GenericDelete(base *Repository, ctx context.Context, table, keyField, keyValue string) error + func GenericDeleteWithQuery(base *Repository, ctx context.Context, table, query string) error + func GenericGetByField[T any](base *Repository, ctx context.Context, table, field, value string) (*T, error) + func GenericListByField[T any](base *Repository, ctx context.Context, table, field, value string) ([]T, error) + func GenericListWithQuery[T any](base *Repository, ctx context.Context, table, query string) ([]T, error) + func GenericList[T any](base *Repository, ctx context.Context, table string) ([]T, error) + func GenericUpdateWithQuery[T any](base *Repository, ctx context.Context, table, query string, model *T) error + func GenericUpdate[T any](base *Repository, ctx context.Context, table, keyField, keyValue string, ...) error + func IsAlreadyExists(err error) bool + func IsInvalidInput(err error) bool + func IsNotFound(err error) bool + func IsUnauthorized(err error) bool + func NewNotFoundError(entity, id string) error + func SanitizeString(s string) string + func ValidateAddress(address string) error + func ValidateEmail(email string) error + func ValidateID(id string) error + func ValidateLimit(limit, defaultLimit, maxLimit int) int + func ValidateOffset(offset int) int + func ValidateStatus(status string, validStatuses []string) error + func ValidateTxHash(txHash string) error + func ValidateUserID(userID string) error + type APIKey struct + CreatedAt time.Time + Description string + ExpiresAt time.Time + ID string + KeyHash string + LastUsed time.Time + Name string + Prefix string + Scopes []string + UserID string + type BaseRepository interface + type Client struct + func NewClient(cfg Config) (*Client, error) + func (c *Client) Delete(ctx context.Context, table string, query string) ([]byte, error) + func (c *Client) Insert(ctx context.Context, table string, data interface{}) ([]byte, error) + func (c *Client) Select(ctx context.Context, table string, query string) ([]byte, error) + func (c *Client) Update(ctx context.Context, table string, data interface{}, query string) ([]byte, error) + func (c *Client) Upsert(ctx context.Context, table string, data interface{}, onConflict string) ([]byte, error) + type Config struct + RestPrefix string + ServiceKey string + URL string + type DepositRequest struct + AccountID string + Amount int64 + Confirmations int + ConfirmedAt time.Time + CreatedAt time.Time + Error string + ExpiresAt time.Time + FromAddress string + ID string + RequiredConfirmations int + Status string + TxHash string + UserID string + type GasBankAccount struct + Balance int64 + CreatedAt time.Time + ID string + Reserved int64 + UpdatedAt time.Time + UserID string + type GasBankRepository interface + CreateDepositRequest func(ctx context.Context, deposit *DepositRequest) error + CreateGasBankAccount func(ctx context.Context, account *GasBankAccount) error + CreateGasBankTransaction func(ctx context.Context, tx *GasBankTransaction) error + DeductFeeAtomic func(ctx context.Context, userID string, amount int64, tx *GasBankTransaction) (newBalance int64, err error) + GetDepositByTxHash func(ctx context.Context, txHash string) (*DepositRequest, error) + GetDepositRequests func(ctx context.Context, userID string, limit int) ([]DepositRequest, error) + GetGasBankAccount func(ctx context.Context, userID string) (*GasBankAccount, error) + GetGasBankTransactions func(ctx context.Context, accountID string, limit int) ([]GasBankTransaction, error) + GetOrCreateGasBankAccount func(ctx context.Context, userID string) (*GasBankAccount, error) + GetPendingDeposits func(ctx context.Context, limit int) ([]DepositRequest, error) + UpdateDepositStatus func(ctx context.Context, depositID, status string, confirmations int) error + UpdateGasBankBalance func(ctx context.Context, userID string, balance, reserved int64) error + type GasBankTransaction struct + AccountID string + Amount int64 + BalanceAfter int64 + CreatedAt time.Time + FromAddress string + ID string + ReferenceID string + Status string + ToAddress string + TxHash string + TxType string + type GenericOps struct + type MockRepository struct + ErrorOnNextCall error + func NewMockRepository() *MockRepository + func (m *MockRepository) CreateDepositRequest(ctx context.Context, deposit *DepositRequest) error + func (m *MockRepository) CreateGasBankAccount(ctx context.Context, account *GasBankAccount) error + func (m *MockRepository) CreateGasBankTransaction(ctx context.Context, tx *GasBankTransaction) error + func (m *MockRepository) CreatePriceFeed(ctx context.Context, feed *PriceFeed) error + func (m *MockRepository) CreateServiceRequest(ctx context.Context, req *ServiceRequest) error + func (m *MockRepository) CreateUser(ctx context.Context, user *User) error + func (m *MockRepository) DeductFeeAtomic(ctx context.Context, userID string, amount int64, tx *GasBankTransaction) (int64, error) + func (m *MockRepository) GetDepositByTxHash(ctx context.Context, txHash string) (*DepositRequest, error) + func (m *MockRepository) GetDepositRequests(ctx context.Context, userID string, limit int) ([]DepositRequest, error) + func (m *MockRepository) GetGasBankAccount(ctx context.Context, userID string) (*GasBankAccount, error) + func (m *MockRepository) GetGasBankTransactions(ctx context.Context, accountID string, limit int) ([]GasBankTransaction, error) + func (m *MockRepository) GetLatestPrice(ctx context.Context, feedID string) (*PriceFeed, error) + func (m *MockRepository) GetOrCreateGasBankAccount(ctx context.Context, userID string) (*GasBankAccount, error) + func (m *MockRepository) GetPendingDeposits(ctx context.Context, limit int) ([]DepositRequest, error) + func (m *MockRepository) GetServiceRequests(ctx context.Context, userID string, limit int) ([]ServiceRequest, error) + func (m *MockRepository) GetUser(ctx context.Context, id string) (*User, error) + func (m *MockRepository) GetUserByAddress(ctx context.Context, address string) (*User, error) + func (m *MockRepository) GetUserByEmail(ctx context.Context, email string) (*User, error) + func (m *MockRepository) HealthCheck(ctx context.Context) error + func (m *MockRepository) Reset() + func (m *MockRepository) UpdateDepositStatus(ctx context.Context, depositID, status string, confirmations int) error + func (m *MockRepository) UpdateGasBankBalance(ctx context.Context, userID string, balance, reserved int64) error + func (m *MockRepository) UpdateServiceRequest(ctx context.Context, req *ServiceRequest) error + func (m *MockRepository) UpdateUserEmail(ctx context.Context, userID, email string) error + func (m *MockRepository) UpdateUserNonce(ctx context.Context, userID, nonce string) error + type NotFoundError struct + Entity string + ID string + func (e *NotFoundError) Error() string + func (e *NotFoundError) Unwrap() error + type PaginationParams struct + Limit int + Offset int + func DefaultPagination() PaginationParams + func NewPagination(limit, offset int) PaginationParams + func (p PaginationParams) ToQuery() string + type PriceFeed struct + Decimals int + FeedID string + ID string + Pair string + Price int64 + Signature []byte + Sources []string + Timestamp time.Time + type PriceFeedRepository interface + CreatePriceFeed func(ctx context.Context, feed *PriceFeed) error + GetLatestPrice func(ctx context.Context, feedID string) (*PriceFeed, error) + type QueryBuilder struct + func NewQuery() *QueryBuilder + func (q *QueryBuilder) Build() string + func (q *QueryBuilder) Eq(field, value string) *QueryBuilder + func (q *QueryBuilder) Gte(field, value string) *QueryBuilder + func (q *QueryBuilder) In(field string, values []string) *QueryBuilder + func (q *QueryBuilder) IsFalse(field string) *QueryBuilder + func (q *QueryBuilder) IsNull(field string) *QueryBuilder + func (q *QueryBuilder) IsTrue(field string) *QueryBuilder + func (q *QueryBuilder) Limit(n int) *QueryBuilder + func (q *QueryBuilder) Lte(field, value string) *QueryBuilder + func (q *QueryBuilder) OrderAsc(field string) *QueryBuilder + func (q *QueryBuilder) OrderDesc(field string) *QueryBuilder + type Repository struct + func NewRepository(client *Client) *Repository + func (r *Repository) CreateAPIKey(ctx context.Context, key *APIKey) error + func (r *Repository) CreateDepositRequest(ctx context.Context, deposit *DepositRequest) error + func (r *Repository) CreateGasBankAccount(ctx context.Context, account *GasBankAccount) error + func (r *Repository) CreateGasBankTransaction(ctx context.Context, tx *GasBankTransaction) error + func (r *Repository) CreatePriceFeed(ctx context.Context, feed *PriceFeed) error + func (r *Repository) CreateServiceRequest(ctx context.Context, req *ServiceRequest) error + func (r *Repository) CreateUser(ctx context.Context, user *User) error + func (r *Repository) CreateWallet(ctx context.Context, wallet *UserWallet) error + func (r *Repository) DeductFeeAtomic(ctx context.Context, userID string, amount int64, tx *GasBankTransaction) (int64, error) + func (r *Repository) DeleteWallet(ctx context.Context, walletID, userID string) error + func (r *Repository) GetAPIKeyByHash(ctx context.Context, keyHash string) (*APIKey, error) + func (r *Repository) GetAPIKeys(ctx context.Context, userID string) ([]APIKey, error) + func (r *Repository) GetDepositByTxHash(ctx context.Context, txHash string) (*DepositRequest, error) + func (r *Repository) GetDepositRequests(ctx context.Context, userID string, limit int) ([]DepositRequest, error) + func (r *Repository) GetGasBankAccount(ctx context.Context, userID string) (*GasBankAccount, error) + func (r *Repository) GetGasBankTransactions(ctx context.Context, accountID string, limit int) ([]GasBankTransaction, error) + func (r *Repository) GetLatestPrice(ctx context.Context, feedID string) (*PriceFeed, error) + func (r *Repository) GetOrCreateGasBankAccount(ctx context.Context, userID string) (*GasBankAccount, error) + func (r *Repository) GetPendingDeposits(ctx context.Context, limit int) ([]DepositRequest, error) + func (r *Repository) GetServiceRequests(ctx context.Context, userID string, limit int) ([]ServiceRequest, error) + func (r *Repository) GetUser(ctx context.Context, id string) (*User, error) + func (r *Repository) GetUserByAddress(ctx context.Context, address string) (*User, error) + func (r *Repository) GetUserByEmail(ctx context.Context, email string) (*User, error) + func (r *Repository) GetUserWallets(ctx context.Context, userID string) ([]UserWallet, error) + func (r *Repository) GetWallet(ctx context.Context, walletID, userID string) (*UserWallet, error) + func (r *Repository) GetWalletByAddress(ctx context.Context, address string) (*UserWallet, error) + func (r *Repository) HealthCheck(ctx context.Context) error + func (r *Repository) Request(ctx context.Context, method, table string, body interface{}, query string) ([]byte, error) + func (r *Repository) RevokeAPIKey(ctx context.Context, keyID, userID string) error + func (r *Repository) SetPrimaryWallet(ctx context.Context, userID, walletID string) error + func (r *Repository) UpdateAPIKeyLastUsed(ctx context.Context, keyID string) error + func (r *Repository) UpdateDepositStatus(ctx context.Context, depositID, status string, confirmations int) error + func (r *Repository) UpdateGasBankBalance(ctx context.Context, userID string, balance, reserved int64) error + func (r *Repository) UpdateServiceRequest(ctx context.Context, req *ServiceRequest) error + func (r *Repository) UpdateUserEmail(ctx context.Context, userID, email string) error + func (r *Repository) UpdateUserNonce(ctx context.Context, userID, nonce string) error + func (r *Repository) VerifyWallet(ctx context.Context, walletID, signature string) error + type RepositoryInterface interface + HealthCheck func(ctx context.Context) error + type ServiceRequest struct + CompletedAt time.Time + CreatedAt time.Time + Error string + GasUsed int64 + ID string + Payload json.RawMessage + Result json.RawMessage + ServiceType string + Status string + UserID string + type ServiceRequestRepository interface + CreateServiceRequest func(ctx context.Context, req *ServiceRequest) error + GetServiceRequests func(ctx context.Context, userID string, limit int) ([]ServiceRequest, error) + UpdateServiceRequest func(ctx context.Context, req *ServiceRequest) error + type User struct + Address string + CreatedAt time.Time + Email string + ID string + Nonce string + UpdatedAt time.Time + type UserRepository interface + CreateUser func(ctx context.Context, user *User) error + GetUser func(ctx context.Context, id string) (*User, error) + GetUserByAddress func(ctx context.Context, address string) (*User, error) + GetUserByEmail func(ctx context.Context, email string) (*User, error) + UpdateUserEmail func(ctx context.Context, userID, email string) error + UpdateUserNonce func(ctx context.Context, userID, nonce string) error + type UserWallet struct + Address string + CreatedAt time.Time + ID string + IsPrimary bool + Label string + UserID string + VerificationMessage string + VerificationSignature string + Verified bool