config

package
v3.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2016 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 1 more Imports: 9 Imported by: 0

Documentation

Overview

Package config defines the default settings and semantic variables

Index

Constants

View Source
const (
	DefaultDisablePathCorrection = false
	DefaultDisablePathEscape     = false
)

Default values for base Iris conf

View Source
const (
	// DefaultCookieName the secret cookie's name for sessions
	DefaultCookieName = "irissessionid"
	// DefaultSessionGcDuration  is the default Session Manager's GCDuration , which is 2 hours
	DefaultSessionGcDuration = time.Duration(2) * time.Hour
	// DefaultRedisNetwork the redis network option, "tcp"
	DefaultRedisNetwork = "tcp"
	// DefaultRedisAddr the redis address option, "127.0.0.1:6379"
	DefaultRedisAddr = "127.0.0.1:6379"
	// DefaultRedisIdleTimeout the redis idle timeout option, time.Duration(5) * time.Minute
	DefaultRedisIdleTimeout = time.Duration(5) * time.Minute
	// DefaultRedisMaxAgeSeconds the redis storage last parameter (SETEX), 31556926.0 (1 year)
	DefaultRedisMaxAgeSeconds = 31556926.0 //1 year

)
View Source
const (
	// DefaultWriteTimeout 15 * time.Second
	DefaultWriteTimeout = 15 * time.Second
	// DefaultPongTimeout 60 * time.Second
	DefaultPongTimeout = 60 * time.Second
	// DefaultPingPeriod (DefaultPongTimeout * 9) / 10
	DefaultPingPeriod = (DefaultPongTimeout * 9) / 10
	// DefaultMaxMessageSize 1024
	DefaultMaxMessageSize = 1024
)

Currently only these 5 values are used for real

View Source
const DefaultLoggerPrefix = ""

DefaultLoggerPrefix is the prefix (expect the [IRIS]), is empty for now

View Source
const ServerName = "iris"

ServerName the response header of the 'Server' value when writes to the client

Variables

View Source
var (
	// StaticCacheDuration expiration duration for INACTIVE file handlers
	StaticCacheDuration = 20 * time.Second
	// CompressedFileSuffix is the suffix to add to the name of
	// cached compressed file when using the .StaticFS function.
	//
	// Defaults to iris-fasthttp.gz
	CompressedFileSuffix = "iris-fasthttp.gz"
)
View Source
var (
	// DefaultServerHostname returns the default hostname which is 127.0.0.1
	DefaultServerHostname = "127.0.0.1"
	// DefaultServerPort returns the default port which is 8080
	DefaultServerPort = 8080
	// DefaultMaxRequestBodySize is 8MB
	DefaultMaxRequestBodySize = 2 * fasthttp.DefaultMaxRequestBodySize

	// Per-connection buffer size for requests' reading.
	// This also limits the maximum header size.
	//
	// Increase this buffer if your clients send multi-KB RequestURIs
	// and/or multi-KB headers (for example, BIG cookies).
	//
	// Default buffer size is 8MB
	DefaultReadBufferSize = 8096

	// Per-connection buffer size for responses' writing.
	//
	// Default buffer size is 8MB
	DefaultWriteBufferSize = 8096
)

Default values for base Server conf, can be changed for global use

View Source
var (
	// Charset character encoding.
	Charset = "UTF-8"
)
View Source
var (

	// CookieExpireNever the default cookie's life for sessions, unlimited
	CookieExpireNever = universe
)
View Source
var (
	// DefaultServerAddr the default server addr which is: 127.0.0.1:8080
	DefaultServerAddr = DefaultServerHostname + ":" + strconv.Itoa(DefaultServerPort)
)
View Source
var (
	// TimeFormat default time format for any kind of datetime parsing
	TimeFormat = "Mon, 02 Jan 2006 15:04:05 GMT"
)

Functions

func ServerParseAddr

func ServerParseAddr(listeningAddr string) string

ServerParseAddr parses the listening addr and returns this

Types

type Amber

type Amber struct {
	// Funcs for the html/template result, amber default funcs are not overrided so use it without worries
	Funcs template.FuncMap
}

Amber the configs for AmberEngine

type EngineType

type EngineType int8

EngineType is the type of template engine

