backend

package
v0.0.0-...-97d3501 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2024 License: BSD-3-Clause Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CodeChars = "2379HJKLNQSTVXYZ" // Limited to a nice even 16 options

)

Variables

This section is empty.

Functions

func CheckVerifyCode

func CheckVerifyCode(token string, signingKey string, email string) bool

func CheckVerifyCodeTS

func CheckVerifyCodeTS(token string, signingKey string, email string, timestamp time.Time) bool

func FileServer

func FileServer(r chi.Router, path string, root http.FileSystem)

FileServer conveniently sets up a http.FileServer handler to serve static files from a http.FileSystem.

func MakeToken

func MakeToken(srv *Server, email string) (string, error)

func MakeVerifyCodeNow

func MakeVerifyCodeNow(signingKey string, email string) string

func MakeVerifyCodeTS

func MakeVerifyCodeTS(signingKey string, email string, timestamp time.Time) string

Types

type AuthConfig

type AuthConfig struct {
	Mode      string          `yaml:"mode" validate:"required,oneof=email"`
	RateLimit RateLimitConfig `yaml:"rate_limit"`
}

AuthConfig changes how authentication works

type Config

type Config struct {
	Title      string           `yaml:"title" validate:"min=1,max=64"`
	Brand      string           `yaml:"brand" validate:"min=1,max=64"`
	Support    string           `yaml:"support" validate:"min=1,max=255"`
	SigningKey string           `yaml:"signing_key" validate:"required,min=16,max=64"`
	CookieAuth CookieAuthConfig `yaml:"cookie_auth"`
	Auth       AuthConfig       `yaml:"auth"`
	Email      EmailConfig      `yaml:"email"`
	Mailjet    MailjetConfig    `yaml:"mailjet"`
	Server     ServerConfig     `yaml:"server"`
	JWT        JWTConfig        `yaml:"jwt"`
}

Config provides all the configuration parsed from praga.yaml

func LoadConfig

func LoadConfig(configPath string) (bool, Config)

LoadConfig loads a praga.yaml file and parses it into a Config

type CookieAuthConfig

type CookieAuthConfig struct {
	CookieName string `yaml:"cookie_name" validate:"required,min=1,max=64"`
	Domain     string `yaml:"domain" validate:"required,min=1,max=255"`
	Secure     bool   `yaml:"secure" validate:""`
}

CookieAuthConfig contains configuration for cookie authentication

type EmailConfig

type EmailConfig struct {
	ValidDomains  []string `yaml:"valid_domains" validate:"dive,min=1,max=255"`
	ValidEmails   []string `yaml:"valid_emails" validate:"dive,email"`
	EmailProvider string   `yaml:"email_provider" validate:"required,oneof=mailjet"`
	From          string   `yaml:"from" validate:"required,email"`
	FromName      string   `yaml:"from_name" validate:"required,min=1"`
}

EmailConfig configures email related settings

type JWTConfig

type JWTConfig struct {
	ValidSeconds int `yaml:"valid_seconds" validate:"required,gte=1,lte=1576800000"`
}

JWTConfig configures the authentication token properties

type MailjetConfig

type MailjetConfig struct {
	APIKeyPublic  string `yaml:"apikey_public" validate:"min=0,max=255"`
	APIKeyPrivate string `yaml:"apikey_private" validate:"min=0,max=255"`
}

MailjetConfig provides Mailjet API configuration

type MailjetSender

type MailjetSender struct {
	// contains filtered or unexported fields
}

type RateLimitConfig

type RateLimitConfig struct {
	IP    RateLimitConfigItem `yaml:"ip"`
	Email RateLimitConfigItem `yaml:"email"`
}

RateLimitConfig defines rate limiting for different things

type RateLimitConfigItem

type RateLimitConfigItem struct {
	PerHour int `yaml:"per_hour" validate:"gte=0,lte=100000"`
}

RateLimitConfigItem contains details for rate limiting

type Server

type Server struct {
	Config        Config
	MailjetSender *MailjetSender
}

Server provides the interface for setting up a HTTP server

func NewServer

func NewServer(config Config) *Server

NewServer creates a new server with this configuration

func (*Server) Start

func (s *Server) Start()

Start the server

type ServerConfig

type ServerConfig struct {
	ListenType string `yaml:"listen_type" validate:"required,oneof=unix http"`
	Socket     string `yaml:"socket" validate:"min=1,max=255"`
	Host       string `yaml:"host" validate:"min=1,max=255"`
	Port       int    `yaml:"port" validate:"gte=1,lte=65535"`
}

ServerConfig contains configuration for the HTTP server

Jump to

Keyboard shortcuts

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