common

package
v0.0.0-...-46c349b Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2023 License: AGPL-3.0 Imports: 12 Imported by: 18

Documentation

Index

Constants

View Source
const MAX_RETRIES float64 = 4

Variables

View Source
var (
	ContextKeyTraceID          = ContextKey("request id")
	ContextKeyRequestStartTime = ContextKey("request start time")
	ContextKeyRemoteAddress    = ContextKey("request remote address")
	ContextKeyUser             = ContextKey("user")
)
View Source
var (
	ErrNotFound            = errors.New("not found")
	ErrValidation          = errors.New("validation")
	ErrRetryable           = errors.New("retryable")
	ErrNoNewBlocks         = errors.New("no new blocks")
	ErrNotDistributionTime = errors.New("not distribution time")
)

Functions

func Decode

func Decode[T any](reader io.Reader) (*T, error)

func FunctionRetrier

func FunctionRetrier[T any](ctx context.Context, fn func() (T, error)) (result T, err error)

Invoke a function with exponential backoff when a retryable error is encountered. If fn returns an err that is wrapped in common.ErrRetyable, fn will be retried with exponential backoff. This was originally implemented to solve getting rate limited by the alchemy APIs

See: https://docs.alchemy.com/alchemy/documentation/rate-limits#retries

func Unmarshal

func Unmarshal[T any](data []byte) (*T, error)

Types

type ContextKey

type ContextKey string

func (ContextKey) String

func (c ContextKey) String() string

type LogEvent

type LogEvent interface {
	Send()
	Msg(msg string)
	Msgf(msg string, v ...any)
	Err(err error) LogEvent
	Strs(strs []struct {
		Key   string
		Value string
	}) LogEvent
}

type Logger

type Logger interface {
	Start(ctx context.Context, config LoggerConfig)
	Debug(ctx context.Context) LogEvent
	Info(ctx context.Context) LogEvent
	Warn(ctx context.Context) LogEvent
	Error(ctx context.Context) LogEvent
}

func NewLogger

func NewLogger() Logger

type LoggerConfig

type LoggerConfig struct {
	Env      string
	Hostname string
	Appname  string
}

type SigninMessage

type SigninMessage struct {
	Address string `json:"address"`
}

type Stream

type Stream = string
const (
	SigninStream Stream = "signin"
	VoteStream   Stream = "vote"
)

type Validator

type Validator interface {
	ValidateStruct(s any) error
	ValidateField(f any, tag string) error
}

func NewValidator

func NewValidator() Validator

type VoteMessage

type VoteMessage struct {
	Id      int64              `json:"id"`
	Address string             `json:"address"`
	Type    entities.VoteType  `json:"type"`
	Value   entities.VoteValue `json:"value"`
	// the timestamp at which the vote was accepted
	// this is used to discard old votes that may be processed out of order
	UpdatedAt int64 `json:"updated_at"`
}

Jump to

Keyboard shortcuts

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