const (
	// NoEngine is a Template's config for engine type
	// when use this, the templates are disabled
	NoEngine EngineType = -1
	// HTMLEngine is a Template's config for engine type
	// when use this, the templates are html/template
	HTMLEngine EngineType = 0
	// PongoEngine is a Template's config for engine type
	// when use this, the templates are flosch/pongo2
	PongoEngine EngineType = 1
	// MarkdownEngine is a Template's config for engine type
	// when use this, the templates are .md files
	MarkdownEngine EngineType = 2
	// JadeEngine is a Template's config for engine type
	// when use this, the templates are joker/jade
	JadeEngine EngineType = 3
	// AmberEngine is a Template's config for engine type
	// when use this, the templates are eknkc/amber
	AmberEngine EngineType = 4
	// HandlebarsEngine is a Template's config for engine type
	// when use this, the templates are aymerick/raymond
	HandlebarsEngine EngineType = 5
	// DefaultEngine is the HTMLEngine
	DefaultEngine EngineType = HTMLEngine

	// NoLayout to disable layout for a particular template file
	NoLayout = "@.|.@iris_no_layout@.|.@"
	// TemplateLayoutContextKey is the name of the user values which can be used to set a template layout from a middleware and override the parent's
	TemplateLayoutContextKey = "templateLayout"
)

type HTMLTemplate

type HTMLTemplate struct {
	// RequirePartials default is false
	RequirePartials bool
	// Delims
	// Left delimeter, default is {{
	Left string
	// Right delimeter, default is }}
	Right string
	// Funcs like html/template
	Funcs map[string]interface{}
	// LayoutFuncs like html/template
	// the difference from Funcs is that these funcs
	// can be used inside a layout and can override the predefined (yield,partial...) or add more custom funcs
	// these can override the Funcs inside no-layout templates also, use it when you know what you're doing
	LayoutFuncs map[string]interface{}
}

HTMLTemplate the configs for HTMLEngine

type Handlebars

type Handlebars struct {
	// Helpers for Handlebars, you can register your own by raymond.RegisterHelper(name string, a interface{}) or RegisterHelpers(map[string]interface{})
	// or just fill this method, do not override it it is not nil by default (because of Iris' helpers (url and urlpath)
	Helpers map[string]interface{}
}

Handlebars the configs for HandlebarsEngine

type Iris

type Iris struct {

	// DisablePathCorrection corrects and redirects the requested path to the registed path
	// for example, if /home/ path is requested but no handler for this Route found,
	// then the Router checks if /home handler exists, if yes,
	// (permant)redirects the client to the correct path /home
	//
	// Default is false
	DisablePathCorrection bool

	// DisablePathEscape when is false then its escapes the path, the named parameters (if any).
	// Change to true it if you want something like this https://github.com/kataras/iris/issues/135 to work
	//
	// When do you need to Disable(true) it:
	// accepts parameters with slash '/'
	// Request: http://localhost:8080/details/Project%2FDelta
	// ctx.Param("project") returns the raw named parameter: Project%2FDelta
	// which you can escape it manually with net/url:
	// projectName, _ := url.QueryUnescape(c.Param("project").
	// Look here: https://github.com/kataras/iris/issues/135 for more
	//
	// Default is false
	DisablePathEscape bool

	// DisableBanner outputs the iris banner at startup
	//
	// Default is false
	DisableBanner bool

	// ProfilePath a the route path, set it to enable http pprof tool
	// Default is empty, if you set it to a $path, these routes will handled:
	// $path/cmdline
	// $path/profile
	// $path/symbol
	// $path/goroutine
	// $path/heap
	// $path/threadcreate
	// $path/pprof/block
	// for example if '/debug/pprof'
	// http://yourdomain:PORT/debug/pprof/
	// http://yourdomain:PORT/debug/pprof/cmdline
	// http://yourdomain:PORT/debug/pprof/profile
	// http://yourdomain:PORT/debug/pprof/symbol
	// http://yourdomain:PORT/debug/pprof/goroutine
	// http://yourdomain:PORT/debug/pprof/heap
	// http://yourdomain:PORT/debug/pprof/threadcreate
	// http://yourdomain:PORT/debug/pprof/pprof/block
	// it can be a subdomain also, for example, if 'debug.'
	// http://debug.yourdomain:PORT/
	// http://debug.yourdomain:PORT/cmdline
	// http://debug.yourdomain:PORT/profile
	// http://debug.yourdomain:PORT/symbol
	// http://debug.yourdomain:PORT/goroutine
	// http://debug.yourdomain:PORT/heap
	// http://debug.yourdomain:PORT/threadcreate
	// http://debug.yourdomain:PORT/pprof/block
	ProfilePath string

	// Logger the configuration for the logger
	// Iris logs ONLY SEMANTIC errors and the banner if enabled
	Logger Logger

	// Sessions contains the configs for sessions
	Sessions Sessions

	// Render contains the configs for template and rest configuration
	Render Render

	// Websocket contains the configs for Websocket's server integration
	Websocket *Websocket

	// Tester contains the configs for the test framework, so far we have only one because all test framework's configs are setted by the iris itself
	Tester Tester
}

