server

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2021 License: MIT Imports: 27 Imported by: 0

Documentation

Overview

Package server is a configurable webserver with pre-defined hooks.

Index

Constants

View Source
const (
	ROUTER = iota + 1
	DB
	CACHE
	TRANSLATION
)

Variables

View Source
var (
	ErrInit = errors.New("server: is not loaded")
	ErrJWT  = errors.New("server: jwt is not defined")
)

Error messages

View Source
var (
	ErrConfig = "server: config %#v is mandatory"
)

Error messages.

Functions

func Caches

func Caches() ([]cache.Manager, error)

Caches of the webserver. Error will return if the server instance was not created yet.

func Config

func Config() (interface{}, error)

Config will return the given configuration. Error will return if the server instance was not created yet.

func Databases

func Databases() ([]query.Builder, error)

Databases of the webserver. Error will return if the server instance was not created yet.

func Dir added in v0.1.11

func Dir() (string, error)

Dir will return the running application directory.

func FrontendConfigConverter

func FrontendConfigConverter(cfg interface{}, addChildren ...bool) map[string]interface{}

FrontendConfigConverter will return all configuration fields as map, if the tag `frontend` exists and the its not the skip tag. Works with embedded fields. If the `frontend` tag exists on a struct, all struct fields will be added, except if a skip tag was used on one or more fields. The the json keys will be first letter to lower.

func JWT

func JWT() (*jwt.Token, error)

JWT of the webserver. Error will return if the server instance was not created yet.

func New

func New(config interface{}) error

New creates a new server instance with the given configuration.

func Router

func Router() (router.Manager, error)

Router of the webserver. Error will return if the server instance was not created yet.

func SetJWT

func SetJWT(t *jwt.Token) error

SetJWT to the webserver. This is needed because the jwt token claim must be set-able to guarantee a customization.

func Start

func Start() error

Start the webserver. Error will return if the server instance was not created yet.

func Stop

func Stop() error

Stop the webserver. Error will return if the server instance was not created yet.

func Translation

func Translation() (translation.Manager, error)

Translation of the webserver. Error will return if the server instance was not created yet.

Types

type Configuration

type Configuration struct {
	Webserver ConfigurationWebserver
	Databases []query.Config
	Mail      ConfigurationMail
	Caches    []ConfigurationCache
}

Configuration for the Webserver. This configuration can be simple embedded in your application config.

func ServerConfig

func ServerConfig() (Configuration, error)

ServerConfig will return the server.Configuration. Error will return if the server instance was not created yet.

type ConfigurationApp

type ConfigurationApp struct {
	Name      string `frontend:""`
	LogoSmall string `frontend:""`
	BgImg     string `frontend:""`
}

type ConfigurationAuth

type ConfigurationAuth struct {
	Providers            map[string]map[string]interface{} `frontend:""`
	JWT                  jwt.Config
	BcryptCost           int    `json:"bcryptCost"`
	AllowedFailedLogin   int    `json:"allowedFailedLogins"` // 0 = infinity
	LockDuration         string `json:"lockDuration"`
	InactiveDuration     string `json:"inactiveDuration"`
	TokenDuration        string `json:"tokenDuration"`
	RefreshTokenDuration string `json:"refreshTokenDuration"`
}

Auth configuration

type ConfigurationCache

type ConfigurationCache struct {
	Provider   string
	GCInterval int
}

type ConfigurationMail

type ConfigurationMail struct {
	Server   string
	Port     int
	User     string
	Password string
	From     string
}

Mail configuration

type ConfigurationRouter

type ConfigurationRouter struct {
	Provider       string
	Favicon        string
	Directories    []PatternSource
	Files          []PatternSource
	CreateDBRoutes bool
}

Router configuration

type ConfigurationWebserver

type ConfigurationWebserver struct {
	App                ConfigurationApp
	Domain             string `frontend:""`
	HTTPPort           int
	FrontendConfigFile string
	Translation        I18n
	Auth               ConfigurationAuth
	Router             ConfigurationRouter
}

Webserver configuration

type I18n

type I18n struct {
	Provider string
	translation.Config
}

type Orm

type Orm struct {
	orm.Model
}

func (Orm) DefaultBuilder

func (o Orm) DefaultBuilder() query.Builder

func (Orm) DefaultCache

func (o Orm) DefaultCache() (cache.Manager, time.Duration)

type PatternSource

type PatternSource struct {
	Pattern string
	Source  string
}

type Route

type Route struct {
	Orm

	ID       int
	Name     string `json:",omitempty"`
	Pattern  string `json:",omitempty"`
	Public   bool   `validate:"omitempty"`
	Frontend bool   `validate:"omitempty"`
	Method   string `validate:"-"`
}

Route struct for frontend and backend routes.

Jump to

Keyboard shortcuts

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