代码拉取完成,页面将自动刷新
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")
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。