add json tag for configuration struct for package gdb/gredis/ghttp/glog/gview

This commit is contained in:
John Guo 2021-01-12 00:42:33 +08:00
parent 2ae32ed2c2
commit a9aa021914
6 changed files with 117 additions and 117 deletions

View File

@ -27,30 +27,30 @@ type ConfigGroup []ConfigNode
// ConfigNode is configuration for one node.
type ConfigNode struct {
Host string // Host of server, ip or domain like: 127.0.0.1, localhost
Port string // Port, it's commonly 3306.
User string // Authentication username.
Pass string // Authentication password.
Name string // Default used database name.
Type string // Database type: mysql, sqlite, mssql, pgsql, oracle.
Role string // (Optional, "master" in default) Node role, used for master-slave mode: master, slave.
Debug bool // (Optional) Debug mode enables debug information logging and output.
Prefix string // (Optional) Table prefix.
DryRun bool // (Optional) Dry run, which does SELECT but no INSERT/UPDATE/DELETE statements.
Weight int // (Optional) Weight for load balance calculating, it's useless if there's just one node.
Charset string // (Optional, "utf8mb4" in default) Custom charset when operating on database.
LinkInfo string `json:"link"` // (Optional) Custom link information, when it is used, configuration Host/Port/User/Pass/Name are ignored.
MaxIdleConnCount int `json:"maxidle"` // (Optional) Max idle connection configuration for underlying connection pool.
MaxOpenConnCount int `json:"maxopen"` // (Optional) Max open connection configuration for underlying connection pool.
MaxConnLifetime time.Duration `json:"maxlifetime"` // (Optional) Max connection TTL configuration for underlying connection pool.
QueryTimeout time.Duration // (Optional) Max query time for per dql.
ExecTimeout time.Duration // (Optional) Max exec time for dml.
TranTimeout time.Duration // (Optional) Max exec time time for a transaction.
PrepareTimeout time.Duration // (Optional) Max exec time time for prepare operation.
CreatedAt string // (Optional) The filed name of table for automatic-filled created datetime.
UpdatedAt string // (Optional) The filed name of table for automatic-filled updated datetime.
DeletedAt string // (Optional) The filed name of table for automatic-filled updated datetime.
TimeMaintainDisabled bool // (Optional) Disable the automatic time maintaining feature.
Host string `json:"host"` // Host of server, ip or domain like: 127.0.0.1, localhost
Port string `json:"port"` // Port, it's commonly 3306.
User string `json:"user"` // Authentication username.
Pass string `json:"pass"` // Authentication password.
Name string `json:"name"` // Default used database name.
Type string `json:"type"` // Database type: mysql, sqlite, mssql, pgsql, oracle.
Role string `json:"role"` // (Optional, "master" in default) Node role, used for master-slave mode: master, slave.
Debug bool `json:"debug"` // (Optional) Debug mode enables debug information logging and output.
Prefix string `json:"prefix"` // (Optional) Table prefix.
DryRun bool `json:"dryRun"` // (Optional) Dry run, which does SELECT but no INSERT/UPDATE/DELETE statements.
Weight int `json:"weight"` // (Optional) Weight for load balance calculating, it's useless if there's just one node.
Charset string `json:"charset"` // (Optional, "utf8mb4" in default) Custom charset when operating on database.
LinkInfo string `json:"link"` // (Optional) Custom link information, when it is used, configuration Host/Port/User/Pass/Name are ignored.
MaxIdleConnCount int `json:"maxIdle"` // (Optional) Max idle connection configuration for underlying connection pool.
MaxOpenConnCount int `json:"maxOpen"` // (Optional) Max open connection configuration for underlying connection pool.
MaxConnLifetime time.Duration `json:"maxLifetime"` // (Optional) Max connection TTL configuration for underlying connection pool.
QueryTimeout time.Duration `json:"queryTimeout"` // (Optional) Max query time for per dql.
ExecTimeout time.Duration `json:"execTimeout"` // (Optional) Max exec time for dml.
TranTimeout time.Duration `json:"tranTimeout"` // (Optional) Max exec time time for a transaction.
PrepareTimeout time.Duration `json:"prepareTimeout"` // (Optional) Max exec time time for prepare operation.
CreatedAt string `json:"createdAt"` // (Optional) The filed name of table for automatic-filled created datetime.
UpdatedAt string `json:"updatedAt"` // (Optional) The filed name of table for automatic-filled updated datetime.
DeletedAt string `json:"deletedAt"` // (Optional) The filed name of table for automatic-filled updated datetime.
TimeMaintainDisabled bool `json:"timeMaintainDisabled"` // (Optional) Disable the automatic time maintaining feature.
}
// configs is internal used configuration object.

