kis-flow/config/kis_conn_config.go

49 lines
1.6 KiB
Go
Raw Permalink Normal View History

2023-12-31 15:26:53 +08:00
package config
2023-12-31 11:45:47 +08:00
import (
"fmt"
2024-04-16 15:11:23 +08:00
2024-03-26 14:54:50 +08:00
"github.com/aceld/kis-flow/common"
2023-12-31 11:45:47 +08:00
)
2024-04-15 17:50:02 +08:00
// KisConnConfig describes the KisConnector strategy configuration
2023-12-31 11:45:47 +08:00
type KisConnConfig struct {
2024-04-15 17:50:02 +08:00
KisType string `yaml:"kistype"` // Configuration type
CName string `yaml:"cname"` // Unique descriptive identifier
AddrString string `yaml:"addrs"` // Base storage medium address
Type common.KisConnType `yaml:"type"` // Storage medium engine type: "Mysql", "Redis", "Kafka", etc.
Key string `yaml:"key"` // Identifier for a single storage: Key name for Redis, Table name for Mysql, Topic name for Kafka, etc.
Params map[string]string `yaml:"params"` // Custom parameters in the configuration information
// NsFuncionID bound to storage reading
2023-12-31 11:45:47 +08:00
Load []string `yaml:"load"`
Save []string `yaml:"save"`
}
2024-04-15 17:50:02 +08:00
// NewConnConfig creates a KisConnector strategy configuration object, used to describe a KisConnector information
func NewConnConfig(cName string, addr string, t common.KisConnType, key string, param map[string]string) *KisConnConfig {
2023-12-31 11:45:47 +08:00
strategy := new(KisConnConfig)
strategy.CName = cName
strategy.AddrString = addr
strategy.Type = t
strategy.Key = key
strategy.Params = param
return strategy
}
2024-04-15 17:50:02 +08:00
// WithFunc binds Connector to Function
2023-12-31 11:45:47 +08:00
func (cConfig *KisConnConfig) WithFunc(fConfig *KisFuncConfig) error {
2024-01-03 10:16:54 +08:00
switch common.KisMode(fConfig.FMode) {
2023-12-31 11:45:47 +08:00
case common.S:
2024-01-03 10:16:54 +08:00
cConfig.Save = append(cConfig.Save, fConfig.FName)
2023-12-31 11:45:47 +08:00
case common.L:
2024-01-03 10:16:54 +08:00
cConfig.Load = append(cConfig.Load, fConfig.FName)
2023-12-31 11:45:47 +08:00
default:
2024-04-15 17:50:02 +08:00
return fmt.Errorf("Wrong KisMode %s", fConfig.FMode)
2023-12-31 11:45:47 +08:00
}
return nil
}