app

package
v0.0.0-...-bfc4fd5 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2024 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const CacheTypeDisabled = "disabled"
View Source
const CacheTypeInMemory = "in-memory"
View Source
const CacheTypeRedis = "redis"
View Source
const StorageTypeFile = "file"
View Source
const StorageTypePostgres = "postgres"

Variables

View Source
var MetricRequestsTotal = promauto.NewSummaryVec(
	prometheus.SummaryOpts{
		Namespace:  "shorter",
		Subsystem:  "http",
		Name:       "requests",
		Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.01},
	},
	[]string{"status"},
)

Functions

This section is empty.

Types

type Application

type Application struct {
	Config     Config
	Logger     *utils.Logger
	Validator  Validator
	Links      LinksCollectionInterface
	Background *utils.Background
}

func (*Application) Serve

func (app *Application) Serve() error

type Config

type Config struct {
	ProjectHost        string `env:"PROJECT_HOST" env-default:""`
	ProjectPort        int    `env:"PROJECT_PORT" env-default:"80"`
	ProjectStorageType string `env:"PROJECT_STORAGE_TYPE" env-default:"file"`
	FileAsync          bool   `env:"FILE_ASYNC" env-default:"false"`
	DbDSN              string `env:"DB_DSN" env-default:"postgres://go:pa55word@localhost:5432/short_links?sslmode=disable"`
	DbMaxOpenConns     int    `env:"DB_MAX_OPEN_CONNS" env-default:"25"`
	DbMaxIdleConns     int    `env:"DB_MAX_IDLE_CONNS" env-default:"25"`
	DbMaxIdleTime      string `env:"DB_MAX_OPEN_TIME" env-default:"15m"`
	DbTimeout          int    `env:"DATABASE_TIMEOUT" env-default:"1"`
	CacheType          string `env:"CACHE_TYPE" env-default:"disabled"`
	CacheCapacity      int    `env:"CACHE_CAPACITY" env-default:"10"`
	CacheRedisDSN      string `env:"CACHE_REDIS_DSN" env-default:"redis://localhost:6379/0"`
	LimiterEnabled     bool   `env:"LIMITER_ENABLED" env-default:"true"`
	LimiterRPS         int    `env:"LIMITER_RPS" env-default:"2"`
	LimiterBurst       int    `env:"LIMITER_BURST" env-default:"4"`
}

func (*Config) Info

func (c *Config) Info() string

type LinksCollectionInterface

type LinksCollectionInterface interface {
	GenerateKey(URL string) (string, error)
	GenerateKeys(URLs []string) (map[string]string, error)
	GetURL(key string) (string, error)
	GetURLs(keys []string) (map[string]string, error)
}

type ReaderFunc

type ReaderFunc func(http.ResponseWriter, *http.Request, interface{}) error

func (ReaderFunc) Run

func (f ReaderFunc) Run(w http.ResponseWriter, r *http.Request, destination interface{}) error

type Validator

type Validator struct {
	KeyMaxLength int
	// contains filtered or unexported fields
}

func NewValidator

func NewValidator(allowedLetters string) *Validator

type WriterFunc

type WriterFunc func(http.ResponseWriter, *http.Request, interface{}) ([]byte, error)

func (WriterFunc) Run

func (f WriterFunc) Run(w http.ResponseWriter, r *http.Request, data interface{}) ([]byte, error)

Jump to

Keyboard shortcuts

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