Iris configs for the station All fields can be changed before server's listen except the DisablePathCorrection field

MaxRequestBodySize is the only options that can be changed after server listen - using Config.MaxRequestBodySize = ... Render's rest config can be changed after declaration but before server's listen - using Config.Render.Rest... Render's Template config can be changed after declaration but before server's listen - using Config.Render.Template... Sessions config can be changed after declaration but before server's listen - using Config.Sessions... and so on...

func Default

func Default() Iris

Default returns the default configuration for the Iris staton

func (Iris) Merge

func (c Iris) Merge(cfg []Iris) (config Iris)

Merge merges the default with the given config and returns the result receives an array because the func caller is variadic

func (Iris) MergeSingle

func (c Iris) MergeSingle(cfg Iris) (config Iris)

MergeSingle merges the default with the given config and returns the result

type Jade

type Jade HTMLTemplate

Jade the configs for JadeEngine

type Logger

type Logger struct {
	// Out the (file) writer which the messages/logs will printed to
	// Default is os.Stdout
	Out *os.File
	// Prefix the prefix for each message
	// Default is ""
	Prefix string
	// Disabled default is false
	Disabled bool

	// ColorFgDefault the foreground color for the normal message bodies
	ColorFgDefault int
	// ColorFgInfo the foreground  color for info messages
	ColorFgInfo int
	// ColorFgSuccess the foreground color for success messages
	ColorFgSuccess int
	// ColorFgWarning the foreground color for warning messages
	ColorFgWarning int
	// ColorFgDanger the foreground color for error messages
	ColorFgDanger int
	// OtherFgColor the foreground color for the rest of the message types
	ColorFgOther int

	// ColorBgDefault the background color for the normal messages
	ColorBgDefault int
	// ColorBgInfo the background  color for info messages
	ColorBgInfo int
	// ColorBgSuccess the background color for success messages
	ColorBgSuccess int
	// ColorBgWarning the background color for warning messages
	ColorBgWarning int
	// ColorBgDanger the background color for error messages
	ColorBgDanger int
	// OtherFgColor the background color for the rest of the message types
	ColorBgOther int

	// ColorFgBanner the foreground color for the banner
	ColorFgBanner int
}

Logger contains the full configuration options fields for the Logger

func DefaultLogger

func DefaultLogger() Logger

DefaultLogger returns the default configs for the Logger

func (Logger) MergeSingle

func (c Logger) MergeSingle(cfg Logger) (config Logger)

MergeSingle merges the default with the given config and returns the result

type Markdown

type Markdown struct {
	Sanitize bool // if true then returns safe html, default is false
}

Markdown the configs for MarkdownEngine

type Pongo

type Pongo struct {
	// Filters for pongo2, map[name of the filter] the filter function . The filters are auto register
	Filters map[string]pongo2.FilterFunction
	// Globals share context fields between templates. https://github.com/flosch/pongo2/issues/35
	Globals map[string]interface{}
}

Pongo the configs for PongoEngine

type Redis

type Redis struct {
	// Network "tcp"
	Network string
	// Addr "127.0.0.1:6379"
	Addr string
	// Password string .If no password then no 'AUTH'. Default ""
	Password string
	// If Database is empty "" then no 'SELECT'. Default ""
	Database string
	// MaxIdle 0 no limit
	MaxIdle int
	// MaxActive 0 no limit
	MaxActive int
	// IdleTimeout  time.Duration(5) * time.Minute
	IdleTimeout time.Duration
	// Prefix "myprefix-for-this-website". Default ""
	Prefix string
	// MaxAgeSeconds how much long the redis should keep the session in seconds. Default 31556926.0 (1 year)
	MaxAgeSeconds int
}

Redis the redis configuration used inside sessions

func DefaultRedis

func DefaultRedis() Redis

DefaultRedis returns the default configuration for Redis service

func (Redis) Merge

func (c Redis) Merge(cfg []Redis) (config Redis)

Merge merges the default with the given config and returns the result

func (Redis) MergeSingle

func (c Redis) MergeSingle(cfg Redis) (config Redis)

MergeSingle merges the default with the given config and returns the result

type Render

