mirror of
https://github.com/retailcrm/mg-transport-core.git
synced 2024-11-29 00:25:31 +03:00
code quality improvements
This commit is contained in:
parent
6290301815
commit
adccc7b3b6
@ -83,15 +83,15 @@ func (m *Migrate) Rollback() error {
|
|||||||
return errors.New("abnormal termination: first migration is nil")
|
return errors.New("abnormal termination: first migration is nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := m.GORMigrate.RollbackTo(m.first.ID); err == nil {
|
if err := m.GORMigrate.RollbackTo(m.first.ID); err != nil {
|
||||||
if err := m.GORMigrate.RollbackMigration(m.first); err == nil {
|
return err
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
if err := m.GORMigrate.RollbackMigration(m.first); err != nil {
|
||||||
} else {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// MigrateTo specified version
|
// MigrateTo specified version
|
||||||
@ -183,12 +183,12 @@ func (m *Migrate) Current() string {
|
|||||||
return "0"
|
return "0"
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := m.db.Last(&migrationInfo).Error; err == nil {
|
if err := m.db.Last(&migrationInfo).Error; err != nil {
|
||||||
return migrationInfo.ID
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Printf("warning => cannot fetch migration version: %s\n", err.Error())
|
fmt.Printf("warning => cannot fetch migration version: %s\n", err.Error())
|
||||||
return "0"
|
return "0"
|
||||||
|
}
|
||||||
|
|
||||||
|
return migrationInfo.ID
|
||||||
}
|
}
|
||||||
|
|
||||||
// NextFrom returns next version from passed version
|
// NextFrom returns next version from passed version
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"html/template"
|
"html/template"
|
||||||
|
|
||||||
"github.com/gin-contrib/multitemplate"
|
"github.com/gin-contrib/multitemplate"
|
||||||
|
"github.com/gobuffalo/packr/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Renderer wraps multitemplate.Renderer in order to make it easier to use
|
// Renderer wraps multitemplate.Renderer in order to make it easier to use
|
||||||
|
@ -32,45 +32,59 @@ func NewTranslationsExtractor(fileNameTemplate string) *TranslationsExtractor {
|
|||||||
func (t *TranslationsExtractor) unmarshalToMap(in []byte) (map[string]interface{}, error) {
|
func (t *TranslationsExtractor) unmarshalToMap(in []byte) (map[string]interface{}, error) {
|
||||||
var dataMap map[string]interface{}
|
var dataMap map[string]interface{}
|
||||||
|
|
||||||
if err := yaml.Unmarshal(in, &dataMap); err == nil {
|
if err := yaml.Unmarshal(in, &dataMap); err != nil {
|
||||||
return dataMap, nil
|
|
||||||
} else {
|
|
||||||
return dataMap, err
|
return dataMap, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return dataMap, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// loadYAMLBox loads YAML from box
|
// loadYAMLBox loads YAML from box
|
||||||
func (t *TranslationsExtractor) loadYAMLBox(fileName string) (map[string]interface{}, error) {
|
func (t *TranslationsExtractor) loadYAMLBox(fileName string) (map[string]interface{}, error) {
|
||||||
var dataMap map[string]interface{}
|
var (
|
||||||
|
dataMap map[string]interface{}
|
||||||
|
data []byte
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
|
||||||
if data, err := t.TranslationsBox.Find(fileName); err != nil {
|
if data, err = t.TranslationsBox.Find(fileName); err != nil {
|
||||||
return dataMap, err
|
return dataMap, err
|
||||||
} else {
|
|
||||||
return t.unmarshalToMap(data)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return t.unmarshalToMap(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
// loadYAMLFile loads YAML from file
|
// loadYAMLFile loads YAML from file
|
||||||
func (t *TranslationsExtractor) loadYAMLFile(fileName string) (map[string]interface{}, error) {
|
func (t *TranslationsExtractor) loadYAMLFile(fileName string) (map[string]interface{}, error) {
|
||||||
var dataMap map[string]interface{}
|
var (
|
||||||
|
dataMap map[string]interface{}
|
||||||
|
info os.FileInfo
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
|
||||||
if info, err := os.Stat(fileName); err == nil {
|
if info, err = os.Stat(fileName); err == nil {
|
||||||
if !info.IsDir() {
|
if !info.IsDir() {
|
||||||
if path, err := filepath.Abs(fileName); err == nil {
|
var (
|
||||||
if source, err := ioutil.ReadFile(path); err != nil {
|
path string
|
||||||
|
source []byte
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
|
||||||
|
if path, err = filepath.Abs(fileName); err != nil {
|
||||||
return dataMap, err
|
return dataMap, err
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
if source, err = ioutil.ReadFile(path); err != nil {
|
||||||
|
return dataMap, err
|
||||||
|
}
|
||||||
|
|
||||||
return t.unmarshalToMap(source)
|
return t.unmarshalToMap(source)
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return dataMap, err
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return dataMap, errors.New("directory provided instead of file")
|
return dataMap, errors.New("directory provided instead of file")
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return dataMap, err
|
return dataMap, err
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// loadYAML loads YAML from filesystem or from packr box - depends on what was configured. Can return error.
|
// loadYAML loads YAML from filesystem or from packr box - depends on what was configured. Can return error.
|
||||||
@ -106,7 +120,11 @@ func (t *TranslationsExtractor) LoadLocale(locale string) (map[string]interface{
|
|||||||
|
|
||||||
// LoadLocaleKeys returns only sorted keys from translation file
|
// LoadLocaleKeys returns only sorted keys from translation file
|
||||||
func (t *TranslationsExtractor) LoadLocaleKeys(locale string) ([]string, error) {
|
func (t *TranslationsExtractor) LoadLocaleKeys(locale string) ([]string, error) {
|
||||||
if data, err := t.LoadLocale(locale); err != nil {
|
var (
|
||||||
|
data map[string]interface{}
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
if data, err = t.LoadLocale(locale); err != nil {
|
||||||
return []string{}, err
|
return []string{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,9 +25,9 @@ import (
|
|||||||
// Utils service object
|
// Utils service object
|
||||||
type Utils struct {
|
type Utils struct {
|
||||||
IsDebug bool
|
IsDebug bool
|
||||||
|
TokenCounter uint32
|
||||||
ConfigAWS ConfigAWS
|
ConfigAWS ConfigAWS
|
||||||
Logger *logging.Logger
|
Logger *logging.Logger
|
||||||
TokenCounter uint32
|
|
||||||
slashRegex *regexp.Regexp
|
slashRegex *regexp.Regexp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user