1 Star 0 Fork 0

conding/reverse

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
model.go 2.11 KB
一键复制 编辑 原始数据 按行查看 历史
package conf
import (
"errors"
"io"
"os"
"gopkg.in/yaml.v3"
)
// ReverseConfig represents a reverse configuration
type ReverseConfig struct {
Kind string `yaml:"kind"`
Name string `yaml:"name"`
Source ReverseSource `yaml:"source"`
Targets []ReverseTarget `yaml:"targets"`
}
// NewReverseConfigFromYAML parse config yaml and return it. support multiple yaml document in one file.
func NewReverseConfigFromYAML(path string) ([]*ReverseConfig, error) {
ret := make([]*ReverseConfig, 0)
file, err := os.Open(path)
if err != nil {
return nil, err
}
defer file.Close()
decoder := yaml.NewDecoder(file)
for {
item := new(ReverseConfig)
err = decoder.Decode(&item)
if errors.Is(err, io.EOF) {
// read last document
break
}
if item == nil {
// empty document
continue
}
if err != nil {
// other error
return nil, err
}
ret = append(ret, item)
}
return ret, nil
}
// ReverseSource represents a reverse source which should be a database connection
type ReverseSource struct {
Database string `yaml:"database"`
ConnStr string `yaml:"conn_str"`
}
// ReverseTarget represents a reverse target
type ReverseTarget struct {
Type string `yaml:"type"`
IncludeTables []string `yaml:"include_tables"`
ExcludeTables []string `yaml:"exclude_tables"`
TableMapper string `yaml:"table_mapper"`
ColumnMapper string `yaml:"column_mapper"`
TemplatePath string `yaml:"template_path"`
Template string `yaml:"template"`
MultipleFiles bool `yaml:"multiple_files"`
OutputDir string `yaml:"output_dir"`
TablePrefix string `yaml:"table_prefix"`
Language string `yaml:"language"`
TableName bool `yaml:"table_name"`
ColumnName bool `yaml:"column_name"`
Funcs map[string]string `yaml:"funcs"`
Formatter string `yaml:"formatter"`
Importter string `yaml:"importter"`
ExtName string `yaml:"ext_name"`
Created string `yaml:"created"`
Updated string `yaml:"updated"`
Deleted string `yaml:"deleted"`
Version string `yaml:"version"`
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/conding/reverse.git
git@gitee.com:conding/reverse.git
conding
reverse
reverse
v0.2.0

搜索帮助