type Render struct {
	// Template the configs for template
	Template Template
	// Rest configs for rendering.
	//
	// these options inside this config don't have any relation with the TemplateEngine
	// from github.com/kataras/iris/rest
	Rest Rest
}

Render struct keeps organise all configuration about rendering, templates and rest currently.

func DefaultRender

func DefaultRender() Render

DefaultRender returns default configuration for templates and rest rendering

type Rest

type Rest struct {
	// Appends the given character set to the Content-Type header. Default is "UTF-8".
	Charset string
	// Gzip enable it if you want to render with gzip compression. Default is false
	Gzip bool
	// Outputs human readable JSON.
	IndentJSON bool
	// Outputs human readable XML. Default is false.
	IndentXML bool
	// Prefixes the JSON output with the given bytes. Default is false.
	PrefixJSON []byte
	// Prefixes the XML output with the given bytes.
	PrefixXML []byte
	// Unescape HTML characters "&<>" to their original values. Default is false.
	UnEscapeHTML bool
	// Streams JSON responses instead of marshalling prior to sending. Default is false.
	StreamingJSON bool
	// Disables automatic rendering of http.StatusInternalServerError when an error occurs. Default is false.
	DisableHTTPErrorRendering bool
	// MarkdownSanitize sanitizes the markdown. Default is false.
	MarkdownSanitize bool
}

Rest is a struct for specifying configuration options for the rest.Render object.

func DefaultRest

func DefaultRest() Rest

DefaultRest returns the default config for rest

func (Rest) Merge

func (c Rest) Merge(cfg []Rest) (config Rest)

Merge merges the default with the given config and returns the result

func (Rest) MergeSingle

func (c Rest) MergeSingle(cfg Rest) (config Rest)

MergeSingle merges the default with the given config and returns the result

type Server

type Server struct {
	// ListenningAddr the addr that server listens to
	ListeningAddr string
	CertFile      string
	KeyFile       string
	// Mode this is for unix only
	Mode os.FileMode
	// MaxRequestBodySize Maximum request body size.
	//
	// The server rejects requests with bodies exceeding this limit.
	//
	// By default request body size is 8MB.
	MaxRequestBodySize int

	// Per-connection buffer size for requests' reading.
	// This also limits the maximum header size.
	//
	// Increase this buffer if your clients send multi-KB RequestURIs
	// and/or multi-KB headers (for example, BIG cookies).
	//
	// Default buffer size is used if not set.
	ReadBufferSize int

	// Per-connection buffer size for responses' writing.
	//
	// Default buffer size is used if not set.
	WriteBufferSize int
	// RedirectTo, defaults to empty, set it in order to override the station's handler and redirect all requests to this address which is of form(HOST:PORT or :PORT)
	//
	// NOTE: the http status is 'StatusMovedPermanently', means one-time-redirect(the browser remembers the new addr and goes to the new address without need to request something from this server
	// which means that if you want to change this address you have to clear your browser's cache in order this to be able to change to the new addr.
	//
	// example: https://github.com/iris-contrib/examples/tree/master/multiserver_listening2
	RedirectTo string
	// Virtual If this server is not really listens to a real host, it mostly used in order to achieve testing without system modifications
	Virtual bool
}

Server used inside server for listening

func DefaultServer

func DefaultServer() Server

DefaultServer returns the default configs for the server

func (Server) Merge

func (c Server) Merge(cfg []Server) (config Server)

Merge merges the default with the given config and returns the result

func (Server) MergeSingle

func (c Server) MergeSingle(cfg Server) (config Server)

MergeSingle merges the default with the given config and returns the result

type Sessions

type Sessions struct {
	// Provider string, usage iris.Config().Provider = "memory" or "redis". If you wan to customize redis then import the package, and change it's config
	Provider string
	// Cookie string, the session's client cookie name, for example: "irissessionid"
	Cookie string
	// DecodeCookie set it to true to decode the cookie key with base64 URLEncoding
	// Defaults to false
	DecodeCookie bool
	//Expires the date which the cookie must expires. Default infinitive/unlimited life
	Expires time.Time
	// GcDuration every how much duration(GcDuration) the memory should be clear for unused cookies (GcDuration)
	// for example: time.Duration(2)*time.Hour. it will check every 2 hours if cookie hasn't be used for 2 hours,
	// deletes it from memory until the user comes back, then the session continue to work as it was
	//
	// Default 2 hours
	GcDuration time.Duration

	// DisableSubdomainPersistence set it to dissallow your iris subdomains to have access to the session cookie
	// defaults to false
	DisableSubdomainPersistence bool
}

