Beego parameter configuration

Configuration parameters

beego currently supports INI, XML, JSON, YAML format configuration file parsing, but defaults to the INI format resolution, users can can get a lot of flexibility through a simple configuration.
The default configuration parsing

beego default conf resolved under the current application / app.conf file.

With this file you can initialize a lot beego default parameters:

appname = beepkg
httpaddr = “127.0.0.1”
httpport = 9090
runmode =”dev”
autorender = false
recoverpanic = false
viewspath = “myview”

These parameters will replace beego above the default parameters, parameter beego mainly, what does? Please refer to https://godoc.org/github.com/astaxie/beego#pkg-constants.
BConfig is the default configuration beego inside, you can also directly beego.BConfig.AppName = "beepkg" so be modified by, and the same effect as the above configuration, but died in a written code inside,
and the profile will be even more flexible.

You can also configure the application needs to use some configuration information in the configuration file, the database information shown in the following example:

mysqluser = “root”
mysqlpass = “rootpass”
mysqlurls = “127.0.0.1”
mysqldb = “beego”

Then you can obtain configuration information set by the following ways:

beego.AppConfig.String ( "mysqluser")
beego.AppConfig.String ( "mysqlpass")
beego.AppConfig.String ( "mysqlurls")
beego.AppConfig.String ( "mysqldb")

AppConfig method is as follows:

Set(key, val string) error
String(key string) string
Strings(key string) []string
Int(key string) (int, error)
Int64(key string) (int64, error)
Bool(key string) (bool, error)
Float(key string) (float64, error)
DefaultString(key string, defaultVal string) string
DefaultStrings(key string, defaultVal []string)
DefaultInt(key string, defaultVal int) int
DefaultInt64(key string, defaultVal int64) int64
DefaultBool(key string, defaultVal bool) bool
DefaultFloat(key string, defaultVal float64) float64
DIY(key string) (interface{}, error)
GetSection(section string) (map[string]string, error)
SaveConfigFile(filename string) error

 

In use ini type of profile, key support section :: key mode.

You can return to the default values Default * methods
different levels of configuration

In the configuration file which supports sectionTop, Runmode can have different configurations, the default priority under RunMode read configuration information, for example the following profiles:

appname = beepkg
httpaddr = “127.0.0.1”
httpport = 9090
runmode =”dev”
autorender = false
recoverpanic = false
viewspath = “myview”

[dev]
httpport = 8080
[prod]
httpport = 8088
[test]
httpport = 8888

The above analytical profile is different at different RunMode arranged, for example in the dev mode, the httpport 8080, 8088 in prod mode is 8888. Likewise other profiles in the test mode. Priority to resolve when parsing the configuration under runmode, and then parse the default configuration.

Different methods reading mode configuration parameter is "mode configuration parameter name ::", for example: beego.AppConfig.String ( "dev :: mysqluser").

For custom parameters, use beego.GetConfig (tpy, key string, defaultVal interface {}) to obtain the configuration (1.4.0 or later required) in the specified runmode, typ parameter type, key is the parameter name, defaultVal of Defaults.
Multiple profiles

INI format configuration supports include manner, a plurality of reference profiles, for example, the following two effects above configuration files:

app.conf

appname = beepkg
httpaddr = “127.0.0.1”
httpport = 9090

include “app2.conf”

app2.conf

runmode =”dev”
autorender = false
recoverpanic = false
viewspath = “myview”

[dev]
httpport = 8080
[prod]
httpport = 8088
[test]
httpport = 8888

The default parameters

beego in with lots of configurable parameters, one by one we know about them, this will help us can fully play their role in the development of the next beego (you can set the conf / app.conf corresponding value, case insensitive):
basic configuration

BConfig
save all beego inside the system default parameters, you can access and modify all the configuration information under through beego.BConfig.

Profile path, the default is the application corresponding to the conf directory / app.conf, the user can load his own profile in the program code
beego.LoadAppConfig ( "ini", "conf / app2.conf")
may also be loaded multiple files, as long as you call it many times, and if the file in front of the back of the key conflict, then loaded with the latest value of the latest

App Configuration

AppName

Application name, the default is beego. Created by bee new project name is created.

