godoc: ConfigurationReadOnly: comment to just a reference of the field

Former-commit-id: b0b74e892d5bdf05dc4c2897c6e0ec3d3747ad49
This commit is contained in:
Gerasimos (Makis) Maropoulos 2020-06-11 16:27:38 +03:00
parent d304086c32
commit 12e61f4456
2 changed files with 58 additions and 205 deletions

View File

@ -397,6 +397,7 @@ func WithRemoteAddrPrivateSubnet(startIP, endIP string) Configurator {
// WithSSLProxyHeader sets a SSLProxyHeaders key value pair. // WithSSLProxyHeader sets a SSLProxyHeaders key value pair.
// Example: WithSSLProxyHeader("X-Forwarded-Proto", "https"). // Example: WithSSLProxyHeader("X-Forwarded-Proto", "https").
// See `Context.IsSSL` for more.
func WithSSLProxyHeader(headerKey, headerValue string) Configurator { func WithSSLProxyHeader(headerKey, headerValue string) Configurator {
return func(app *Application) { return func(app *Application) {
if app.config.SSLProxyHeaders == nil { if app.config.SSLProxyHeaders == nil {
@ -1004,174 +1005,111 @@ type Configuration struct {
var _ context.ConfigurationReadOnly = &Configuration{} var _ context.ConfigurationReadOnly = &Configuration{}
// GetVHost returns the non-exported vhost config field. // 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 (c Configuration) GetVHost() string { func (c Configuration) GetVHost() string {
return c.vhost return c.vhost
} }
// GetLogLevel returns the `Configuration.LogLevel` field. // GetLogLevel returns the LogLevel field.
// The same (as `golog.LogLevel`) can be retrieved through `app.Logger().Level`.
func (c Configuration) GetLogLevel() string { func (c Configuration) GetLogLevel() string {
return c.vhost return c.vhost
} }
// GetDisablePathCorrection returns the Configuration#DisablePathCorrection. // GetDisablePathCorrection returns the DisablePathCorrection field.
// DisablePathCorrection disables the correcting
// and redirecting or executing directly the handler of
// 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,
// (permanent)redirects the client to the correct path /home.
func (c Configuration) GetDisablePathCorrection() bool { func (c Configuration) GetDisablePathCorrection() bool {
return c.DisablePathCorrection return c.DisablePathCorrection
} }
// GetDisablePathCorrectionRedirection returns the Configuration.DisablePathCorrectionRedirection field. // GetDisablePathCorrectionRedirection returns the DisablePathCorrectionRedirection field.
// If DisablePathCorrectionRedirection set to true then it will fire the handler of the matching route without
// the last slash ("/") instead of send a redirection status.
func (c Configuration) GetDisablePathCorrectionRedirection() bool { func (c Configuration) GetDisablePathCorrectionRedirection() bool {
return c.DisablePathCorrectionRedirection return c.DisablePathCorrectionRedirection
} }
// GetEnablePathIntelligence returns the Configuration.EnablePathIntelligence field. // GetEnablePathIntelligence returns the EnablePathIntelligence field.
func (c Configuration) GetEnablePathIntelligence() bool { func (c Configuration) GetEnablePathIntelligence() bool {
return c.EnablePathIntelligence return c.EnablePathIntelligence
} }
// GetEnablePathEscape is the Configuration.EnablePathEscape, // GetEnablePathEscape returns the EnablePathEscape field.
// returns true when its escapes the path, the named parameters (if any).
func (c Configuration) GetEnablePathEscape() bool { func (c Configuration) GetEnablePathEscape() bool {
return c.EnablePathEscape return c.EnablePathEscape
} }
// GetForceLowercaseRouting returns the value of the Configuration.ForceLowercaseRouting setting. // GetForceLowercaseRouting returns the ForceLowercaseRouting field.
func (c Configuration) GetForceLowercaseRouting() bool { func (c Configuration) GetForceLowercaseRouting() bool {
return c.ForceLowercaseRouting return c.ForceLowercaseRouting
} }
// GetFireMethodNotAllowed returns the Configuration.FireMethodNotAllowed. // GetFireMethodNotAllowed returns the FireMethodNotAllowed field.
func (c Configuration) GetFireMethodNotAllowed() bool { func (c Configuration) GetFireMethodNotAllowed() bool {
return c.FireMethodNotAllowed return c.FireMethodNotAllowed
} }
// GetEnableOptimizations returns whether // GetEnableOptimizations returns the EnableOptimizations.
// the application has performance optimizations enabled.
func (c Configuration) GetEnableOptimizations() bool { func (c Configuration) GetEnableOptimizations() bool {
return c.EnableOptimizations return c.EnableOptimizations
} }
// GetDisableBodyConsumptionOnUnmarshal returns the Configuration#GetDisableBodyConsumptionOnUnmarshal, // GetDisableBodyConsumptionOnUnmarshal returns the DisableBodyConsumptionOnUnmarshal field.
// 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 (c Configuration) GetDisableBodyConsumptionOnUnmarshal() bool { func (c Configuration) GetDisableBodyConsumptionOnUnmarshal() bool {
return c.DisableBodyConsumptionOnUnmarshal return c.DisableBodyConsumptionOnUnmarshal
} }
// GetFireEmptyFormError returns the Configuration.FireEmptyFormError value. // GetFireEmptyFormError returns the DisableBodyConsumptionOnUnmarshal field.
// If true then the `context.ReadBody/ReadForm` will return an `iris.ErrEmptyForm`
// on empty request form data.
func (c Configuration) GetFireEmptyFormError() bool { func (c Configuration) GetFireEmptyFormError() bool {
return c.DisableBodyConsumptionOnUnmarshal return c.FireEmptyFormError
} }
// GetDisableAutoFireStatusCode returns the Configuration.DisableAutoFireStatusCode. // GetDisableAutoFireStatusCode returns the DisableAutoFireStatusCode field.
// Returns true when the http error status code handler automatic execution turned off.
func (c Configuration) GetDisableAutoFireStatusCode() bool { func (c Configuration) GetDisableAutoFireStatusCode() bool {
return c.DisableAutoFireStatusCode return c.DisableAutoFireStatusCode
} }
// GetResetOnFireErrorCode returns the Configuration.ResetOnFireErrorCode. // GetResetOnFireErrorCode returns ResetOnFireErrorCode field.
// Returns true when the router should not respect the handler's error response and
// fire the registered error handler instead.
//
// See https://github.com/kataras/iris/issues/1531
func (c Configuration) GetResetOnFireErrorCode() bool { func (c Configuration) GetResetOnFireErrorCode() bool {
return c.ResetOnFireErrorCode return c.ResetOnFireErrorCode
} }
// GetTimeFormat returns the Configuration.TimeFormat, // GetTimeFormat returns the TimeFormat field.
// format for any kind of datetime parsing.
func (c Configuration) GetTimeFormat() string { func (c Configuration) GetTimeFormat() string {
return c.TimeFormat return c.TimeFormat
} }
// GetCharset returns the Configuration.Charset, // GetCharset returns the Charset field.
// the character encoding for various rendering
// used for templates and the rest of the responses.
func (c Configuration) GetCharset() string { func (c Configuration) GetCharset() string {
return c.Charset return c.Charset
} }
// GetPostMaxMemory returns the maximum configured post data size // GetPostMaxMemory returns the PostMaxMemory field.
// that a client can send to the server, this differs
// from the overral request body size which can be modified
// by the `context#SetMaxRequestBodySize` or `iris#LimitRequestBodySize`.
//
// Defaults to 32MB or 32 << 20 if you prefer.
func (c Configuration) GetPostMaxMemory() int64 { func (c Configuration) GetPostMaxMemory() int64 {
return c.PostMaxMemory return c.PostMaxMemory
} }
// GetLocaleContextKey returns the configuration's LocaleContextKey value, // GetLocaleContextKey returns the LocaleContextKey field.
// used for i18n.
func (c Configuration) GetLocaleContextKey() string { func (c Configuration) GetLocaleContextKey() string {
return c.LocaleContextKey return c.LocaleContextKey
} }
// GetLanguageContextKey returns the configuration's LanguageContextKey value, // GetLanguageContextKey returns the LanguageContextKey field.
// used for i18n.
func (c Configuration) GetLanguageContextKey() string { func (c Configuration) GetLanguageContextKey() string {
return c.LanguageContextKey return c.LanguageContextKey
} }
// GetVersionContextKey returns the configuration's VersionContextKey value, // GetVersionContextKey returns the VersionContextKey field.
// used for API Versioning.
func (c Configuration) GetVersionContextKey() string { func (c Configuration) GetVersionContextKey() string {
return c.VersionContextKey return c.VersionContextKey
} }
// GetViewLayoutContextKey returns the key of the context's user values' key // GetViewLayoutContextKey returns the ViewLayoutContextKey field.
// 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 (c Configuration) GetViewLayoutContextKey() string { func (c Configuration) GetViewLayoutContextKey() string {
return c.ViewLayoutContextKey return c.ViewLayoutContextKey
} }
// GetViewDataContextKey returns the key of the context's user values' key // GetViewDataContextKey returns the ViewDataContextKey field.
// which is being used to set the template
// binding data from a middleware or the main handler.
func (c Configuration) GetViewDataContextKey() string { func (c Configuration) GetViewDataContextKey() string {
return c.ViewDataContextKey return c.ViewDataContextKey
} }
// GetRemoteAddrHeaders returns the allowed request headers names // GetRemoteAddrHeaders returns the RemoteAddrHeaders field.
// that can be valid to parse the client's IP based on.
// By-default no "X-" header is consired safe to be used for retrieving the
// client's IP address, because those headers can manually change by
// the client. But sometimes are useful e.g., when behind a proxy
// you want to enable the "X-Forwarded-For" or when cloudflare
// you want to enable the "CF-Connecting-IP", inneed you
// can allow the `ctx.RemoteAddr()` to use any header
// that the client may sent.
//
// Defaults to an empty map but an example usage is:
// RemoteAddrHeaders {
// "X-Real-Ip": true,
// "X-Forwarded-For": true,
// "CF-Connecting-IP": true,
// }
//
// Look `context.RemoteAddr()` for more.
func (c Configuration) GetRemoteAddrHeaders() map[string]bool { func (c Configuration) GetRemoteAddrHeaders() map[string]bool {
return c.RemoteAddrHeaders return c.RemoteAddrHeaders
} }
@ -1181,42 +1119,12 @@ func (c Configuration) GetSSLProxyHeaders() map[string]string {
return c.SSLProxyHeaders return c.SSLProxyHeaders
} }
// GetRemoteAddrPrivateSubnets returns the configuration's private sub-networks. // GetRemoteAddrPrivateSubnets returns the RemoteAddrPrivateSubnets field.
// They are used to be compared against
// IP Addresses fetched through `RemoteAddrHeaders` or `Request.RemoteAddr`.
// For details please navigate through: https://github.com/kataras/iris/issues/1453
// Defaults to:
// {
// Start: net.ParseIP("10.0.0.0"),
// End: net.ParseIP("10.255.255.255"),
// },
// {
// Start: net.ParseIP("100.64.0.0"),
// End: net.ParseIP("100.127.255.255"),
// },
// {
// Start: net.ParseIP("172.16.0.0"),
// End: net.ParseIP("172.31.255.255"),
// },
// {
// Start: net.ParseIP("192.0.0.0"),
// End: net.ParseIP("192.0.0.255"),
// },
// {
// Start: net.ParseIP("192.168.0.0"),
// End: net.ParseIP("192.168.255.255"),
// },
// {
// Start: net.ParseIP("198.18.0.0"),
// End: net.ParseIP("198.19.255.255"),
// }
//
// Look `context.RemoteAddr()` for more.
func (c Configuration) GetRemoteAddrPrivateSubnets() []netutil.IPRange { func (c Configuration) GetRemoteAddrPrivateSubnets() []netutil.IPRange {
return c.RemoteAddrPrivateSubnets return c.RemoteAddrPrivateSubnets
} }
// GetOther returns the Configuration#Other map. // GetOther returns the Other field.
func (c Configuration) GetOther() map[string]interface{} { func (c Configuration) GetOther() map[string]interface{} {
return c.Other return c.Other
} }
@ -1342,6 +1250,15 @@ func WithConfiguration(c Configuration) Configurator {
main.RemoteAddrPrivateSubnets = v main.RemoteAddrPrivateSubnets = v
} }
if v := c.SSLProxyHeaders; len(v) > 0 {
if main.SSLProxyHeaders == nil {
main.SSLProxyHeaders = make(map[string]string, len(v))
}
for key, value := range v {
main.SSLProxyHeaders[key] = value
}
}
if v := c.Other; len(v) > 0 { if v := c.Other; len(v) > 0 {
if main.Other == nil { if main.Other == nil {
main.Other = make(map[string]interface{}, len(v)) main.Other = make(map[string]interface{}, len(v))

View File

@ -9,122 +9,58 @@ import "github.com/kataras/iris/v12/core/netutil"
// safe or its useless to be called from a request handler. // safe or its useless to be called from a request handler.
type ConfigurationReadOnly interface { type ConfigurationReadOnly interface {
// GetVHost returns the non-exported vhost config field. // 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.
GetVHost() string GetVHost() string
// GetLogLevel returns the LogLevel field.
// GetLogLevel returns the `Configuration.LogLevel` field.
// The same (as `golog.LogLevel`) can be retrieved through `app.Logger().Level`.
GetLogLevel() string GetLogLevel() string
// GetDisablePathCorrection returns the DisablePathCorrection field
// 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.
GetDisablePathCorrection() bool GetDisablePathCorrection() bool
// GetDisablePathCorrectionRedirection returns the Configuration.DisablePathCorrectionRedirection field. // GetDisablePathCorrectionRedirection returns the DisablePathCorrectionRedirection field.
// If DisablePathCorrectionRedirection set to true then it will handle paths as they are.
// it will fire the handler of the matching route without
// the last slash ("/") instead of send a redirection status.
GetDisablePathCorrectionRedirection() bool GetDisablePathCorrectionRedirection() bool
// GetEnablePathIntelligence returns the Configuration.EnablePathIntelligence field. // GetEnablePathIntelligence returns the EnablePathIntelligence field.
GetEnablePathIntelligence() bool GetEnablePathIntelligence() bool
// GetEnablePathEscape is the configuration.EnablePathEscape, // GetEnablePathEscape returns the EnablePathEscape field.
// returns true when its escapes the path, the named parameters (if any).
GetEnablePathEscape() bool GetEnablePathEscape() bool
// GetForceLowercaseRouting returns the value of the `ForceLowercaseRouting` setting. // GetForceLowercaseRouting returns the ForceLowercaseRouting field.
GetForceLowercaseRouting() bool GetForceLowercaseRouting() bool
// GetFireMethodNotAllowed returns the configuration.FireMethodNotAllowed. // GetFireMethodNotAllowed returns the FireMethodNotAllowed field.
GetFireMethodNotAllowed() bool GetFireMethodNotAllowed() bool
// GetDisableAutoFireStatusCode returns the configuration.DisableAutoFireStatusCode. // GetDisableAutoFireStatusCode returns the DisableAutoFireStatusCode field.
// Returns true when the http error status code handler automatic execution turned off.
GetDisableAutoFireStatusCode() bool GetDisableAutoFireStatusCode() bool
// ResetOnFireErrorCode if true then any previously response body or headers through // ResetOnFireErrorCode retruns the ResetOnFireErrorCode field.
// response recorder or gzip writer will be ignored and the router
// will fire the registered (or default) HTTP error handler instead.
// See `core/router/handler#FireErrorCode` and `Context.EndRequest` for more details.
//
// Read more at: https://github.com/kataras/iris/issues/1531
//
// Defaults to false.
GetResetOnFireErrorCode() bool GetResetOnFireErrorCode() bool
// GetEnableOptimizations returns whether // GetEnableOptimizations returns the EnableOptimizations field.
// the application has performance optimizations enabled.
GetEnableOptimizations() bool GetEnableOptimizations() bool
// GetDisableBodyConsumptionOnUnmarshal returns the configuration.GetDisableBodyConsumptionOnUnmarshal, // GetDisableBodyConsumptionOnUnmarshal returns the DisableBodyConsumptionOnUnmarshal field.
// 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.
GetDisableBodyConsumptionOnUnmarshal() bool GetDisableBodyConsumptionOnUnmarshal() bool
// GetFireEmptyFormError returns the Configuration.FireEmptyFormError value. // GetFireEmptyFormError returns the FireEmptyFormError field.
// If true then the `context.ReadBody/ReadForm` will return an `iris.ErrEmptyForm`
// on empty request form data.
GetFireEmptyFormError() bool GetFireEmptyFormError() bool
// GetTimeFormat returns the configuration.TimeFormat, // GetTimeFormat returns the TimeFormat field.
// format for any kind of datetime parsing.
GetTimeFormat() string GetTimeFormat() string
// GetCharset returns the Charset field.
// GetCharset returns the configuration.Charset,
// the character encoding for various rendering
// used for templates and the rest of the responses.
GetCharset() string GetCharset() string
// GetPostMaxMemory returns the PostMaxMemory field.
// GetPostMaxMemory returns the maximum configured post data size
// that a client can send to the server, this differs
// from the overral request body size which can be modified
// by the `context#SetMaxRequestBodySize` or `iris#LimitRequestBodySize`.
//
// Defaults to 32MB or 32 << 20 if you prefer.
GetPostMaxMemory() int64 GetPostMaxMemory() int64
// GetTranslateLanguageContextKey returns the configuration's LocaleContextKey value, // GetTranslateLanguageContextKey returns the LocaleContextKey field.
// used for i18n. Defaults to "iris.locale".
GetLocaleContextKey() string GetLocaleContextKey() string
// GetLanguageContextKey returns the configuration's LanguageContextKey value, // GetLanguageContextKey returns the LanguageContextKey field.
// used for i18n. Defaults to "iris.locale.language".
GetLanguageContextKey() string GetLanguageContextKey() string
// GetVersionContextKey returns the configuration's VersionKey value, // GetVersionContextKey returns the VersionContextKey field.
// used for API Versioning. Defaults to "iris.api.version".
GetVersionContextKey() string GetVersionContextKey() string
// GetViewLayoutContextKey returns the key of the context's user values' key // GetViewLayoutContextKey returns the ViewLayoutContextKey field.
// which is being used to set the template
// layout from a middleware or the main handler.
// Overrides the parent's or the configuration's.
GetViewLayoutContextKey() string GetViewLayoutContextKey() string
// GetViewDataContextKey returns the key of the context's user values' key // GetViewDataContextKey returns the ViewDataContextKey field.
// which is being used to set the template
// binding data from a middleware or the main handler.
GetViewDataContextKey() string GetViewDataContextKey() string
// GetRemoteAddrHeaders returns the allowed request headers names // GetRemoteAddrHeaders returns RemoteAddrHeaders field.
// that can be valid to parse the client's IP based on.
//
// Defaults to:
// "X-Real-Ip": true,
// "X-Forwarded-For": true,
// "CF-Connecting-IP": false
//
// Look `context.RemoteAddr()` for more.
GetRemoteAddrHeaders() map[string]bool GetRemoteAddrHeaders() map[string]bool
// GetRemoteAddrPrivateSubnets returns the configuration's private sub-networks. // GetRemoteAddrPrivateSubnets returns the RemoteAddrPrivateSubnets field.
// They are used to be compared against
// IP Addresses fetched through `RemoteAddrHeaders` or `Request.RemoteAddr`.
// For details please navigate through: https://github.com/kataras/iris/issues/1453
//
// Look `context.RemoteAddr()` for more.
GetRemoteAddrPrivateSubnets() []netutil.IPRange GetRemoteAddrPrivateSubnets() []netutil.IPRange
// GetSSLProxyHeaders returns the SSLProxyHeaders field. // GetSSLProxyHeaders returns the SSLProxyHeaders field.
GetSSLProxyHeaders() map[string]string GetSSLProxyHeaders() map[string]string
// GetOther returns the configuration.Other map.
// GetOther returns the Other field.
GetOther() map[string]interface{} GetOther() map[string]interface{}
} }