api

package
v0.0.0-...-83f4222 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthJWT

func AuthJWT(next http.HandlerFunc) http.HandlerFunc

auth middleware

func GetUUID

func GetUUID(r *http.Request) (uuid.UUID, error)

Get id from url

func HTTPHandler

func HTTPHandler(f ApiFunc) http.HandlerFunc

Wrapper for handler func

func WriteJSON

func WriteJSON(w http.ResponseWriter, status int, v any) error

Types

type ApiError

type ApiError struct {
	Error string `json:"error"`
}

type ApiFunc

type ApiFunc func(w http.ResponseWriter, r *http.Request) error

type JSONApiServer

type JSONApiServer struct {
	Server *http.Server
	// contains filtered or unexported fields
}

Server

func NewJSONApiServer

func NewJSONApiServer(config *config.Config, db *sql.DB, redis *redis.Client, storage Storage, redisStorage RedisStorage, logger *logrus.Logger) *JSONApiServer

Constructor

func (*JSONApiServer) Run

func (s *JSONApiServer) Run()

type RedisStorage

type RedisStorage interface {
	CreateSession(ctx context.Context, session *types.Session, expire int) (string, error)
	GetUserID(ctx context.Context, refreshToken string) (uuid.UUID, error)
	DeleteSession(ctx context.Context, refreshToken string) error
}

Redis storage interface

type Storage

type Storage interface {
	CreateAccount(ctx context.Context, reqAcc *types.RequestCreate) (*types.Account, error)
	GetAccount(ctx context.Context) ([]*types.Account, error)
	GetAccountByID(ctx context.Context, id uuid.UUID) (*types.Account, error)
	GetAccountByCard(ctx context.Context, card string) (*types.Account, error)
	UpdateAccount(ctx context.Context, reqUp *types.RequestUpdate, id uuid.UUID) (*types.Account, error)
	DeleteAccount(ctx context.Context, id uuid.UUID) error
	DepositAccount(ctx context.Context, reqDep *types.RequestDeposit) (*types.Account, error)
	GetAccountStatement(ctx context.Context, id uuid.UUID) ([]string, error)
	SavePayment(ctx context.Context, tx *sql.Tx, payment *types.Payment) (*types.Payment, error)
	GetPaymentByID(ctx context.Context, id uuid.UUID) (*types.Payment, error)
	SaveBalance(ctx context.Context, tx *sql.Tx, account *types.Account, balance, bmoney uint64) (*types.Account, error)
	UpdateStatement(ctx context.Context, tx *sql.Tx, id, paymentId uuid.UUID) (*types.Account, error)
}

Postgres storage interface

Directories

Path Synopsis
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.

Jump to

Keyboard shortcuts

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