76 lines
2.9 KiB
Go
76 lines
2.9 KiB
Go
package config
|
||
|
||
import (
|
||
"git.hpds.cc/Component/logging"
|
||
"github.com/gammazero/workerpool"
|
||
"gopkg.in/yaml.v3"
|
||
"os"
|
||
)
|
||
|
||
var (
|
||
Cfg *TaskExecutorConfig
|
||
Logger *logging.Logger
|
||
WorkPool *workerpool.WorkerPool
|
||
)
|
||
|
||
type TaskExecutorConfig struct {
|
||
Name string `yaml:"name,omitempty"`
|
||
Mode string `yaml:"mode,omitempty"`
|
||
TmpPath string `yaml:"tmpPath"`
|
||
Store string `yaml:"store"`
|
||
TaskPoolCount int `yaml:"taskPoolCount"`
|
||
Logging LogOptions `yaml:"logging"`
|
||
Minio MinioConfig `yaml:"minio"`
|
||
Node HpdsNode `yaml:"node,omitempty"`
|
||
Functions []FuncConfig `yaml:"functions,omitempty"`
|
||
}
|
||
|
||
type MinioConfig struct {
|
||
Protocol string `yaml:"protocol"` //http or https
|
||
Endpoint string `yaml:"endpoint"`
|
||
AccessKeyId string `yaml:"accessKeyId"`
|
||
SecretAccessKey string `yaml:"secretAccessKey"`
|
||
Bucket string `yaml:"bucket"`
|
||
}
|
||
|
||
type FuncConfig struct {
|
||
Name string `yaml:"name"`
|
||
DataTag uint8 `yaml:"dataTag"`
|
||
MqType uint `yaml:"mqType"` //消息类型, 发布,1;订阅;2
|
||
}
|
||
|
||
type HpdsNode struct {
|
||
Host string `yaml:"host"`
|
||
Port int `yaml:"port"`
|
||
Token string `yaml:"token,omitempty"`
|
||
}
|
||
|
||
type LogOptions struct {
|
||
Path string `yaml:"path" json:"path" toml:"path"` // 文件保存地方
|
||
Prefix string `yaml:"prefix" json:"prefix" toml:"prefix"` // 日志文件前缀
|
||
ErrorFileSuffix string `yaml:"errorFileSuffix" json:"errorFileSuffix" toml:"errorFileSuffix"` // error日志文件后缀
|
||
WarnFileSuffix string `yaml:"warnFileSuffix" json:"warnFileSuffix" toml:"warnFileSuffix"` // warn日志文件后缀
|
||
InfoFileSuffix string `yaml:"infoFileSuffix" json:"infoFileSuffix" toml:"infoFileSuffix"` // info日志文件后缀
|
||
DebugFileSuffix string `yaml:"debugFileSuffix" json:"debugFileSuffix" toml:"debugFileSuffix"` // debug日志文件后缀
|
||
Level string `yaml:"level" json:"level" toml:"level"` // 日志等级
|
||
MaxSize int `yaml:"maxSize" json:"maxSize" toml:"maxSize"` // 日志文件大小(M)
|
||
MaxBackups int `yaml:"maxBackups" json:"maxBackups" toml:"maxBackups"` // 最多存在多少个切片文件
|
||
MaxAge int `yaml:"maxAge" json:"maxAge" toml:"maxAge"` // 保存的最大天数
|
||
Development bool `yaml:"development" json:"development" toml:"development"` // 是否是开发模式
|
||
}
|
||
|
||
func ParseConfigByFile(path string) (cfg *TaskExecutorConfig, err error) {
|
||
buffer, err := os.ReadFile(path)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
return load(buffer)
|
||
}
|
||
|
||
func load(buf []byte) (cfg *TaskExecutorConfig, err error) {
|
||
cfg = new(TaskExecutorConfig)
|
||
cfg.Functions = make([]FuncConfig, 0)
|
||
err = yaml.Unmarshal(buf, cfg)
|
||
return
|
||
}
|