support foreign key.添加 外键支持
This commit is contained in:
@@ -4,12 +4,13 @@ import "fmt"
|
||||
|
||||
// Config custom config struct
|
||||
type Config struct {
|
||||
CfgBase
|
||||
MySQLInfo MysqlDbInfo `toml:"mysql_info"`
|
||||
OutDir string `toml:"out_dir"`
|
||||
Simple bool `toml:"simple"`
|
||||
IsJSONTag bool `toml:"isJsonTag"`
|
||||
SingularTable bool `toml:"singular_table"`
|
||||
CfgBase `yaml:"base"`
|
||||
MySQLInfo MysqlDbInfo `yaml:"mysql_info"`
|
||||
OutDir string `yaml:"out_dir"`
|
||||
Simple bool `yaml:"simple"`
|
||||
IsJSONTag bool `yaml:"is_json_tag"`
|
||||
SingularTable bool `yaml:"singular_table"`
|
||||
IsForeignKey bool `yaml:"is_foreign_key"`
|
||||
}
|
||||
|
||||
// MysqlDbInfo mysql database information. mysql 数据库信息
|
||||
@@ -71,3 +72,13 @@ func GetSimple() bool {
|
||||
func GetIsJSONTag() bool {
|
||||
return _map.IsJSONTag
|
||||
}
|
||||
|
||||
// GetIsForeignKey if is foreign key
|
||||
func GetIsForeignKey() bool {
|
||||
return _map.IsForeignKey
|
||||
}
|
||||
|
||||
// SetForeignKey Set if is foreign key.设置是否外键关联
|
||||
func SetForeignKey(b bool) {
|
||||
_map.IsForeignKey = b
|
||||
}
|
||||
|
||||
@@ -2,20 +2,20 @@ package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/xxjwxc/public/dev"
|
||||
"github.com/xxjwxc/public/tools"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
// CfgBase base config struct
|
||||
type CfgBase struct {
|
||||
SerialNumber string `json:"serial_number" toml:"serial_number"` // version.版本号
|
||||
ServiceName string `json:"service_name" toml:"service_name"` // service name .service名字
|
||||
ServiceDisplayname string `json:"service_displayname" toml:"service_displayname"` // display name .显示名
|
||||
SerciceDesc string `json:"sercice_desc" toml:"sercice_desc"` // sercice desc .service描述
|
||||
IsDev bool `json:"is_dev" toml:"is_dev"` // Is it a development version?是否是开发版本
|
||||
SerialNumber string `json:"serial_number" yaml:"serial_number"` // version.版本号
|
||||
ServiceName string `json:"service_name" yaml:"service_name"` // service name .service名字
|
||||
ServiceDisplayname string `json:"service_displayname" yaml:"service_displayname"` // display name .显示名
|
||||
SerciceDesc string `json:"sercice_desc" yaml:"sercice_desc"` // sercice desc .service描述
|
||||
IsDev bool `json:"is_dev" yaml:"is_dev"` // Is it a development version?是否是开发版本
|
||||
}
|
||||
|
||||
var _map = Config{}
|
||||
@@ -27,7 +27,7 @@ func init() {
|
||||
|
||||
func onInit() {
|
||||
path := tools.GetModelPath()
|
||||
err := InitFile(path + "/config.toml")
|
||||
err := InitFile(path + "/config.yml")
|
||||
if err != nil {
|
||||
fmt.Println("InitFile: ", err.Error())
|
||||
return
|
||||
@@ -36,7 +36,11 @@ func onInit() {
|
||||
|
||||
// InitFile default value from file .
|
||||
func InitFile(filename string) error {
|
||||
if _, err := toml.DecodeFile(filename, &_map); err != nil {
|
||||
bs, err := ioutil.ReadFile(filename)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := yaml.Unmarshal(bs, &_map); err != nil {
|
||||
fmt.Println("read toml error: ", err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -7,6 +7,23 @@ import (
|
||||
|
||||
const (
|
||||
testFile = `
|
||||
serial_number : "1.0" #版本号
|
||||
service_name : #服务名
|
||||
service_displayname : #服务显示名
|
||||
sercice_desc : #服务描述
|
||||
is_dev : false # 是否开发者模式
|
||||
out_dir : ./db # 输出目录
|
||||
singular_table : false # 单表模式:true:禁用表名复数,false:采用表明复数 参考:gorm.SingularTable
|
||||
simple : true #简单输出
|
||||
isJsonTag : true #是否打json标记
|
||||
mysql_info:
|
||||
host : 127.0.0.1
|
||||
port : 3306
|
||||
username : root
|
||||
password : qwer
|
||||
database : oauth_db
|
||||
|
||||
|
||||
`
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user