mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-23 09:00:20 +08:00
parent
7954ad3759
commit
97c7835d9e
@ -3,7 +3,6 @@ package config
|
|||||||
import (
|
import (
|
||||||
_ "embed"
|
_ "embed"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@ -19,12 +18,8 @@ const (
|
|||||||
configFile = "goctl.yaml"
|
configFile = "goctl.yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
//go:embed default.yaml
|
||||||
//go:embed default.yaml
|
var defaultConfig []byte
|
||||||
defaultConfig []byte
|
|
||||||
|
|
||||||
ExternalConfig *External
|
|
||||||
)
|
|
||||||
|
|
||||||
// Config defines the file naming style
|
// Config defines the file naming style
|
||||||
type (
|
type (
|
||||||
@ -77,14 +72,13 @@ func NewConfig(format string) (*Config, error) {
|
|||||||
return cfg, err
|
return cfg, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func GetExternalConfig() (*External, error) {
|
||||||
var cfg External
|
var cfg External
|
||||||
err := loadConfig(&cfg)
|
err := loadConfig(&cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
return nil, err
|
||||||
} else {
|
|
||||||
ExternalConfig = &cfg
|
|
||||||
}
|
}
|
||||||
|
return &cfg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadConfig(cfg *External) error {
|
func loadConfig(cfg *External) error {
|
||||||
|
@ -258,10 +258,12 @@ func ConvertStringDataType(dataBaseType string, isDefaultNull, unsigned, strict
|
|||||||
}
|
}
|
||||||
|
|
||||||
func convertDatatypeWithConfig(dataBaseType string, isDefaultNull, unsigned bool) (string, string) {
|
func convertDatatypeWithConfig(dataBaseType string, isDefaultNull, unsigned bool) (string, string) {
|
||||||
if config.ExternalConfig == nil {
|
externalConfig, err := config.GetExternalConfig()
|
||||||
|
if err != nil {
|
||||||
return "", ""
|
return "", ""
|
||||||
}
|
}
|
||||||
opt, ok := config.ExternalConfig.Model.TypesMap[strings.ToLower(dataBaseType)]
|
|
||||||
|
opt, ok := externalConfig.Model.TypesMap[strings.ToLower(dataBaseType)]
|
||||||
if !ok || (len(opt.Type) == 0 && len(opt.UnsignedType) == 0 && len(opt.NullType) == 0) {
|
if !ok || (len(opt.Type) == 0 && len(opt.UnsignedType) == 0 && len(opt.NullType) == 0) {
|
||||||
return "", ""
|
return "", ""
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user