configuration

package
v7.4.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2017 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Configuration

type Configuration struct {

	// EnableReuseport if set to true then it turns on the Reuseport feature.
	//
	// Defaults to false.
	EnableReuseport bool `yaml:"EnableReuseport" toml:"EnableReuseport"`

	// EnableQUICSupport if set to true then it turns on the QUIC protocol feature.
	// Only with a TLS Server
	//
	// Defaults to false.
	EnableQUICSupport bool `yaml:"EnableQUICSupport" toml:"EnableQUICSupport"`

	// DisableBanner if set to true then it turns off the write banner on server startup.
	//
	// Defaults to false.
	DisableBanner bool `yaml:"DisableBanner" toml:"DisableBanner"`

	// DisableInterruptHandler if set to true then it disables the automatic graceful server shutdown
	// when control/cmd+C pressed.
	// Turn this to true if you're planning to handle this by your own via a custom host.Task.
	//
	// Defaults to false.
	DisableInterruptHandler bool `yaml:"DisableInterruptHandler" toml:"DisableInterruptHandler"`

	// DisablePathCorrection corrects and redirects the requested path to the registered 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
	//
	// Defaults to false.
	DisablePathCorrection bool `yaml:"DisablePathCorrection" toml:"DisablePathCorrection"`

	// EnablePathEscape when is true then its escapes the path, the named parameters (if any).
	// Change to false it if you want something like this https://github.com/go-siris/siris/issues/135 to work
	//
	// When do you need to Disable(false) 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").
	//
	// Defaults to false.
	EnablePathEscape bool `yaml:"EnablePathEscape" toml:"EnablePathEscape"`

	// FireMethodNotAllowed if it's true router checks for StatusMethodNotAllowed(405) and
	//  fires the 405 error instead of 404
	// Defaults to false.
	FireMethodNotAllowed bool `yaml:"FireMethodNotAllowed" toml:"FireMethodNotAllowed"`

	// DisableBodyConsumptionOnUnmarshal manages the reading behavior of the context's body readers/binders.
	// If set to true then it
	// disables the body consumption by the `context.UnmarshalBody/ReadJSON/ReadXML`.
	//
	// By-default io.ReadAll` is used to read the body from the `context.Request.Body which is an `io.ReadCloser`,
	// if this field set to true then a new buffer will be created to read from and the request body.
	// The body will not be changed and existing data before the
	// context.UnmarshalBody/ReadJSON/ReadXML will be not consumed.
	DisableBodyConsumptionOnUnmarshal bool `yaml:"DisableBodyConsumptionOnUnmarshal" toml:"DisableBodyConsumptionOnUnmarshal"`

	// JSONInteratorReplacement manages the reading behavior of the context's body readers/binders.
	// If set to true, it replaces the "encoding / json" libery with jsoniter (JSON-Interator) for
	// `context.UnmarshalBody/ReadJSON/JSON/JSONP`.
	// If returns true then the JSON body is Marshal and Unmarshal by JSON-Interator a dropin replacment
	// for encoding/json.
	JSONInteratorReplacement bool `yaml:"JSONInteratorReplacement" toml:"JSONInteratorReplacement"`

	// DisableAutoFireStatusCode if true then it turns off the http error status code handler automatic execution
	// from "context.StatusCode(>=400)" and instead app should manually call the "context.FireStatusCode(>=400)".
	//
	// By-default a custom http error handler will be fired when "context.StatusCode(code)" called,
	// code should be >=400 in order to be received as an "http error handler".
	//
	// Developer may want this option to set as true in order to manually call the
	// error handlers when needed via "context.FireStatusCode(>=400)".
	// HTTP Custom error handlers are being registered via "framework.OnStatusCode(code, handler)".
	//
	// Defaults to false.
	DisableAutoFireStatusCode bool `yaml:"DisableAutoFireStatusCode" toml:"DisableAutoFireStatusCode"`

	// TimeFormat time format for any kind of datetime parsing
	// Defaults to  "Mon, 02 Jan 2006 15:04:05 GMT".
	TimeFormat string `yaml:"TimeFormat" toml:"TimeFormat"`

	// Charset character encoding for various rendering
	// used for templates and the rest of the responses
	// Defaults to "UTF-8".
	Charset string `yaml:"Charset" toml:"Charset"`

	// Context values' keys for various features.
	//
	// TranslateLanguageContextKey & TranslateFunctionContextKey are used by i18n handlers/middleware
	// currently we have only one: https://github.com/go-siris/siris/tree/master/middleware/i18n.
	//
	// Defaults to "siris.translate" and "siris.language"
	TranslateFunctionContextKey string `yaml:"TranslateFunctionContextKey" toml:"TranslateFunctionContextKey"`

	// TranslateLanguageContextKey used for i18n.
	//
	// Defaults to "siris.language"
	TranslateLanguageContextKey string `yaml:"TranslateLanguageContextKey" toml:"TranslateLanguageContextKey"`

	// GetViewLayoutContextKey is the key of the context's user values' key
	// which is being used to set the template
	// layout from a middleware or the main handler.
	// Overrides the parent's or the configuration's.
	//
	// Defaults to "siris.ViewLayout"
	ViewLayoutContextKey string `yaml:"ViewLayoutContextKey" toml:"ViewLayoutContextKey"`
	// GetViewDataContextKey is the key of the context's user values' key
	// which is being used to set the template
	// binding data from a middleware or the main handler.
	//
	// Defaults to "siris.viewData"
	ViewDataContextKey string `yaml:"ViewDataContextKey" toml:"ViewDataContextKey"`

	// RemoteAddrHeaders returns the allowed request headers names
	// that can be valid to parse the client's IP based on.
	//
	// Defaults to:
	// "X-Real-Ip":             false,
	// "X-Forwarded-For":       false,
	// "CF-Connecting-IP":      false
	//
	// Look `context.RemoteAddr()` for more.
	RemoteAddrHeaders map[string]bool `yaml:"RemoteAddrHeaders" toml:"RemoteAddrHeaders"`

	// Other are the custom, dynamic options, can be empty.
	// This field used only by you to set any app's options you want
	// or by custom adaptors, it's a way to simple communicate between your adaptors (if any)
	// Defaults to a non-nil empty map
	Other map[string]interface{} `yaml:"Other" toml:"Other"`
	// contains filtered or unexported fields
}

