This commit is contained in:
kesonan 2024-06-04 18:26:34 +08:00 committed by GitHub
parent 7954ad3759
commit 97c7835d9e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 13 deletions

View File

@ -3,7 +3,6 @@ package config
import (
_ "embed"
"errors"
"fmt"
"os"
"path/filepath"
"strings"
@ -19,12 +18,8 @@ const (
configFile = "goctl.yaml"
)
var (
//go:embed default.yaml
defaultConfig []byte
ExternalConfig *External
)
//go:embed default.yaml
var defaultConfig []byte
// Config defines the file naming style
type (
@ -77,14 +72,13 @@ func NewConfig(format string) (*Config, error) {
return cfg, err
}
func init() {
func GetExternalConfig() (*External, error) {
var cfg External
err := loadConfig(&cfg)
if err != nil {
fmt.Println(err.Error())
} else {
ExternalConfig = &cfg
return nil, err
}
return &cfg, nil
}
func loadConfig(cfg *External) error {

View File

@ -258,10 +258,12 @@ func ConvertStringDataType(dataBaseType string, isDefaultNull, unsigned, strict
}
func convertDatatypeWithConfig(dataBaseType string, isDefaultNull, unsigned bool) (string, string) {
if config.ExternalConfig == nil {
externalConfig, err := config.GetExternalConfig()
if err != nil {
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) {
return "", ""
}