beego.BConfig.AppName = "beego"

RunMode

Applications operating mode is selectable prod, dev or Test. Dev default, mode of development, in the development model error prompts friendly error page, as described above in the description of the error.

beego.BConfig.RunMode = "dev"

RouterCaseSensitive

Ignore case whether the route matches, the default is true, case sensitive

beego.BConfig.RouterCaseSensitive = true

ServerName

beego server to server beego default output at the time of the request.

beego.BConfig.ServerName = "beego"

RecoverPanic

Recovery is abnormal, the default value is true, which occurs when abnormal application, resume back through the recover, but will not cause the application to quit unexpectedly.

beego.BConfig.RecoverPanic = true

CopyRequestBody

When the HTTP request is allowed to return to the original body of data bytes requested, the default is true (except GET or HEAD or upload request).

beego.BConfig.CopyRequestBody = false

EnableGzip

Gzip support is turned on, the default is false does not support gzip, gzip once opened, then the contents of the template output will be gzip or zlib compression to determine the user's Accept-Encoding.

beego.BConfig.EnableGzip = false

Gzip allows users to customize the level of compression, the compression threshold and compression length for the request type:

Compression level, gzipCompressLevel = 9, range 1 to 9, if not set to 1 (fastest compression)

Compression length threshold, gzipMinLength = 256, only when the length of the original content compression greater than this threshold turn, default 20B (ngnix default length)

Request type, includedMethods = get; post, compression type for which a request, only for the default compression GET request

MaxMemory

File upload default memory cache size, the default is 1 << 26 (64M).

beego.BConfig.MaxMemory = 1 << 26

EnableErrorsShow

Whether to display the system error message, the default is true.

beego.BConfig.EnableErrorsShow = true


Web Configuration

AutoRender

Whether template automatic rendering, the default value is true, the type of application for the API, the application needs this option is set to false, no rendering template.

beego.BConfig.WebConfig.AutoRender = true

EnableDocs

Whether to open the document built-in functions, the default is false

beego.BConfig.WebConfig.EnableDocs = true

FlashName

When Flash Cookie data set name, the default is BEEGO_FLASH

beego.BConfig.WebConfig.FlashName = "BEEGO_FLASH"

FlashSeperator

Flash data delimiters, the default is BEEGOFLASH

beego.BConfig.WebConfig.FlashSeperator = "BEEGOFLASH"

DirectoryIndex

Whether to open a static directory list shows the default does not display the directory returns a 403 error.

beego.BConfig.WebConfig.DirectoryIndex = false

StaticDir

Static files directory settings, the default is static

You can configure a single or multiple directories:

Single directory, StaticDir = download. Corresponds beego.SetStaticPath ( "/ download", "download")

A plurality of directories, StaticDir = download: down download2:. Down2 corresponds beego.SetStaticPath ( "/ download", "down") and beego.SetStaticPath ( "/ download2", "down2")

beego.BConfig.WebConfig.StaticDir

StaticExtensionsToGzip

What static file name suffix allows for gzip compression, default support .css and .js

beego.BConfig.WebConfig.StaticExtensionsToGzip = []string{".css", ".js"}

Equivalent config file

StaticExtensionsToGzip = .css, .js

TemplateLeft

Left label template, the default is {{.

beego.BConfig.WebConfig.TemplateLeft="{{"

TemplateRight

Right label templates, default is}}.

beego.BConfig.WebConfig.TemplateRight="}}"

ViewsPath

Template path, the default is views.

beego.BConfig.WebConfig.ViewsPath="views"

EnableXSRF

Whether to open XSRF, default is false, do not open.

beego.BConfig.WebConfig.EnableXSRF = false

XSRFKEY

XSRF of key information, the default value is beegoxsrf. EnableXSRF = true to be effective

beego.BConfig.WebConfig.XSRFKEY = "beegoxsrf"

XSRFExpire

XSRF expiration time, the default value is 0, but period.

beego.BConfig.WebConfig.XSRFExpire = 0



Monitor configuration

Graceful

Whether to open the hot upgrade, the default is false, turn off the heat to upgrade.

beego.BConfig.Listen.Graceful=false

ServerTimeOut

Set HTTP timeout, the default is 0, no timeout.

beego.BConfig.Listen.ServerTimeOut=0

ListenTCP4

Monitor local network address type, the default is "tcp4", the value can be "tcp", one of "unixpacket" "tcp4", "tcp6", "unix" or.

beego.BConfig.Listen.ListenTCP4 = "tcp4"

EnableHTTP

HTTP listener is enabled, the default is true.

beego.BConfig.Listen.EnableHTTP = true

HTTPAddr

Applications listen address, empty by default, listens on all network card IP.

beego.BConfig.Listen.HTTPAddr = ""

HTTPPort

Application listening port, default to 8080.

beego.BConfig.Listen.HTTPPort = 8080

EnableHTTPS

Whether to enable HTTPS, the default is false closed. When the need to enable, to set EnableHTTPS = true, and set HTTPSCertFile and HTTPSKeyFile

beego.BConfig.Listen.EnableHTTPS = false

HTTPSAddr

Applications listen address, empty by default, listens on all network card IP.

beego.BConfig.Listen.HTTPSAddr = ""

HTTPSPort

Application listening port, default is 10443

beego.BConfig.Listen.HTTPSPort = 10443

HTTPSCertFile

When you turn on HTTPS, ssl certification path, the default is empty.

beego.BConfig.Listen.HTTPSCertFile = "conf/ssl.crt"

HTTPSKeyFile

After turning HTTPS, SSL certificate keyfile path.

beego.BConfig.Listen.HTTPSKeyFile = "conf/ssl.key"

EnableAdmin

Whether to open an in-process monitoring module, default false closed.

beego.BConfig.Listen.AdminEnable = false

Adminaddra

Monitor monitor address, the default value is localhost.

beego.BConfig.Listen.AdminAddr = "localhost"

AdminPort


Monitor monitor address, the default value is 8088.

beego.BConfig.Listen.AdminPort = 8088

EnableFcgi

Whether to enable fastcgi, the default is false.

beego.BConfig.Listen.EnableFcgi = false

EnableStdIo

By fastcgi standard I / O, after the entry into force of fastcgi enabled, default false.

beego.BConfig.Listen.EnableStdIo = false


Session Configuration

SessionOn

Whether the session open, the default is false.

beego.BConfig.WebConfig.Session.SessionOn = false

SessionProvider

session of the engine, the default is memory, see the session module in detail.

beego.BConfig.WebConfig.Session.SessionProvider = ""

SessionName

The presence of the client's cookie name, the default value is beegosessionID.

beego.BConfig.WebConfig.Session.SessionName = "beegosessionID"

SessionGCMaxLifetime

session expire time, default is 3600 seconds.

beego.BConfig.WebConfig.Session.SessionGCMaxLifetime = 3600

SessionProviderConfig

Configuration information, set different depending on the engine configuration information, see the following detailed configuration of the engine settings, see the detailed session module

SessionCookieLifeTime

The default session cookie time of existence of the client, the default value is 3600 seconds.

beego.BConfig.WebConfig.Session.SessionCookieLifeTime = 3600

SessionAutoSetCookie

Whether to open SetCookie, default true not open.

beego.BConfig.WebConfig.Session.SessionAutoSetCookie = true

SessionDomain



session cookie storage domain, default empty.

beego.BConfig.WebConfig.Session.SessionDomain = “”
Log配置

log detailed configuration, see the logs module.

AccessLogs

Whether to output logs to Log, the default output will not log in prod mode, the default is false does not output log. This parameter is not supported by the configuration file configuration.

beego.BConfig.Log.AccessLogs = false

I filelinen

Whether to display the output log file name and line number in the log inside, default true. This parameter is not supported by the configuration file configuration.

beego.BConfig.Log.FileLineNum = true

Outputs

Log output configuration, the reference logs module, console file and other configuration, this parameter is not supported profile configuration.

beego.BConfig.Log.Outputs = map[string]string{"console": ""}

or

beego.BConfig.Log.Outputs["console"] = ""

 

Reference: https://blog.csdn.net/qq_33610643/article/details/53511058

Guess you like

Origin www.cnblogs.com/show58/p/12362852.html