Configuration the whole configuration for an Siris instance these can be passed via options also, look at the top of this file(configuration.go). Configuration is a valid OptionSetter.

func DefaultConfiguration

func DefaultConfiguration() Configuration

DefaultConfiguration returns the default configuration for an Siris station, fills the main Configuration

func TOML

func TOML(filename string) Configuration

TOML reads Configuration from a toml-compatible document file. Read more about toml's implementation at: https://github.com/toml-lang/toml

Accepts the absolute path of the configuration file. An error will be shown to the user via panic with the error message. Error may occur when the file doesn't exists or is not formatted correctly.

Usage: app := siris.Run(siris.Addr(":8080"), siris.WithConfiguration(siris.YAML("myconfig.tml")))

func YAML

func YAML(filename string) Configuration

YAML reads Configuration from a configuration.yml file.

Accepts the absolute path of the configuration.yml. An error will be shown to the user via panic with the error message. Error may occur when the configuration.yml doesn't exists or is not formatted correctly.

Usage: app := siris.Run(siris.Addr(":8080"), siris.WithConfiguration(siris.YAML("myconfig.yml")))

func (Configuration) GetCharset

func (c Configuration) GetCharset() string

GetCharset returns the configuration.Charset, the character encoding for various rendering used for templates and the rest of the responses.

func (Configuration) GetDisableAutoFireStatusCode

func (c Configuration) GetDisableAutoFireStatusCode() bool

GetDisableAutoFireStatusCode returns the configuration.DisableAutoFireStatusCode. Returns true when the http error status code handler automatic execution turned off.

func (Configuration) GetDisableBodyConsumptionOnUnmarshal

func (c Configuration) GetDisableBodyConsumptionOnUnmarshal() bool

GetDisableBodyConsumptionOnUnmarshal returns the configuration.DisableBodyConsumptionOnUnmarshal, manages the reading behavior of the context's body readers/binders. If returns true then the body consumption by the `context.UnmarshalBody/ReadJSON/ReadXML` is disabled.

By-default io.ReadAll` is used to read the body from the `context.Request.Body which is an `io.ReadCloser`, if this field set to true then a new buffer will be created to read from and the request body. The body will not be changed and existing data before the context.UnmarshalBody/ReadJSON/ReadXML will be not consumed.

func (Configuration) GetDisablePathCorrection

func (c Configuration) GetDisablePathCorrection() bool

GetDisablePathCorrection returns the configuration.DisablePathCorrection, DisablePathCorrection corrects and redirects the requested path to the registered 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.

func (Configuration) GetEnablePathEscape

func (c Configuration) GetEnablePathEscape() bool

GetEnablePathEscape is the configuration.EnablePathEscape, returns true when its escapes the path, the named parameters (if any).

func (Configuration) GetEnableQUICSupport

func (c Configuration) GetEnableQUICSupport() bool

GetEnableQUICSupport is the configuration.EnableQUICSupport, returns true when its use the feature of the QUIC protocol for TLS Server.

func (Configuration) GetEnableReuseport

func (c Configuration) GetEnableReuseport() bool

GetEnableReuseport is the configuration.EnableReuseport, returns true when its use the feature of the Reusepost listener.

func (Configuration) GetFireMethodNotAllowed

func (c Configuration) GetFireMethodNotAllowed() bool

GetFireMethodNotAllowed returns the configuration.FireMethodNotAllowed.

func (Configuration) GetJSONInteratorReplacement

func (c Configuration) GetJSONInteratorReplacement() bool

GetJSONInteratorReplacement returns the configuration.JSONInteratorReplacement, manages the reading behavior of the context's body readers/binders.

If returns true then the JSON body is Marshal and Unmarshal by JSON-Interator a dropin replacment for encoding/json.

func (Configuration) GetOther

func (c Configuration) GetOther() map[string]interface{}

GetOther returns the configuration.Other map.

func (Configuration) GetRemoteAddrHeaders

func (c Configuration) GetRemoteAddrHeaders() map[string]bool

GetRemoteAddrHeaders returns the allowed request headers names that can be valid to parse the client's IP based on.

Defaults to: "X-Real-Ip": false, "X-Forwarded-For": false, "CF-Connecting-IP": false

Look `context.RemoteAddr()` for more.

func (Configuration) GetTimeFormat

func (c Configuration) GetTimeFormat() string

GetTimeFormat returns the configuration.TimeFormat, format for any kind of datetime parsing.

func (Configuration) GetTranslateFunctionContextKey

func (c Configuration) GetTranslateFunctionContextKey() string

GetTranslateFunctionContextKey returns the configuration's TranslateFunctionContextKey value, used for i18n.

func (Configuration) GetTranslateLanguageContextKey

func (c Configuration) GetTranslateLanguageContextKey() string

GetTranslateLanguageContextKey returns the configuration's TranslateLanguageContextKey value, used for i18n.

func (Configuration) GetVHost

func (c Configuration) GetVHost() string

GetVHost returns the non-exported vhost config field.

If original addr ended with :443 or :80, it will return the host without the port. If original addr was :https or :http, it will return localhost. If original addr was 0.0.0.0, it will return localhost.

func (Configuration) GetViewDataContextKey

func (c Configuration) GetViewDataContextKey() string

GetViewDataContextKey returns the key of the context's user values' key which is being used to set the template binding data from a middleware or the main handler.

func (Configuration) GetViewLayoutContextKey

func (c Configuration) GetViewLayoutContextKey() string

GetViewLayoutContextKey returns the key of the context's user values' key which is being used to set the template layout from a middleware or the main handler. Overrides the parent's or the configuration's.

func (Configuration) SetVHost

func (c Configuration) SetVHost(vhost string)

Jump to

Keyboard shortcuts

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