Documentation
¶
Overview ¶
@Title globalobj.go @Description 相关配置文件定义及加载方式 defines a configuration structure named "Config" along with its methods. The package is named "zconf", and the file is named "globalobj.go". @Author Aceld - Thu Mar 11 10:32:29 CST 2019
Index ¶
Constants ¶
const ( // EnvConfigFilePathKey (Set configuration file path export ZINX_CONFIG_FILE_PATH = xxxxxxzinx.json) // (设置配置文件路径 export ZINX_CONFIG_FILE_PATH = xxx/xxx/zinx.json) EnvConfigFilePathKey = "ZINX_CONFIG_FILE_PATH" EnvDefaultConfigFilePath = "/conf/zinx.json" )
const ( ServerModeTcp = "tcp" ServerModeWebsocket = "websocket" ServerModeKcp = "kcp" )
const ( WorkerModeHash = "Hash" // By default, the round-robin average allocation rule is used.(默认使用取余的方式) WorkerModeBind = "Bind" // Bind a worker to each connection.(为每个连接分配一个worker) //WorkerModeDynamicBind 也是一个连接对应一个worker, 给连接分配worker时, 如果工作池里初始化的worker已经用完了,就动态创建一个worker绑定到每个连接。这个临时创建的worker, 会在连接断开后销毁。 //跟WorkerModeHash的区别是,如果业务层回调有阻塞操作的话,也不影响其他连接的业务层处理。 //跟WorkerModeBind的区别是,不需要像Bind模式那样一开始就创建很多worker,而是根据连接数动态创建worker,这样可以避免闲置worker数量过多导致的资源浪费。 WorkerModeDynamicBind = "DynamicBind" // Dynamic binding of a worker to each connection when there is no worker in worker pool.(临时动态创建一个worker绑定到每个连接) )
Variables ¶
This section is empty.
Functions ¶
func GetConfigFilePath ¶ added in v1.2.2
func GetConfigFilePath() string
func PathExists ¶
PathExists Check if a file exists.(判断一个文件是否存在)
func UserConfToGlobal ¶
func UserConfToGlobal(config *Config)
UserConfToGlobal, Note that if UserConf is used, the method should be called to synchronize with GlobalConfObject because other parameters are called from this structure parameter. (注意如果使用UserConf应该调用方法同步至 GlobalConfObject 因为其他参数是调用的此结构体参数)
Types ¶
type Config ¶
type Config struct {
/*
Server
*/
Host string // The IP address of the current server. (当前服务器主机IP)
TCPPort int // The port number on which the server listens for TCP connections.(当前服务器主机监听端口号)
WsPort int // The port number on which the server listens for WebSocket connections.(当前服务器主机websocket监听端口)
WsPath string // The path of the WebSocket connection.(websocket连接路径)
Name string // The name of the current server.(当前服务器名称)
KcpPort int // he port number on which the server listens for KCP connections.(当前服务器主机监听端口号)
/*
ServerConfig
*/
KcpACKNoDelay bool // changes ack flush option, set true to flush ack immediately,
KcpStreamMode bool // toggles the stream mode on/off
KcpNoDelay int // Whether nodelay mode is enabled, 0 is not enabled; 1 enabled.
KcpInterval int // Protocol internal work interval, in milliseconds, such as 10 ms or 20 ms.
KcpResend int // Fast retransmission mode, 0 represents off by default, 2 can be set (2 ACK spans will result in direct retransmission)
KcpNc int // Whether to turn off flow control, 0 represents “Do not turn off” by default, 1 represents “Turn off”.
KcpSendWindow int // SND_BUF, this unit is the packet, default 32.
KcpRecvWindow int // RCV_BUF, this unit is the packet, default 32.
KcpFecDataShards int // The number of data shards in the FEC.(FEC数据分片), default 0.
KcpFecParityShards int // The number of parity shards in the FEC.(FEC校验分片) default 0.
/*
Zinx
*/
Version string // The version of the Zinx framework.(当前Zinx版本号)
MaxPacketSize uint32 // The maximum size of the packets that can be sent or received.(读写数据包的最大值)
MaxConn int // The maximum number of connections that the server can handle.(当前服务器主机允许的最大连接个数)
WorkerPoolSize uint32 // The number of worker pools in the business logic.(业务工作Worker池的数量)
MaxWorkerTaskLen uint32 // The maximum number of tasks that a worker pool can handle.(业务工作Worker对应负责的任务队列最大任务存储数量)
WorkerMode string // The way to assign workers to connections.(为连接分配worker的方式)
MaxMsgChanLen uint32 // The maximum length of the send buffer message queue.(SendBuffMsg发送消息的缓冲最大长度)
IOReadBuffSize uint32 // The maximum size of the read buffer for each IO operation.(每次IO最大的读取长度)
//The server mode, which can be "tcp" or "websocket". If it is empty, both modes are enabled.
//"tcp":tcp监听, "websocket":websocket 监听 为空时同时开启
Mode string
// A boolean value that indicates whether the new or old version of the router is used. The default value is false.
// 路由模式 false为旧版本路由,true为启用新版本的路由 默认使用旧版本
RouterSlicesMode bool
// 是否开启 Request 对象池模式
RequestPoolMode bool
/*
logger
*/
LogDir string // The directory where log files are stored. The default value is "./log".(日志所在文件夹 默认"./log")
// The name of the log file. If it is empty, the log information will be printed to stderr.
// (日志文件名称 默认"" --如果没有设置日志文件,打印信息将打印至stderr)
LogFile string
LogSaveDays int // 日志最大保留天数
LogFileSize int64 // 日志单个日志最大容量 默认 64MB,单位:字节,记得一定要换算成MB(1024 * 1024)
LogCons bool // 日志标准输出 默认 false
// The level of log isolation. The values can be 0 (all open), 1 (debug off), 2 (debug/info off), 3 (debug/info/warn off), and so on.
// 日志隔离级别 -- 0:全开 1:关debug 2:关debug/info 3:关debug/info/warn ...
LogIsolationLevel int
/*
Keepalive
*/
// The maximum interval for heartbeat detection in seconds.
// 最长心跳检测间隔时间(单位:秒),超过改时间间隔,则认为超时,从配置文件读取
HeartbeatMax int
/*
TLS
*/
CertFile string // The name of the certificate file. If it is empty, TLS encryption is not enabled.(证书文件名称 默认"")
PrivateKeyFile string // The name of the private key file. If it is empty, TLS encryption is not enabled.(私钥文件名称 默认"" --如果没有设置证书和私钥文件,则不启用TLS加密)
}
Store all global parameters related to the Zinx framework for use by other modules. Some parameters can also be configured by the user based on the zinx.json file. (存储一切有关Zinx框架的全局参数,供其他模块使用 一些参数也可以通过 用户根据 zinx.json来配置)
var GlobalObject *Config
GlobalObject Define a global object.(定义一个全局的对象)
func (*Config) HeartbeatMaxDuration ¶
func (*Config) InitLogConfig ¶ added in v1.1.17
func (g *Config) InitLogConfig()
func (*Config) Reload ¶
func (g *Config) Reload()
Reload 读取用户的配置文件 This method is used to reload the configuration file. It reads the configuration file specified in the command-line arguments, and updates the fields of the "Config" structure accordingly. If the configuration file does not exist, it prints an error message to the log and returns.