2 Star 1 Fork 1

mosache/YFrame

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
gen.go 1.75 KB
一键复制 编辑 原始数据 按行查看 历史
ヤ沒脩袮兲︶ 提交于 2023-03-14 17:52 . init
package configgen
import (
"errors"
"fmt"
"gitee.com/mosache/YFrame/tools/Y/vars"
"os"
)
const (
configTemp = `package config
import (
"gitee.com/mosache/YFrame/core/stores/mysql"
"gitee.com/mosache/YFrame/core/stores/redis"
"github.com/zeromicro/go-zero/rest"
)
var (
C Config
)
type Config struct {
rest.RestConf
Redis redis.Config
Db DBConnConfig
}
func (c Config) GetConfigs() []*mysql.Config {
cs := []*mysql.Config{
{
Host: c.Db.Main.Writer.Host,
Port: c.Db.Main.Writer.Port,
UserName: c.Db.Main.Writer.Username,
PassWord: c.Db.Main.Writer.Password,
DataBaseName: c.Db.Main.Writer.DataBaseName,
},
}
if c.Db.Main.Reader.Port != 0 {
cs = append(cs, &mysql.Config{
Host: c.Db.Main.Reader.Host,
Port: c.Db.Main.Reader.Port,
UserName: c.Db.Main.Reader.Username,
PassWord: c.Db.Main.Reader.Password,
DataBaseName: c.Db.Main.Reader.DataBaseName,
})
}
return cs
}
type DBConnConfig struct {
Main DBSourceConfig
}
type DBSourceConfig struct {
Reader DBConfig
Writer DBConfig
}
type DBSubSourceConfig struct {
Name string
}
type DBConfig struct {
Host string
Port int
Username string
Password string
DataBaseName string
}
`
)
func GenConfig() error {
if _, err := os.Stat(vars.CodeConfigDir); err != nil {
if os.IsNotExist(err) {
/// create the code config dir
err = os.MkdirAll(vars.CodeConfigDir, os.ModePerm)
if err != nil {
return err
}
/// create config.go
if err = os.WriteFile(fmt.Sprintf("%s/%s", vars.CodeConfigDir, vars.CodeConfigFileName), []byte(configTemp), os.ModePerm); err != nil {
return err
}
return nil
} else {
return err
}
}
return errors.New("config dir is ready exist")
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/mosache/YFrame.git
git@gitee.com:mosache/YFrame.git
mosache
YFrame
YFrame
v0.1.71

搜索帮助