conf

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package conf 包含micserver中使用的 配置文件/命令行参数 的配置

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppConfig

type AppConfig struct {
	*BaseConfig `json:"settings"`
	Modules     map[string]*ModuleConfig `json:"modules"`
}

AppConfig App的配置,包括App全局配置以及配置文件中的模块配置

func (*AppConfig) GetModuleConfig

func (a *AppConfig) GetModuleConfig(moduleid string) *ModuleConfig

GetModuleConfig 获取目标模块ID的模块配置,返回模块的指针,如果目标模块不存在,返回nil。 为了性能考虑不进行拷贝, 调用方不允许使用代码修改 ModuleConfig 的内容, 你应该修改配置文件而不是用代码设置配置值。

func (*AppConfig) GetModuleConfigList

func (a *AppConfig) GetModuleConfigList() map[string]*ModuleConfig

GetModuleConfigList 获取所有的模块配置

func (*AppConfig) GetSubnetTCPAddrMap

func (a *AppConfig) GetSubnetTCPAddrMap() map[string]string

GetSubnetTCPAddrMap 获取配置中存在的所有模块的subnet地址

type BaseConfig

type BaseConfig map[string]interface{}

BaseConfig 配置由 encoding/json 读入为 map[string]interface{} 类型的结构。 不可写,所以不对外提供写接口

func NewBaseConfig

func NewBaseConfig() *BaseConfig

NewBaseConfig 获取一个空的 BaseConfig 结构

func (*BaseConfig) Exist

func (bf *BaseConfig) Exist(key ConfigKey) bool

Exist 判断键是否存在

func (*BaseConfig) Get

func (bf *BaseConfig) Get(key ConfigKey) interface{}

Get 获取指定键的值

func (*BaseConfig) GetBool

func (bf *BaseConfig) GetBool(key ConfigKey) bool

GetBool 获取指定键的bool类型值

func (*BaseConfig) GetInt64

func (bf *BaseConfig) GetInt64(key ConfigKey) int64

GetInt64 获取指定键的 int64 类型值

func (*BaseConfig) GetInt64Slice

func (bf *BaseConfig) GetInt64Slice(key ConfigKey) []int64

GetInt64Slice 获取指定键的 []int64 类型值

func (*BaseConfig) GetString

func (bf *BaseConfig) GetString(key ConfigKey) string

GetString 获取指定键的 string 类型值

func (*BaseConfig) GetStringSlice

func (bf *BaseConfig) GetStringSlice(key ConfigKey) []string

GetStringSlice 获取指定键的 []string 类型值

type ConfigKey

type ConfigKey string

ConfigKey micserver中配置的键类型

var (
	// 版本号		string
	Version ConfigKey = "version"
	// 进程ID		string
	ProcessID ConfigKey = "processid"
	// log完整路径		string
	LogWholePath ConfigKey = "logpath"
	// log等级		string
	LogLevel ConfigKey = "loglevel"
	// 服务器TCP子网ip及端口,如 1.0.0.1:80 		string
	SubnetTCPAddr ConfigKey = "subnettcpaddr"
	// 不使用本地chan		bool
	SubnetNoChan ConfigKey = "subnetnochan"
	// 网关TCP地址		string
	GateTCPAddr ConfigKey = "gatetcpaddr"
	// 是否是受保护的进程 		bool
	IsDaemon ConfigKey = "isdaemon"
	// 消息处理并发协程数量		int
	MsgThreadNum ConfigKey = "msgthreadnum"
	// ROC的绑定是否使用异步方式同步到别的module中,会与ROC调用有异步问题 bool
	AsynchronousSyncRocbind ConfigKey = "asynchronous_sync_rocbind"
)

micserver框架内置的配置选项

type ModuleConfig

type ModuleConfig struct {
	ID          string      `json:"id"`
	Settings    *BaseConfig `json:"settings"`
	AppSettings *BaseConfig `json:"-"`
}

ModuleConfig 模块的配置,也包括了该模块所属的App配置

func (*ModuleConfig) Exist

func (mc *ModuleConfig) Exist(key ConfigKey) bool