View File

@ -1,4 +1,4 @@
// Copyright 2017 gf Author(https://github.com/gogf/gf). All Rights Reserved.
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
@ -36,17 +36,17 @@ type Conn struct {
// Redis configuration.
type Config struct {
Host string
Port int
Db int
Pass string // Password for AUTH.
MaxIdle int // Maximum number of connections allowed to be idle (default is 10)
MaxActive int // Maximum number of connections limit (default is 0 means no limit).
IdleTimeout time.Duration // Maximum idle time for connection (default is 10 seconds, not allowed to be set to 0)
MaxConnLifetime time.Duration // Maximum lifetime of the connection (default is 30 seconds, not allowed to be set to 0)
ConnectTimeout time.Duration // Dial connection timeout.
TLS bool // Specifies the config to use when a TLS connection is dialed.
TLSSkipVerify bool // Disables server name verification when connecting over TLS
Host string `json:"host"`
Port int `json:"port"`
Db int `json:"db"`
Pass string `json:"pass"` // Password for AUTH.
MaxIdle int `json:"maxIdle"` // Maximum number of connections allowed to be idle (default is 10)
MaxActive int `json:"maxActive"` // Maximum number of connections limit (default is 0 means no limit).
IdleTimeout time.Duration `json:"idleTimeout"` // Maximum idle time for connection (default is 10 seconds, not allowed to be set to 0)
MaxConnLifetime time.Duration `json:"maxConnLifetime"` // Maximum lifetime of the connection (default is 30 seconds, not allowed to be set to 0)
ConnectTimeout time.Duration `json:"connectTimeout"` // Dial connection timeout.
TLS bool `json:"tls"` // Specifies the config to use when a TLS connection is dialed.
TLSSkipVerify bool `json:"tlsSkipVerify"` // Disables server name verification when connecting over TLS
}
// Pool statistics.

View File

@ -350,7 +350,7 @@ func (s *Server) startServer(fdMap listenerFdMap) {
s.config.HTTPSAddr = s.config.Address
s.config.Address = ""
} else {
s.config.HTTPSAddr = gDEFAULT_HTTPS_ADDR
s.config.HTTPSAddr = defaultHttpsAddr
}
}
httpsEnabled = len(s.config.HTTPSAddr) > 0
@ -385,7 +385,7 @@ func (s *Server) startServer(fdMap listenerFdMap) {
}
// HTTP
if !httpsEnabled && len(s.config.Address) == 0 {
s.config.Address = gDEFAULT_HTTP_ADDR
s.config.Address = defaultHttpAddr
}
var array []string
if v, ok := fdMap["http"]; ok && len(v) > 0 {

View File

@ -27,12 +27,12 @@ import (
)
const (
gDEFAULT_HTTP_ADDR = ":80" // Default listening port for HTTP.
gDEFAULT_HTTPS_ADDR = ":443" // Default listening port for HTTPS.
URI_TYPE_DEFAULT = 0 // Method name to URI converting type, which converts name to its lower case and joins the words using char '-'.
URI_TYPE_FULLNAME = 1 // Method name to URI converting type, which does no converting to the method name.
URI_TYPE_ALLLOWER = 2 // Method name to URI converting type, which converts name to its lower case.
URI_TYPE_CAMEL = 3 // Method name to URI converting type, which converts name to its camel case.
defaultHttpAddr = ":80" // Default listening port for HTTP.
defaultHttpsAddr = ":443" // Default listening port for HTTPS.
URI_TYPE_DEFAULT = 0 // Method name to URI converting type, which converts name to its lower case and joins the words using char '-'.
URI_TYPE_FULLNAME = 1 // Method name to URI converting type, which does no converting to the method name.
URI_TYPE_ALLLOWER = 2 // Method name to URI converting type, which converts name to its lower case.
URI_TYPE_CAMEL = 3 // Method name to URI converting type, which converts name to its camel case.
)
// ServerConfig is the HTTP Server configuration manager.
@ -43,16 +43,16 @@ type ServerConfig struct {
// Address specifies the server listening address like "port" or ":port",
// multiple addresses joined using ','.
Address string
Address string `json:"address"`
// HTTPSAddr specifies the HTTPS addresses, multiple addresses joined using char ','.
HTTPSAddr string
HTTPSAddr string `json:"httpsAddr"`
// HTTPSCertPath specifies certification file path for HTTPS service.
HTTPSCertPath string
HTTPSCertPath string `json:"httpsCertPath"`
// HTTPSKeyPath specifies the key file path for HTTPS service.
HTTPSKeyPath string
HTTPSKeyPath string `json:"httpsKeyPath"`
// TLSConfig optionally provides a TLS configuration for use
// by ServeTLS and ListenAndServeTLS. Note that this value is
@ -61,10 +61,10 @@ type ServerConfig struct {
// tls.Config.SetSessionTicketKeys. To use
// SetSessionTicketKeys, use Server.Serve with a TLS Listener
// instead.
TLSConfig *tls.Config
TLSConfig *tls.Config `json:"tlsConfig"`
// Handler the handler for HTTP request.
Handler http.Handler
Handler http.Handler `json:"-"`
// ReadTimeout is the maximum duration for reading the entire
// request, including the body.
@ -73,19 +73,19 @@ type ServerConfig struct {
// decisions on each request body's acceptable deadline or
// upload rate, most users will prefer to use
// ReadHeaderTimeout. It is valid to use them both.
ReadTimeout time.Duration
ReadTimeout time.Duration `json:"readTimeout"`
// WriteTimeout is the maximum duration before timing out
// writes of the response. It is reset whenever a new
// request's header is read. Like ReadTimeout, it does not
// let Handlers make decisions on a per-request basis.
WriteTimeout time.Duration
WriteTimeout time.Duration `json:"writeTimeout"`
// IdleTimeout is the maximum amount of time to wait for the
// next request when keep-alives are enabled. If IdleTimeout
// is zero, the value of ReadTimeout is used. If both are
// zero, there is no timeout.
IdleTimeout time.Duration
IdleTimeout time.Duration `json:"idleTimeout"`
// MaxHeaderBytes controls the maximum number of bytes the
// server will read parsing the request header's keys and
@ -94,102 +94,102 @@ type ServerConfig struct {
//
// It can be configured in configuration file using string like: 1m, 10m, 500kb etc.
// It's 10240 bytes in default.
MaxHeaderBytes int
MaxHeaderBytes int `json:"maxHeaderBytes"`
// KeepAlive enables HTTP keep-alive.
KeepAlive bool
KeepAlive bool `json:"keepAlive"`
// ServerAgent specifies the server agent information, which is wrote to
// HTTP response header as "Server".
ServerAgent string
ServerAgent string `json:"serverAgent"`
// View specifies the default template view object for the server.
View *gview.View
View *gview.View `json:"view"`
// ==================================
// Static.
// ==================================
// Rewrites specifies the URI rewrite rules map.
Rewrites map[string]string
Rewrites map[string]string `json:"rewrites"`
// IndexFiles specifies the index files for static folder.
IndexFiles []string
IndexFiles []string `json:"indexFiles"`
// IndexFolder specifies if listing sub-files when requesting folder.
// The server responses HTTP status code 403 if it is false.
IndexFolder bool
IndexFolder bool `json:"indexFolder"`
// ServerRoot specifies the root directory for static service.
ServerRoot string
ServerRoot string `json:"serverRoot"`
// SearchPaths specifies additional searching directories for static service.
SearchPaths []string
SearchPaths []string `json:"searchPaths"`
// StaticPaths specifies URI to directory mapping array.
StaticPaths []staticPathItem
StaticPaths []staticPathItem `json:"staticPaths"`
// FileServerEnabled is the global switch for static service.
// It is automatically set enabled if any static path is set.
FileServerEnabled bool
FileServerEnabled bool `json:"fileServerEnabled"`
// ==================================
// Cookie.
// ==================================
// CookieMaxAge specifies the max TTL for cookie items.
CookieMaxAge time.Duration
CookieMaxAge time.Duration `json:"cookieMaxAge"`
// CookiePath specifies cookie path.
// It also affects the default storage for session id.
CookiePath string
CookiePath string `json:"cookiePath"`
// CookieDomain specifies cookie domain.
// It also affects the default storage for session id.
CookieDomain string
CookieDomain string `json:"cookieDomain"`
// ==================================
// Session.
// ==================================
// SessionIdName specifies the session id name.
SessionIdName string
SessionIdName string `json:"sessionIdName"`
// SessionMaxAge specifies max TTL for session items.
SessionMaxAge time.Duration
SessionMaxAge time.Duration `json:"sessionMaxAge"`
// SessionPath specifies the session storage directory path for storing session files.
// It only makes sense if the session storage is type of file storage.
SessionPath string
SessionPath string `json:"sessionPath"`
// SessionStorage specifies the session storage.
SessionStorage gsession.Storage
SessionStorage gsession.Storage `json:"sessionStorage"`
// SessionCookieMaxAge specifies the cookie ttl for session id.
// It it is set 0, it means it expires along with browser session.
SessionCookieMaxAge time.Duration
SessionCookieMaxAge time.Duration `json:"sessionCookieMaxAge"`
// SessionCookieOutput specifies whether automatic outputting session id to cookie.
SessionCookieOutput bool
SessionCookieOutput bool `json:"sessionCookieOutput"`
// ==================================
// Logging.
// ==================================
Logger *glog.Logger // Logger specifies the logger for server.
LogPath string // LogPath specifies the directory for storing logging files.
LogLevel string // LogLevel specifies the logging level for logger.
LogStdout bool // LogStdout specifies whether printing logging content to stdout.
ErrorStack bool // ErrorStack specifies whether logging stack information when error.
ErrorLogEnabled bool // ErrorLogEnabled enables error logging content to files.
ErrorLogPattern string // ErrorLogPattern specifies the error log file pattern like: error-{Ymd}.log
AccessLogEnabled bool // AccessLogEnabled enables access logging content to files.
AccessLogPattern string // AccessLogPattern specifies the error log file pattern like: access-{Ymd}.log
Logger *glog.Logger `json:"logger"` // Logger specifies the logger for server.
LogPath string `json:"logPath"` // LogPath specifies the directory for storing logging files.
LogLevel string `json:"logLevel"` // LogLevel specifies the logging level for logger.
LogStdout bool `json:"logStdout"` // LogStdout specifies whether printing logging content to stdout.
ErrorStack bool `json:"errorStack"` // ErrorStack specifies whether logging stack information when error.
ErrorLogEnabled bool `json:"errorLogEnabled"` // ErrorLogEnabled enables error logging content to files.
ErrorLogPattern string `json:"errorLogPattern"` // ErrorLogPattern specifies the error log file pattern like: error-{Ymd}.log
AccessLogEnabled bool `json:"accessLogEnabled"` // AccessLogEnabled enables access logging content to files.
AccessLogPattern string `json:"accessLogPattern"` // AccessLogPattern specifies the error log file pattern like: access-{Ymd}.log
// ==================================
// PProf.
// ==================================
PProfEnabled bool // PProfEnabled enables PProf feature.
PProfPattern string // PProfPattern specifies the PProf service pattern for router.
PProfEnabled bool `json:"pprofEnabled"` // PProfEnabled enables PProf feature.
PProfPattern string `json:"pprofPattern"` // PProfPattern specifies the PProf service pattern for router.
// ==================================
// Other.
@ -198,26 +198,26 @@ type ServerConfig struct {
// ClientMaxBodySize specifies the max body size limit in bytes for client request.
// It can be configured in configuration file using string like: 1m, 10m, 500kb etc.
// It's 8MB in default.
ClientMaxBodySize int64
ClientMaxBodySize int64 `json:"clientMaxBodySize"`
// FormParsingMemory specifies max memory buffer size in bytes which can be used for
// parsing multimedia form.
// It can be configured in configuration file using string like: 1m, 10m, 500kb etc.
// It's 1MB in default.
FormParsingMemory int64
FormParsingMemory int64 `json:"formParsingMemory"`
// NameToUriType specifies the type for converting struct method name to URI when
// registering routes.
NameToUriType int
NameToUriType int `json:"nameToUriType"`
// RouteOverWrite allows overwrite the route if duplicated.
RouteOverWrite bool
RouteOverWrite bool `json:"routeOverWrite"`
// DumpRouterMap specifies whether automatically dumps router map when server starts.
DumpRouterMap bool
DumpRouterMap bool `json:"dumpRouterMap"`
// Graceful enables graceful reload feature for all servers of the process.
Graceful bool
Graceful bool `json:"graceful"`
}
// Deprecated. Use NewConfig instead.

View File

@ -1,4 +1,4 @@
// Copyright 2017 gf Author(https://github.com/gogf/gf). All Rights Reserved.
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
@ -21,25 +21,25 @@ import (
// Config is the configuration object for logger.
type Config struct {
Writer io.Writer // Customized io.Writer.
Flags int // Extra flags for logging output features.
Path string // Logging directory path.
File string // Format for logging file.
Level int // Output level.
Prefix string // Prefix string for every logging content.
StSkip int // Skip count for stack.
StStatus int // Stack status(1: enabled - default; 0: disabled)
StFilter string // Stack string filter.
CtxKeys []interface{} // Context keys for logging, which is used for value retrieving from context.
HeaderPrint bool `c:"header"` // Print header or not(true in default).
StdoutPrint bool `c:"stdout"` // Output to stdout or not(true in default).
LevelPrefixes map[int]string // Logging level to its prefix string mapping.
RotateSize int64 // Rotate the logging file if its size > 0 in bytes.
RotateExpire time.Duration // Rotate the logging file if its mtime exceeds this duration.
RotateBackupLimit int // Max backup for rotated files, default is 0, means no backups.
RotateBackupExpire time.Duration // Max expire for rotated files, which is 0 in default, means no expiration.
RotateBackupCompress int // Compress level for rotated files using gzip algorithm. It's 0 in default, means no compression.
RotateCheckInterval time.Duration // Asynchronizely checks the backups and expiration at intervals. It's 1 hour in default.
Writer io.Writer `json:"-"` // Customized io.Writer.
Flags int `json:"flags"` // Extra flags for logging output features.
Path string `json:"path"` // Logging directory path.
File string `json:"file"` // Format for logging file.
Level int `json:"level"` // Output level.
Prefix string `json:"prefix"` // Prefix string for every logging content.
StSkip int `json:"stSkip"` // Skip count for stack.
StStatus int `json:"stStatus"` // Stack status(1: enabled - default; 0: disabled)
StFilter string `json:"stFilter"` // Stack string filter.
CtxKeys []interface{} `json:"ctxKeys"` // Context keys for logging, which is used for value retrieving from context.
HeaderPrint bool `json:"header"` // Print header or not(true in default).
StdoutPrint bool `json:"stdout"` // Output to stdout or not(true in default).
LevelPrefixes map[int]string `json:"levelPrefixes"` // Logging level to its prefix string mapping.
RotateSize int64 `json:"rotateSize"` // Rotate the logging file if its size > 0 in bytes.
RotateExpire time.Duration `json:"rotateExpire"` // Rotate the logging file if its mtime exceeds this duration.
RotateBackupLimit int `json:"rotateBackupLimit"` // Max backup for rotated files, default is 0, means no backups.
RotateBackupExpire time.Duration `json:"rotateBackupExpire"` // Max expire for rotated files, which is 0 in default, means no expiration.
RotateBackupCompress int `json:"rotateBackupCompress"` // Compress level for rotated files using gzip algorithm. It's 0 in default, means no compression.
RotateCheckInterval time.Duration `json:"rotateCheckInterval"` // Asynchronizely checks the backups and expiration at intervals. It's 1 hour in default.
}
// DefaultConfig returns the default configuration for logger.

View File

@ -1,4 +1,4 @@
// Copyright 2017 gf Author(https://github.com/gogf/gf). All Rights Reserved.
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
@ -21,12 +21,12 @@ import (
// Config is the configuration object for template engine.
type Config struct {
Paths []string // Searching array for path, NOT concurrent-safe for performance purpose.
Data map[string]interface{} // Global template variables including configuration.
DefaultFile string // Default template file for parsing.
Delimiters []string // Custom template delimiters.
AutoEncode bool // Automatically encodes and provides safe html output, which is good for avoiding XSS.
I18nManager *gi18n.Manager // I18n manager for the view.
Paths []string `json:"paths"` // Searching array for path, NOT concurrent-safe for performance purpose.
Data map[string]interface{} `json:"data"` // Global template variables including configuration.
DefaultFile string `json:"defaultFile"` // Default template file for parsing.
Delimiters []string `json:"delimiters"` // Custom template delimiters.
AutoEncode bool `json:"autoEncode"` // Automatically encodes and provides safe html output, which is good for avoiding XSS.
I18nManager *gi18n.Manager `json:"-"` // I18n manager for the view.
}
const (