app

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package app provides structures and functions to configure and run application.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewJWT

func NewJWT(cfg *Config) (jwt.Builder, jwt.Parser, error)

NewJWT reads private and public keys, creates JWT builder and JWT parser. It returns error if keys read failed or configuration is incorrect.

func NewServer

func NewServer(cfg *Config, logger log.Logger, user usecase.User, token usecase.Token, auth usecase.Auth) *http.Server

NewServer creates mux and http.Server instance, appends middlewares and mounts controllers. It returns pointer to a http.Server instance.

func Run

func Run(cfg *Config, logger log.Logger) error

Run initializes application modules and runs server. It returns error if server has down.

Types

type ATConfig

type ATConfig struct {
	Alg string `env:"AT_ALG" default:"HS256"`
	Age int    `env:"AT_AGE" default:"15"`
}

type BcryptConfig

type BcryptConfig struct {
	Cost int `env:"BCRYPT_COST" default:"4"`
}

type Config

type Config struct {
	Name     string      `env:"APP_NAME" default:"auth"`
	Env      Environment `env:"APP_ENV" default:"development"`
	Key      KeyConfig
	HTTP     HTTPConfig
	Postgres PostgresConfig
	AT       ATConfig
	RT       RTConfig
	Bcrypt   BcryptConfig
}

Config represents app configuration structure.

func NewConfig

func NewConfig(path string) (*Config, error)

NewConfig reads variables from file or environment and sets Config fields to variables. It returns pointer to a Config instance or nil if read failed.

type Environment

type Environment string
const (
	EnvDev  Environment = "development"
	EnvProd Environment = "production"
)

type HTTPConfig

type HTTPConfig struct {
	Host           string   `env:"HTTP_HOST" default:"0.0.0.0"`
	Port           string   `env:"HTTP_PORT" default:"3000"`
	AllowedOrigins []string `env:"HTTP_ORIGINS" default:"*"`
}

type KeyConfig

type KeyConfig struct {
	PrivatePath string `env:"KEY_PRIVATE"`
	PublicPath  string `env:"KEY_PUBLIC"`
}

type PostgresConfig

type PostgresConfig struct {
	URI string `env:"POSTGRES_URI"`
}

type RTConfig

type RTConfig struct {
	Cap int `env:"RT_CAP" default:"10"`
	Age int `env:"RT_AGE" default:"30"`
}

Jump to

Keyboard shortcuts

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