Exist 判断配置是否存在,先尝试获取 Module 中的配置,如果 Module 中不存在该配置, 再尝试获取 App 中的配置,如果都不存在则返回 nil

func (*ModuleConfig) ExistInApp

func (mc *ModuleConfig) ExistInApp(key ConfigKey) bool

ExistInApp 判断目标配置是否在 App 配置中存在,无视 Module 的配置

func (*ModuleConfig) ExistInModule

func (mc *ModuleConfig) ExistInModule(key ConfigKey) bool

ExistInModule 判断目标配置是否在 Module 配置中存在,无视 App 的配置

func (*ModuleConfig) Get

func (mc *ModuleConfig) Get(key ConfigKey) interface{}

Get 获取配置值,先尝试获取 Module 中的配置,如果 Module 中不存在该配置, 再尝试获取 App 中的配置,如果都不存在则返回 nil

func (*ModuleConfig) GetBool

func (mc *ModuleConfig) GetBool(key ConfigKey) bool

GetBool 获取配置 bool 值,先尝试获取 Module 中的配置,如果 Module 中不存在该配置, 再尝试获取 App 中的配置,如果都不存在则返回 nil

func (*ModuleConfig) GetInt64

func (mc *ModuleConfig) GetInt64(key ConfigKey) int64

GetInt64 获取配置 int64 值,先尝试获取 Module 中的配置,如果 Module 中不存在该配置, 再尝试获取 App 中的配置,如果都不存在则返回 nil

func (*ModuleConfig) GetInt64Slice

func (mc *ModuleConfig) GetInt64Slice(key ConfigKey) []int64

GetInt64Slice 获取配置 []int64 值,先尝试获取 Module 中的配置,如果 Module 中不存在该配置, 再尝试获取 App 中的配置,如果都不存在则返回 nil

func (*ModuleConfig) GetString

func (mc *ModuleConfig) GetString(key ConfigKey) string

GetString 获取配置 string 值,先尝试获取 Module 中的配置,如果 Module 中不存在该配置, 再尝试获取 App 中的配置,如果都不存在则返回 nil

func (*ModuleConfig) GetStringSlice

func (mc *ModuleConfig) GetStringSlice(key ConfigKey) []string

GetStringSlice 获取配置 []string 值,先尝试获取 Module 中的配置,如果 Module 中不存在该配置, 再尝试获取 App 中的配置,如果都不存在则返回 nil

type TopConfig

type TopConfig struct {
	AppConfig AppConfig `json:"app"` // 进程配置信息

	// 服务器数字版本
	// 建议命名规则为: YYYYMMDDhhmmss (年月日时分秒)
	Version uint64 `json:"-"`
	// contains filtered or unexported fields
}

TopConfig 所有配置,包括从文件以进命令行输入的所有配置内容

func Default added in v0.1.1

func Default() *TopConfig

Default config

func LoadConfig

func LoadConfig(filepath string) (*TopConfig, error)

LoadConfig 从配置文件以及命令行参数中加载配置

func (*TopConfig) GetArgvModuleList

func (tc *TopConfig) GetArgvModuleList() []string

GetArgvModuleList 命令行参数中的模块名列表,可使用命令行参数的 -p 选项携带,例如: ./foo -p gate001,gate002,logic001 表明该进程中启动的模块包括 gate001 gate002 logic001

func (*TopConfig) GetProp

func (tc *TopConfig) GetProp(propname string) string

GetProp 获取名为key的命令行参数

func (*TopConfig) GetPropBool

func (tc *TopConfig) GetPropBool(propname string) bool

GetPropBool 获取bool类型,名为key的命令行参数

func (*TopConfig) GetPropInt64

func (tc *TopConfig) GetPropInt64(propname string) int64

GetPropInt64 获取int类型,名为key的命令行参数

func (*TopConfig) HasProp

func (tc *TopConfig) HasProp(key string) bool

HasProp 判断命令行参数是否携带名为key的参数

func (*TopConfig) InitFlag added in v0.1.1

func (tc *TopConfig) InitFlag()

InitFlag 初始化命令行参数

Jump to

Keyboard shortcuts

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