rinha

package module
v0.0.0-...-755a65f Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 License: MIT Imports: 19 Imported by: 0

README

rinha-de-backend-2024-q1-golang

Projeto feito em Golang para a rinha de backend 2024 q1.

  • Golang 1.22.
  • Gin Web Framework.
  • Postgresql 16.
  • Nginx.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrClientNotFound      = errors.New("client not found")
	ErrInsufficientBalance = errors.New("insufficient balance")
)

Functions

func RunServer

func RunServer(cfg *Config, pool *pgxpool.Pool)

func SetupDatabaseConnection

func SetupDatabaseConnection(ctx context.Context, cfg *Config) (*pgxpool.Pool, error)

Types

type Balance

type Balance struct {
	AccountLimit   int `db:"limite" json:"limite"`
	AccountBalance int `db:"saldo" json:"saldo"`
}

func AddTransaction

func AddTransaction(ctx context.Context, pool *pgxpool.Pool, clientID uint, transaction Transaction) (Balance, error)

type Client

type Client struct {
	ID             uint          `db:"id" json:"id"`
	AccountLimit   int           `db:"limite" json:"limite"`
	AccountBalance int           `db:"saldo" json:"saldo"`
	Transactions   []Transaction `db:"ultimas_transacoes" json:"ultimas_transacoes"`
}

func GetClient

func GetClient(ctx context.Context, pool *pgxpool.Pool, clientID uint) (Client, error)

type Config

type Config struct {
	ServerHost       string
	ServerPort       uint
	DatabaseURL      string
	DatabaseMinConns uint
	DatabaseMaxConns uint
}

func NewConfig

func NewConfig() *Config

type Transaction

type Transaction struct {
	Amount      uint            `json:"valor"`
	Type        TransactionType `json:"tipo"`
	Description string          `json:"descricao"`
	CreatedAt   time.Time       `json:"realizada_em"`
}

func (Transaction) Validate

func (t Transaction) Validate() error

type TransactionType

type TransactionType string
const (
	CreditType TransactionType = "c"
	DebitType  TransactionType = "d"
)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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