zconf

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 1, 2024 License: GPL-3.0 Imports: 8 Imported by: 0

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

View Source
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"
)
View Source
const (
	ServerModeTcp       = "tcp"
	ServerModeWebsocket = "websocket"
	ServerModeKcp       = "kcp"
	ServerModeUdp       = "udp"
)
View Source
const (
	WorkerModeHash = "Hash" // By default, the round-robin average allocation rule is used.(默认使用取余的方式)
	WorkerModeBind = "Bind" // Bind a worker to each connection.(为每个连接分配一个worker)
)

Variables

This section is empty.

Functions

func GetConfigFilePath

func GetConfigFilePath() string

func PathExists

func PathExists(path string) (bool, error)

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监听端口)
	Name    string // The name of the current server.(当前服务器名称)
	KcpPort int    // he port number on which the server listens for KCP connections.(当前服务器主机监听端口号)
	UdpPort int    // he port number on which the server listens for UDP connections.(当前服务器主机监听端口号)
	/*
		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

	/*
		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

Define a global object.(定义一个全局的对象)

func (*Config) HeartbeatMaxDuration

func (g *Config) HeartbeatMaxDuration() time.Duration

func (*Config) InitLogConfig

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.

func (*Config) Show

func (g *Config) Show()

Show Zinx Config Info

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL