You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nnet/config/config.go

52 lines
1.3 KiB
Go

package config
import (
"fmt"
"time"
)
const (
// DevMode means development mode.
DevMode = "dev"
// TestMode means test mode.
TestMode = "test"
// ProductionMode means production mode.
ProductionMode = "prod"
)
// Defaults
const (
DefaultSendChannelSize = 1 << 10
DefaultWriteChannelSize = 1 << 10 << 10
)
type (
EngineConf struct {
// TaskTimerPrecision 全局任务的timer间隔
TaskTimerPrecision time.Duration `json:",default=1s"`
// Mode 运行模式
Mode string `json:",default=dev,options=[dev,test,prod]"`
// Name 引擎名称
Name string `json:",default=NL,env=ENGINE_NAME"`
// ReadDeadline 读数据超时时长,0为不超时
ReadDeadline time.Duration `json:",default=0s"`
// WriteDeadline 写数据超时时长,0为不超时
WriteDeadline time.Duration `json:",default=0s"`
// Deadline 读+写数据超时时长,0为不超时
Deadline time.Duration `json:",default=0s"`
// SendChannelSize
SendChannelSize int `json:",default=1024"`
// WriteChannelSize
WriteChannelSize int `json:",default=1024"`
}
)
// ShallLogDebug 是否应该打印 Debug 级别的日志,打印的首要条件是 nlog 的打印级别为 debug
func (c EngineConf) ShallLogDebug() bool {
return c.Mode == DevMode || c.Mode == TestMode
}
func (c EngineConf) LogPrefix() string {
return fmt.Sprintf("[NNet-%s]", c.Name)
}