mirror of
https://github.com/kataras/iris.git
synced 2025-02-02 15:30:36 +01:00
gofmt everything, even the vendor.
Former-commit-id: c2bf34c63b5cc6c974ce2b3bcf04bb1c9b77efaf
This commit is contained in:
parent
13e83fc57e
commit
40b62f2958
2
addr.go
2
addr.go
|
@ -150,7 +150,7 @@ func (ln TCPKeepAliveListener) Accept() (c net.Conn, err error) {
|
||||||
return tc, nil
|
return tc, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
///TODO:
|
///TODO: ?
|
||||||
// func (ln TCPKeepAliveListener) Close() error {
|
// func (ln TCPKeepAliveListener) Close() error {
|
||||||
// return nil
|
// return nil
|
||||||
// }
|
// }
|
||||||
|
|
172
configuration.go
172
configuration.go
|
@ -8,20 +8,23 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/imdario/mergo"
|
"github.com/imdario/mergo"
|
||||||
"github.com/kataras/go-options"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
// OptionSetter sets a configuration field to the main configuration
|
// OptionSetter sets a configuration field to the main configuration
|
||||||
// used to help developers to write less and configure only what they really want and nothing else
|
// used to help developers to write less and configure only what
|
||||||
// example:
|
// they really want and nothing else.
|
||||||
|
//
|
||||||
|
// Usage:
|
||||||
// iris.New(iris.Configuration{Charset: "UTF-8", Gzip:true})
|
// iris.New(iris.Configuration{Charset: "UTF-8", Gzip:true})
|
||||||
// now can be done also by using iris.Option$FIELD:
|
// now can be done also by using iris.Option$FIELD:
|
||||||
// iris.New(iris.OptionCharset("UTF-8"), iris.OptionGzip(true))
|
// iris.New(iris.OptionCharset("UTF-8"), iris.OptionGzip(true))
|
||||||
// benefits:
|
//
|
||||||
// 1. dev has no worries what option to pass,
|
// Benefits:
|
||||||
// he/she can just press iris.Option and all options should be shown to her/his editor's autocomplete-popup window
|
// 1. Developers have no worries what option to pass,
|
||||||
// 2. can be passed with any order
|
// they can just type iris.Option and all options should
|
||||||
|
// be visible to their editor's autocomplete-popup window
|
||||||
|
// 2. Can be passed with any order
|
||||||
// 3. Can override previous configuration
|
// 3. Can override previous configuration
|
||||||
OptionSetter interface {
|
OptionSetter interface {
|
||||||
// Set receives a pointer to the global Configuration type and does the job of filling it
|
// Set receives a pointer to the global Configuration type and does the job of filling it
|
||||||
|
@ -36,10 +39,9 @@ func (o OptionSet) Set(c *Configuration) {
|
||||||
o(c)
|
o(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configuration the whole configuration for an iris instance ($instance.Config) or global iris instance (iris.Default.Config)
|
// Configuration the whole configuration for an Iris station instance
|
||||||
// these can be passed via options also, look at the top of this file(configuration.go)
|
// these can be passed via options also, look at the top of this file(configuration.go).
|
||||||
//
|
// Configuration is a valid OptionSetter.
|
||||||
// Configuration is also implements the OptionSet so it's a valid option itself, this is brilliant enough
|
|
||||||
type Configuration struct {
|
type Configuration struct {
|
||||||
// VHost is the addr or the domain that server listens to, which it's optional
|
// VHost is the addr or the domain that server listens to, which it's optional
|
||||||
// When to set VHost manually:
|
// When to set VHost manually:
|
||||||
|
@ -54,20 +56,24 @@ type Configuration struct {
|
||||||
// Note: this is the main's server Host, you can setup unlimited number of net/http servers
|
// Note: this is the main's server Host, you can setup unlimited number of net/http servers
|
||||||
// listening to the $instance.Handler after the manually-called $instance.Build
|
// listening to the $instance.Handler after the manually-called $instance.Build
|
||||||
//
|
//
|
||||||
// Default comes from iris.Default.Listen/.Serve with iris' listeners (iris.TCP4/UNIX/TLS/LETSENCRYPT)
|
// Default comes from iris.Default.Listen/.Serve with iris' listeners (iris.TCP4/UNIX/TLS/LETSENCRYPT).
|
||||||
VHost string
|
VHost string
|
||||||
|
|
||||||
// VScheme is the scheme (http:// or https://) putted at the template function '{{url }}'
|
// VScheme is the scheme (http:// or https://) putted at the template function '{{url }}'
|
||||||
// It's an optional field,
|
// It's an optional field,
|
||||||
// When to set VScheme manually:
|
// When to set VScheme manually:
|
||||||
// 1. You didn't start the main server using $instance.Listen/ListenTLS/ListenLETSENCRYPT or $instance.Serve($instance.TCP4()/.TLS...)
|
// 1. You didn't start the main server using $instance.Listen/ListenTLS/ListenLETSENCRYPT
|
||||||
// 2. if you're using something like nginx and have iris listening with addr only(http://) but the nginx mapper is listening to https://
|
// or $instance.Serve($instance.TCP4()/.TLS...)
|
||||||
|
// 2. if you're using something like nginx and have iris listening with
|
||||||
|
// addr only(http://) but the nginx mapper is listening to https://
|
||||||
//
|
//
|
||||||
// Default comes from iris.Default.Listen/.Serve with iris' listeners (TCP4,UNIX,TLS,LETSENCRYPT)
|
// Default comes from iris.Default.Listen/.Serve with iris' listeners (TCP4,UNIX,TLS,LETSENCRYPT).
|
||||||
VScheme string
|
VScheme string
|
||||||
|
|
||||||
ReadTimeout time.Duration // maximum duration before timing out read of the request
|
// ReadTimeout is the maximum duration before timing out read of the request.
|
||||||
WriteTimeout time.Duration // maximum duration before timing out write of the response
|
ReadTimeout time.Duration
|
||||||
|
// WriteTimeout is the maximum duration before timing out write of the response.
|
||||||
|
WriteTimeout time.Duration
|
||||||
|
|
||||||
// MaxHeaderBytes controls the maximum number of bytes the
|
// MaxHeaderBytes controls the maximum number of bytes the
|
||||||
// server will read parsing the request header's keys and
|
// server will read parsing the request header's keys and
|
||||||
|
@ -98,30 +104,21 @@ type Configuration struct {
|
||||||
// Notes:
|
// Notes:
|
||||||
// 1. Experimental feature
|
// 1. Experimental feature
|
||||||
// 2. If setted to true, the app will start the server normally and runs the updater in its own goroutine,
|
// 2. If setted to true, the app will start the server normally and runs the updater in its own goroutine,
|
||||||
// for a sync operation see CheckForUpdatesSync.
|
// in order to no delay the boot time on your development state.
|
||||||
// 3. If you as developer edited the $GOPATH/src/github/kataras or any other Iris' Go dependencies at the past
|
// 3. If you as developer edited the $GOPATH/src/github/kataras or any other Iris' Go dependencies at the past
|
||||||
// then the update process will fail.
|
// then the update process will fail.
|
||||||
//
|
//
|
||||||
// Usage: iris.Default.Set(iris.OptionCheckForUpdates(true)) or
|
// Usage: app := iris.New(iris.Configuration{CheckForUpdates: true})
|
||||||
// iris.Default.Config.CheckForUpdates = true or
|
|
||||||
// app := iris.New(iris.OptionCheckForUpdates(true))
|
|
||||||
// Default is false
|
|
||||||
CheckForUpdates bool
|
|
||||||
// CheckForUpdatesSync checks for updates before server starts, it will have a little delay depends on the machine's download's speed
|
|
||||||
// See CheckForUpdates for more
|
|
||||||
// Notes:
|
|
||||||
// 1. you could use the CheckForUpdatesSync while CheckForUpdates is false, set this or CheckForUpdates to true not both
|
|
||||||
// 2. if both CheckForUpdates and CheckForUpdatesSync are setted to true then the updater will run in sync mode, before server server starts.
|
|
||||||
//
|
//
|
||||||
// Default is false
|
// Defaults to false.
|
||||||
CheckForUpdatesSync bool
|
CheckForUpdates bool
|
||||||
|
|
||||||
// DisablePathCorrection corrects and redirects the requested path to the registered path
|
// 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,
|
// for example, if /home/ path is requested but no handler for this Route found,
|
||||||
// then the Router checks if /home handler exists, if yes,
|
// then the Router checks if /home handler exists, if yes,
|
||||||
// (permant)redirects the client to the correct path /home
|
// (permant)redirects the client to the correct path /home
|
||||||
//
|
//
|
||||||
// Default is false
|
// Defaults to false.
|
||||||
DisablePathCorrection bool
|
DisablePathCorrection bool
|
||||||
|
|
||||||
// EnablePathEscape when is true then its escapes the path, the named parameters (if any).
|
// EnablePathEscape when is true then its escapes the path, the named parameters (if any).
|
||||||
|
@ -133,18 +130,18 @@ type Configuration struct {
|
||||||
// ctx.Param("project") returns the raw named parameter: Project%2FDelta
|
// ctx.Param("project") returns the raw named parameter: Project%2FDelta
|
||||||
// which you can escape it manually with net/url:
|
// which you can escape it manually with net/url:
|
||||||
// projectName, _ := url.QueryUnescape(c.Param("project").
|
// projectName, _ := url.QueryUnescape(c.Param("project").
|
||||||
// Look here: https://github.com/kataras/iris/issues/135 for more
|
|
||||||
//
|
//
|
||||||
// Default is false
|
// Defaults to false.
|
||||||
EnablePathEscape bool
|
EnablePathEscape bool
|
||||||
|
|
||||||
// FireMethodNotAllowed if it's true router checks for StatusMethodNotAllowed(405) and fires the 405 error instead of 404
|
// FireMethodNotAllowed if it's true router checks for StatusMethodNotAllowed(405) and
|
||||||
// Default is false
|
// fires the 405 error instead of 404
|
||||||
|
// Defaults to false.
|
||||||
FireMethodNotAllowed bool
|
FireMethodNotAllowed bool
|
||||||
|
|
||||||
// DisableBanner outputs the iris banner at startup
|
// DisableBanner outputs the iris banner at startup
|
||||||
//
|
//
|
||||||
// Default is false
|
// Defaults to false.
|
||||||
DisableBanner bool
|
DisableBanner bool
|
||||||
|
|
||||||
// DisableBodyConsumptionOnUnmarshal manages the reading behavior of the context's body readers/binders.
|
// DisableBodyConsumptionOnUnmarshal manages the reading behavior of the context's body readers/binders.
|
||||||
|
@ -153,35 +150,35 @@ type Configuration struct {
|
||||||
//
|
//
|
||||||
// By-default io.ReadAll` is used to read the body from the `context.Request.Body which is an `io.ReadCloser`,
|
// By-default io.ReadAll` is used to read the body from the `context.Request.Body which is an `io.ReadCloser`,
|
||||||
// if this field setted to true then a new buffer will be created to read from and the request body.
|
// if this field setted 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.
|
// The body will not be changed and existing data before the
|
||||||
|
// context.UnmarshalBody/ReadJSON/ReadXML will be not consumed.
|
||||||
DisableBodyConsumptionOnUnmarshal bool
|
DisableBodyConsumptionOnUnmarshal bool
|
||||||
|
|
||||||
// DisableTemplateEngines set to true to disable loading the default template engine (html/template) and disallow the use of iris.Default.UseEngine
|
|
||||||
// Defaults to false
|
|
||||||
DisableTemplateEngines bool
|
|
||||||
|
|
||||||
// TimeFormat time format for any kind of datetime parsing
|
// TimeFormat time format for any kind of datetime parsing
|
||||||
|
// Defauls to "Mon, 02 Jan 2006 15:04:05 GMT".
|
||||||
TimeFormat string
|
TimeFormat string
|
||||||
|
|
||||||
// Charset character encoding for various rendering
|
// Charset character encoding for various rendering
|
||||||
// used for templates and the rest of the responses
|
// used for templates and the rest of the responses
|
||||||
// Defaults to "UTF-8"
|
// Defaults to "UTF-8".
|
||||||
Charset string
|
Charset string
|
||||||
|
|
||||||
// Gzip enables gzip compression on your Render actions, this includes any type of render, templates and pure/raw content
|
// Gzip enables gzip compression on your Render actions, this includes any type of render,
|
||||||
// If you don't want to enable it globally, you could just use the third parameter on context.Render("myfileOrResponse", structBinding{}, iris.RenderOptions{"gzip": true})
|
// templates and pure/raw content
|
||||||
// Defaults to false
|
// If you don't want to enable it globally, you could just use the third parameter
|
||||||
|
// on context.Render("myfileOrResponse", structBinding{}, iris.RenderOptions{"gzip": true})
|
||||||
|
// Defaults to false.
|
||||||
Gzip bool
|
Gzip bool
|
||||||
|
|
||||||
// Other are the custom, dynamic options, can be empty
|
// Other are the custom, dynamic options, can be empty.
|
||||||
// this fill used only by you to set any app's options you want
|
// This field used only by you to set any app's options you want
|
||||||
// for each of an Iris instance
|
// or by custom adaptors, it's a way to simple communicate between your adaptors (if any)
|
||||||
Other options.Options
|
// Defaults to a non-nil empty map.
|
||||||
|
Other map[string]interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set implements the OptionSetter
|
// Set implements the OptionSetter
|
||||||
func (c Configuration) Set(main *Configuration) {
|
func (c Configuration) Set(main *Configuration) {
|
||||||
// ignore error
|
|
||||||
mergo.MergeWithOverwrite(main, c)
|
mergo.MergeWithOverwrite(main, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,7 +198,7 @@ var (
|
||||||
// Note: this is the main's server Host, you can setup unlimited number of net/http servers
|
// Note: this is the main's server Host, you can setup unlimited number of net/http servers
|
||||||
// listening to the $instance.Handler after the manually-called $instance.Build
|
// listening to the $instance.Handler after the manually-called $instance.Build
|
||||||
//
|
//
|
||||||
// Default comes from iris.Default.Listen/.Serve with iris' listeners (iris.TCP4/UNIX/TLS/LETSENCRYPT)
|
// Default comes from iris.Default.Listen/.Serve with iris' listeners (iris.TCP4/UNIX/TLS/LETSENCRYPT).
|
||||||
OptionVHost = func(val string) OptionSet {
|
OptionVHost = func(val string) OptionSet {
|
||||||
return func(c *Configuration) {
|
return func(c *Configuration) {
|
||||||
c.VHost = val
|
c.VHost = val
|
||||||
|
@ -211,22 +208,26 @@ var (
|
||||||
// OptionVScheme is the scheme (http:// or https://) putted at the template function '{{url }}'
|
// OptionVScheme is the scheme (http:// or https://) putted at the template function '{{url }}'
|
||||||
// It's an optional field,
|
// It's an optional field,
|
||||||
// When to set Scheme manually:
|
// When to set Scheme manually:
|
||||||
// 1. You didn't start the main server using $instance.Listen/ListenTLS/ListenLETSENCRYPT or $instance.Serve($instance.TCP4()/.TLS...)
|
// 1. You didn't start the main server using $instance.Listen/ListenTLS/ListenLETSENCRYPT
|
||||||
// 2. if you're using something like nginx and have iris listening with addr only(http://) but the nginx mapper is listening to https://
|
// or $instance.Serve($instance.TCP4()/.TLS...)
|
||||||
|
// 2. if you're using something like nginx and have iris listening with
|
||||||
|
// addr only(http://) but the nginx mapper is listening to https://
|
||||||
//
|
//
|
||||||
// Default comes from iris.Default.Listen/.Serve with iris' listeners (TCP4,UNIX,TLS,LETSENCRYPT)
|
// Default comes from iris.Default.Listen/.Serve with iris' listeners (TCP4,UNIX,TLS,LETSENCRYPT).
|
||||||
OptionVScheme = func(val string) OptionSet {
|
OptionVScheme = func(val string) OptionSet {
|
||||||
return func(c *Configuration) {
|
return func(c *Configuration) {
|
||||||
c.VScheme = val
|
c.VScheme = val
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// maximum duration before timing out read of the request
|
|
||||||
|
// OptionReadTimeout sets the Maximum duration before timing out read of the request.
|
||||||
OptionReadTimeout = func(val time.Duration) OptionSet {
|
OptionReadTimeout = func(val time.Duration) OptionSet {
|
||||||
return func(c *Configuration) {
|
return func(c *Configuration) {
|
||||||
c.ReadTimeout = val
|
c.ReadTimeout = val
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// maximum duration before timing out write of the response
|
|
||||||
|
// OptionWriteTimeout sets the Maximum duration before timing out write of the response.
|
||||||
OptionWriteTimeout = func(val time.Duration) OptionSet {
|
OptionWriteTimeout = func(val time.Duration) OptionSet {
|
||||||
return func(c *Configuration) {
|
return func(c *Configuration) {
|
||||||
c.WriteTimeout = val
|
c.WriteTimeout = val
|
||||||
|
@ -280,31 +281,19 @@ var (
|
||||||
// Usage: iris.Default.Set(iris.OptionCheckForUpdates(true)) or
|
// Usage: iris.Default.Set(iris.OptionCheckForUpdates(true)) or
|
||||||
// iris.Default.Config.CheckForUpdates = true or
|
// iris.Default.Config.CheckForUpdates = true or
|
||||||
// app := iris.New(iris.OptionCheckForUpdates(true))
|
// app := iris.New(iris.OptionCheckForUpdates(true))
|
||||||
// Default is false
|
// Defaults to false.
|
||||||
OptionCheckForUpdates = func(val bool) OptionSet {
|
OptionCheckForUpdates = func(val bool) OptionSet {
|
||||||
return func(c *Configuration) {
|
return func(c *Configuration) {
|
||||||
c.CheckForUpdates = val
|
c.CheckForUpdates = val
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// CheckForUpdatesSync checks for updates before server starts, it will have a little delay depends on the machine's download's speed
|
|
||||||
// See CheckForUpdates for more
|
|
||||||
// Notes:
|
|
||||||
// 1. you could use the CheckForUpdatesSync while CheckForUpdates is false, set this or CheckForUpdates to true not both
|
|
||||||
// 2. if both CheckForUpdates and CheckForUpdatesSync are setted to true then the updater will run in sync mode, before server server starts.
|
|
||||||
//
|
|
||||||
// Default is false
|
|
||||||
OptionCheckForUpdatesSync = func(val bool) OptionSet {
|
|
||||||
return func(c *Configuration) {
|
|
||||||
c.CheckForUpdatesSync = val
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// OptionDisablePathCorrection corrects and redirects the requested path to the registered path
|
// OptionDisablePathCorrection corrects and redirects the requested path to the registered path
|
||||||
// for example, if /home/ path is requested but no handler for this Route found,
|
// for example, if /home/ path is requested but no handler for this Route found,
|
||||||
// then the Router checks if /home handler exists, if yes,
|
// then the Router checks if /home handler exists, if yes,
|
||||||
// (permant)redirects the client to the correct path /home
|
// (permant)redirects the client to the correct path /home
|
||||||
//
|
//
|
||||||
// Default is false
|
// Defaults to false.
|
||||||
OptionDisablePathCorrection = func(val bool) OptionSet {
|
OptionDisablePathCorrection = func(val bool) OptionSet {
|
||||||
return func(c *Configuration) {
|
return func(c *Configuration) {
|
||||||
c.DisablePathCorrection = val
|
c.DisablePathCorrection = val
|
||||||
|
@ -319,17 +308,18 @@ var (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// FireMethodNotAllowed if it's true router checks for StatusMethodNotAllowed(405) and fires the 405 error instead of 404
|
// FireMethodNotAllowed if it's true router checks for StatusMethodNotAllowed(405)
|
||||||
// Default is false
|
// and fires the 405 error instead of 404
|
||||||
|
// Defaults to false.
|
||||||
OptionFireMethodNotAllowed = func(val bool) OptionSet {
|
OptionFireMethodNotAllowed = func(val bool) OptionSet {
|
||||||
return func(c *Configuration) {
|
return func(c *Configuration) {
|
||||||
c.FireMethodNotAllowed = val
|
c.FireMethodNotAllowed = val
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// OptionDisableBanner outputs the iris banner at startup
|
// OptionDisableBanner outputs the iris banner at startup.
|
||||||
//
|
//
|
||||||
// Default is false
|
// Defaults to false.
|
||||||
OptionDisableBanner = func(val bool) OptionSet {
|
OptionDisableBanner = func(val bool) OptionSet {
|
||||||
return func(c *Configuration) {
|
return func(c *Configuration) {
|
||||||
c.DisableBanner = val
|
c.DisableBanner = val
|
||||||
|
@ -349,7 +339,8 @@ var (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// OptionTimeFormat time format for any kind of datetime parsing
|
// OptionTimeFormat time format for any kind of datetime parsing.
|
||||||
|
// Defauls to "Mon, 02 Jan 2006 15:04:05 GMT".
|
||||||
OptionTimeFormat = func(val string) OptionSet {
|
OptionTimeFormat = func(val string) OptionSet {
|
||||||
return func(c *Configuration) {
|
return func(c *Configuration) {
|
||||||
c.TimeFormat = val
|
c.TimeFormat = val
|
||||||
|
@ -358,7 +349,7 @@ var (
|
||||||
|
|
||||||
// OptionCharset character encoding for various rendering
|
// OptionCharset character encoding for various rendering
|
||||||
// used for templates and the rest of the responses
|
// used for templates and the rest of the responses
|
||||||
// Default is "UTF-8"
|
// Defaults to "UTF-8".
|
||||||
OptionCharset = func(val string) OptionSet {
|
OptionCharset = func(val string) OptionSet {
|
||||||
return func(c *Configuration) {
|
return func(c *Configuration) {
|
||||||
c.Charset = val
|
c.Charset = val
|
||||||
|
@ -367,25 +358,23 @@ var (
|
||||||
|
|
||||||
// OptionGzip enables gzip compression on your Render actions, this includes any type of render, templates and pure/raw content
|
// OptionGzip enables gzip compression on your Render actions, this includes any type of render, templates and pure/raw content
|
||||||
// If you don't want to enable it globally, you could just use the third parameter on context.Render("myfileOrResponse", structBinding{}, iris.RenderOptions{"gzip": true})
|
// If you don't want to enable it globally, you could just use the third parameter on context.Render("myfileOrResponse", structBinding{}, iris.RenderOptions{"gzip": true})
|
||||||
// Default is false
|
// Defaults to false.
|
||||||
OptionGzip = func(val bool) OptionSet {
|
OptionGzip = func(val bool) OptionSet {
|
||||||
return func(c *Configuration) {
|
return func(c *Configuration) {
|
||||||
c.Gzip = val
|
c.Gzip = val
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// OptionOther are the custom, dynamic options, can be empty
|
// Other are the custom, dynamic options, can be empty.
|
||||||
// this fill used only by you to set any app's options you want
|
// This field used only by you to set any app's options you want
|
||||||
// for each of an Iris instance
|
// or by custom adaptors, it's a way to simple communicate between your adaptors (if any)
|
||||||
OptionOther = func(val ...options.Options) OptionSet {
|
// Defaults to a non-nil empty map.
|
||||||
opts := options.Options{}
|
OptionOther = func(key string, val interface{}) OptionSet {
|
||||||
for _, opt := range val {
|
|
||||||
for k, v := range opt {
|
|
||||||
opts[k] = v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return func(c *Configuration) {
|
return func(c *Configuration) {
|
||||||
c.Other = opts
|
if c.Other == nil {
|
||||||
|
c.Other = make(map[string]interface{}, 0)
|
||||||
|
}
|
||||||
|
c.Other[key] = val
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -418,15 +407,14 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
// DefaultConfiguration returns the default configuration for an Iris station, fills the main Configuration
|
// DefaultConfiguration returns the default configuration for an Iris station, fills the main Configuration
|
||||||
func DefaultConfiguration() Configuration {
|
func DefaultConfiguration() *Configuration {
|
||||||
return Configuration{
|
return &Configuration{
|
||||||
VHost: "",
|
VHost: "",
|
||||||
VScheme: "",
|
VScheme: "",
|
||||||
ReadTimeout: DefaultReadTimeout,
|
ReadTimeout: DefaultReadTimeout,
|
||||||
WriteTimeout: DefaultWriteTimeout,
|
WriteTimeout: DefaultWriteTimeout,
|
||||||
MaxHeaderBytes: DefaultMaxHeaderBytes,
|
MaxHeaderBytes: DefaultMaxHeaderBytes,
|
||||||
CheckForUpdates: false,
|
CheckForUpdates: false,
|
||||||
CheckForUpdatesSync: false,
|
|
||||||
DisablePathCorrection: DefaultDisablePathCorrection,
|
DisablePathCorrection: DefaultDisablePathCorrection,
|
||||||
EnablePathEscape: DefaultEnablePathEscape,
|
EnablePathEscape: DefaultEnablePathEscape,
|
||||||
FireMethodNotAllowed: false,
|
FireMethodNotAllowed: false,
|
||||||
|
@ -435,7 +423,7 @@ func DefaultConfiguration() Configuration {
|
||||||
TimeFormat: DefaultTimeFormat,
|
TimeFormat: DefaultTimeFormat,
|
||||||
Charset: DefaultCharset,
|
Charset: DefaultCharset,
|
||||||
Gzip: false,
|
Gzip: false,
|
||||||
Other: options.Options{},
|
Other: make(map[string]interface{}, 0),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
26
iris.go
26
iris.go
|
@ -92,8 +92,7 @@ func DevLogger() LoggerPolicy {
|
||||||
// New creates and returns a fresh Iris *Framework instance
|
// New creates and returns a fresh Iris *Framework instance
|
||||||
// with the default configuration if no 'setters' parameters passed.
|
// with the default configuration if no 'setters' parameters passed.
|
||||||
func New(setters ...OptionSetter) *Framework {
|
func New(setters ...OptionSetter) *Framework {
|
||||||
s := &Framework{}
|
s := &Framework{Config: DefaultConfiguration()}
|
||||||
|
|
||||||
// +------------------------------------------------------------+
|
// +------------------------------------------------------------+
|
||||||
// | Set the config passed from setters |
|
// | Set the config passed from setters |
|
||||||
// | or use the default one |
|
// | or use the default one |
|
||||||
|
@ -176,8 +175,9 @@ func New(setters ...OptionSetter) *Framework {
|
||||||
{
|
{
|
||||||
// +------------------------------------------------------------+
|
// +------------------------------------------------------------+
|
||||||
// | Module Name: Rich Content-Type Renderer |
|
// | Module Name: Rich Content-Type Renderer |
|
||||||
// | On Init: Attach a new empty content-type serializers |
|
// | On Init: Attach a new empty content-type serializers. |
|
||||||
// | On Build: register the default serializers + the user's |
|
// | Adapt one RenderPolicy which is responsible |
|
||||||
|
// | for json,jsonp,xml and markdown rendering |
|
||||||
// +------------------------------------------------------------+
|
// +------------------------------------------------------------+
|
||||||
|
|
||||||
// prepare the serializers,
|
// prepare the serializers,
|
||||||
|
@ -219,16 +219,13 @@ func New(setters ...OptionSetter) *Framework {
|
||||||
{
|
{
|
||||||
// +------------------------------------------------------------+
|
// +------------------------------------------------------------+
|
||||||
// | Module Name: Template engine's funcs |
|
// | Module Name: Template engine's funcs |
|
||||||
// | On Init: Use the template mux builder to |
|
// | On Init: Adapt the reverse routing tmpl funcs |
|
||||||
// | adapt the reverse routing tmpl funcs |
|
|
||||||
// | for any template engine that will be registered |
|
// | for any template engine that will be registered |
|
||||||
// +------------------------------------------------------------+
|
// +------------------------------------------------------------+
|
||||||
s.Adapt(TemplateFuncsPolicy{
|
s.Adapt(TemplateFuncsPolicy{
|
||||||
"url": s.URL,
|
"url": s.URL,
|
||||||
"urlpath": s.policies.RouterReversionPolicy.URLPath,
|
"urlpath": s.policies.RouterReversionPolicy.URLPath,
|
||||||
})
|
}) // the entire template registration logic lives inside the ./adaptors/view now.
|
||||||
|
|
||||||
// the entire template registration logic lives inside the ./adaptors/template now.
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -286,14 +283,12 @@ func New(setters ...OptionSetter) *Framework {
|
||||||
{
|
{
|
||||||
// +------------------------------------------------------------+
|
// +------------------------------------------------------------+
|
||||||
// | Module Name: System |
|
// | Module Name: System |
|
||||||
// | On Build: Check for updates on Build |
|
// | On Build: Check for updates on Build, async |
|
||||||
// +------------------------------------------------------------+
|
// +------------------------------------------------------------+
|
||||||
|
|
||||||
// On Build: local repository updates
|
// On Build: local repository updates
|
||||||
s.Adapt(EventPolicy{Build: func(*Framework) {
|
s.Adapt(EventPolicy{Build: func(*Framework) {
|
||||||
if s.Config.CheckForUpdatesSync {
|
if s.Config.CheckForUpdates {
|
||||||
s.CheckForUpdates(false)
|
|
||||||
} else if s.Config.CheckForUpdates {
|
|
||||||
go s.CheckForUpdates(false)
|
go s.CheckForUpdates(false)
|
||||||
}
|
}
|
||||||
}})
|
}})
|
||||||
|
@ -304,11 +299,6 @@ func New(setters ...OptionSetter) *Framework {
|
||||||
|
|
||||||
// Set sets an option, configuration field to its Config
|
// Set sets an option, configuration field to its Config
|
||||||
func (s *Framework) Set(setters ...OptionSetter) {
|
func (s *Framework) Set(setters ...OptionSetter) {
|
||||||
if s.Config == nil {
|
|
||||||
defaultConfiguration := DefaultConfiguration()
|
|
||||||
s.Config = &defaultConfiguration
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, setter := range setters {
|
for _, setter := range setters {
|
||||||
setter.Set(s.Config)
|
setter.Set(s.Config)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user