mirror of
https://github.com/aceld/kis-flow.git
synced 2025-01-23 07:30:23 +08:00
58 lines
1.5 KiB
Go
58 lines
1.5 KiB
Go
|
package flow
|
|||
|
|
|||
|
import (
|
|||
|
"errors"
|
|||
|
"fmt"
|
|||
|
"kis-flow/common"
|
|||
|
)
|
|||
|
|
|||
|
// KisConnConfig KisConnector 策略配置
|
|||
|
type KisConnConfig struct {
|
|||
|
//配置类型
|
|||
|
KisType string `yaml:"kistype"`
|
|||
|
//唯一标识
|
|||
|
CId string `yaml:"cid"`
|
|||
|
//唯一描述标识
|
|||
|
CName string `yaml:"cname"`
|
|||
|
//基础存储媒介地址
|
|||
|
AddrString string `yaml:"addrs"`
|
|||
|
//存储媒介引擎类型"Mysql" "Redis" "Kafka"等
|
|||
|
Type common.KisConnType `yaml:"type"`
|
|||
|
//一次存储的标识:如Redis为Key名称、Mysql为Table名称,Kafka为Topic名称等
|
|||
|
Key string `yaml:"key"`
|
|||
|
//配置信息中的自定义参数
|
|||
|
Params map[string]string `yaml:"params"`
|
|||
|
//存储读取所绑定的NsFuncionID
|
|||
|
Load []string `yaml:"load"`
|
|||
|
Save []string `yaml:"save"`
|
|||
|
}
|
|||
|
|
|||
|
// NewConnConfig 创建一个KisConnector策略配置对象, 用于描述一个KisConnector信息
|
|||
|
func NewConnConfig(cid string, cName string, addr string, t common.KisConnType, key string, param FParam) *KisConnConfig {
|
|||
|
strategy := new(KisConnConfig)
|
|||
|
strategy.CId = cid
|
|||
|
strategy.CName = cName
|
|||
|
strategy.AddrString = addr
|
|||
|
|
|||
|
strategy.Type = t
|
|||
|
strategy.Key = key
|
|||
|
strategy.Params = param
|
|||
|
|
|||
|
return strategy
|
|||
|
}
|
|||
|
|
|||
|
// WithFunc Connector与Function进行关系绑定
|
|||
|
func (cConfig *KisConnConfig) WithFunc(fConfig *KisFuncConfig) error {
|
|||
|
|
|||
|
switch common.KisMode(fConfig.Fmode) {
|
|||
|
case common.S:
|
|||
|
cConfig.Save = append(cConfig.Save, fConfig.Fid)
|
|||
|
case common.L:
|
|||
|
cConfig.Load = append(cConfig.Load, fConfig.Fid)
|
|||
|
default:
|
|||
|
return errors.New(fmt.Sprintf("Wrong KisMode %s", fConfig.Fmode))
|
|||
|
}
|
|||
|
|
|||
|
return nil
|
|||
|
}
|