kis-flow/file/config_export.go

59 lines
1.3 KiB
Go
Raw Normal View History

2024-01-12 17:27:43 +08:00
package file
import (
"errors"
"fmt"
2024-03-26 14:54:50 +08:00
"github.com/aceld/kis-flow/common"
"github.com/aceld/kis-flow/kis"
2024-03-01 16:32:36 +08:00
"os"
2024-03-01 16:29:07 +08:00
"gopkg.in/yaml.v3"
2024-01-12 17:27:43 +08:00
)
// ConfigExportYaml 将flow配置输出且存储本地
func ConfigExportYaml(flow kis.Flow, savaPath string) error {
if data, err := yaml.Marshal(flow.GetConfig()); err != nil {
return err
} else {
2024-03-01 16:29:07 +08:00
// flow
2024-03-01 16:32:36 +08:00
err := os.WriteFile(savaPath+common.KisIdTypeFlow+"-"+flow.GetName()+".yaml", data, 0644)
2024-01-12 17:27:43 +08:00
if err != nil {
return err
}
2024-03-01 16:29:07 +08:00
// function
2024-01-12 17:27:43 +08:00
for _, fp := range flow.GetConfig().Flows {
fConf := flow.GetFuncConfigByName(fp.FuncName)
if fConf == nil {
return errors.New(fmt.Sprintf("function name = %s config is nil ", fp.FuncName))
}
if fdata, err := yaml.Marshal(fConf); err != nil {
return err
} else {
2024-03-01 16:32:36 +08:00
if err := os.WriteFile(savaPath+common.KisIdTypeFunction+"-"+fp.FuncName+".yaml", fdata, 0644); err != nil {
2024-01-12 17:27:43 +08:00
return err
}
}
// Connector
if fConf.Option.CName != "" {
cConf, err := fConf.GetConnConfig()
if err != nil {
return err
}
if cdata, err := yaml.Marshal(cConf); err != nil {
return err
} else {
2024-03-01 16:32:36 +08:00
if err := os.WriteFile(savaPath+common.KisIdTypeConnector+"-"+cConf.CName+".yaml", cdata, 0644); err != nil {
2024-01-12 17:27:43 +08:00
return err
}
}
}
}
}
return nil
}