Sessions the configuration for sessions has 4 fields first is the providerName (string) ["memory","redis"] second is the cookieName, the session's name (string) ["mysessionsecretcookieid"] third is the time which the client's cookie expires forth is the gcDuration (time.Duration) when this time passes it removes the unused sessions from the memory until the user come back

func DefaultSessions

func DefaultSessions() Sessions

DefaultSessions the default configs for Sessions

func (Sessions) Merge

func (c Sessions) Merge(cfg []Sessions) (config Sessions)

Merge merges the default with the given config and returns the result

func (Sessions) MergeSingle

func (c Sessions) MergeSingle(cfg Sessions) (config Sessions)

MergeSingle merges the default with the given config and returns the result

type Template

type Template struct {
	// Engine the type of template engine
	// default is DefaultEngine (HTMLEngine)
	Engine EngineType
	// Gzip enable gzip compression
	// default is false
	Gzip bool

	// IsDevelopment re-builds the templates on each request
	// default is false
	IsDevelopment bool
	// Directory the system path which the templates live
	// default is ./templates
	Directory string
	// Extensions the allowed file extension
	// default is []string{".html"}
	Extensions []string
	// ContentType is the Content-Type response header
	// default is text/html but you can change if if needed
	ContentType string
	// Charset the charset, default is UTF-8
	Charset string
	// Asset is a func which returns bytes, use it to load the templates by binary
	Asset func(name string) ([]byte, error)
	// AssetNames should returns the template filenames, look Asset
	AssetNames func() []string
	// Layout the template file ( with its extension) which is the mother of all
	// use it to have it as a root file, and include others with {{ yield }}, refer  the docs
	Layout string

	// HTMLTemplate contains specific configs for HTMLTemplate standard html/template
	HTMLTemplate HTMLTemplate
	// Jade contains specific configs for Jade
	Jade Jade
	// Pongo contains specific configs for pongo2
	Pongo Pongo
	// Markdown contains specific configs for  markdown
	// this doesn't supports Layout & binding context
	Markdown Markdown
	// Amber contains specific configs for amber
	Amber Amber
	// Handlebars contains specific configs for handlebars
	Handlebars Handlebars
}

Template the configs for templates (template/view engines) contains common configs for all template engines

func DefaultTemplate

func DefaultTemplate() Template

DefaultTemplate returns the default template configs

func (Template) Merge

func (c Template) Merge(cfg []Template) (config Template)

Merge merges the default with the given config and returns the result

func (Template) MergeSingle

func (c Template) MergeSingle(cfg Template) (config Template)

MergeSingle merges the default with the given config and returns the result

type Tester

type Tester struct {
	ListeningAddr string
	ExplicitURL   bool
	Debug         bool
}

Tester configuration

func DefaultTester

func DefaultTester() Tester

DefaultTester returns the default configuration for a tester the ListeningAddr is used as virtual only when no running server is founded

type Websocket

type Websocket struct {
	// WriteTimeout time allowed to write a message to the connection.
	// Default value is 15 * time.Second
	WriteTimeout time.Duration
	// PongTimeout allowed to read the next pong message from the connection
	// Default value is 60 * time.Second
	PongTimeout time.Duration
	// PingPeriod send ping messages to the connection with this period. Must be less than PongTimeout
	// Default value is (PongTimeout * 9) / 10
	PingPeriod time.Duration
	// MaxMessageSize max message size allowed from connection
	// Default value is 1024
	MaxMessageSize int64
	// Endpoint is the path which the websocket server will listen for clients/connections
	// Default value is empty string, if you don't set it the Websocket server is disabled.
	Endpoint string
	// Headers  the response headers before upgrader
	// Default is empty
	Headers map[string]string
	// ReadBufferSize is the buffer size for the underline reader
	ReadBufferSize int
	// WriteBufferSize is the buffer size for the underline writer
	WriteBufferSize int
}

Websocket the config contains options for 'websocket' package

func DefaultWebsocket

func DefaultWebsocket() *Websocket

DefaultWebsocket returns the default config for iris-ws websocket package

func (*Websocket) Merge

func (c *Websocket) Merge(cfg []*Websocket) (config *Websocket)

Merge merges the default with the given config and returns the result

func (*Websocket) MergeSingle

func (c *Websocket) MergeSingle(cfg *Websocket) (config *Websocket)

MergeSingle merges the default with the given config and returns the result

Jump to

Keyboard shortcuts

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