diff --git a/generators/base/base.go b/generators/base/base.go index c2ac491..822471d 100644 --- a/generators/base/base.go +++ b/generators/base/base.go @@ -9,7 +9,7 @@ import ( "path" "strings" - "github.com/dizzyfool/genna/lib" + genna "github.com/dizzyfool/genna/lib" "github.com/dizzyfool/genna/model" "github.com/dizzyfool/genna/util" @@ -128,8 +128,6 @@ func AddFlags(command *cobra.Command) { flags.StringSlice(customTypesFlag, []string{}, "set custom types separated by comma\nformat: :.\nexamples: uuid:github.com/google/uuid.UUID,point:src/model.Point,bytea:string\n") flags.IntP(GoPgVer, "g", 10, "specify go-pg version (8, 9 and 10 are supported)") - - return } // ReadFlags reads basic flags from command @@ -183,7 +181,7 @@ func ReadFlags(command *cobra.Command) (conn, output, pkg string, tables []strin customTypes.Add(model.TypePGUuid, "uuid.UUID", "github.com/google/uuid") } - if gopgVer < 8 && gopgVer > 10 { + if gopgVer < 8 || gopgVer > 10 { err = fmt.Errorf("go-pg version %d not supported", gopgVer) return } diff --git a/generators/model/generator_test.go b/generators/model/generator_test.go index d167e3b..68b4eb4 100644 --- a/generators/model/generator_test.go +++ b/generators/model/generator_test.go @@ -19,7 +19,7 @@ func TestGenerator_Generate(t *testing.T) { generator.options.FollowFKs = true generator.options.CustomTypes.Add(model.TypePGUuid, "uuid.UUID", "github.com/google/uuid") generator.options.GoPgVer = 10 - //generator.options.AddJSONTag = true + // generator.options.AddJSONTag = true if err := generator.Generate(); err != nil { t.Errorf("generate error = %v", err) diff --git a/generators/search/generator_test.go b/generators/search/generator_test.go index 4faa33c..14af565 100644 --- a/generators/search/generator_test.go +++ b/generators/search/generator_test.go @@ -18,7 +18,7 @@ func TestGenerator_Generate(t *testing.T) { generator.options.Output = path.Join(os.TempDir(), "search_test.go") generator.options.FollowFKs = true generator.options.CustomTypes.Add(model.TypePGUuid, "uuid.UUID", "github.com/google/uuid") - //generator.options.AddJSONTag = true + // generator.options.AddJSONTag = true if err := generator.Generate(); err != nil { t.Errorf("generate error = %v", err) diff --git a/lib/database.go b/lib/database.go index 0e56dbf..b5be217 100644 --- a/lib/database.go +++ b/lib/database.go @@ -12,11 +12,11 @@ import ( // queryLogger helper struct for query logging type queryLogger struct { - logger log.Logger + logger *log.Logger } // newQueryLogger creates new helper struct for query logging -func newQueryLogger(logger log.Logger) queryLogger { +func newQueryLogger(logger *log.Logger) queryLogger { return queryLogger{logger: logger} } @@ -58,7 +58,7 @@ func newDatabase(url string, logger *log.Logger) (orm.DB, error) { client := pg.Connect(options) if logger != nil { - client.AddQueryHook(newQueryLogger(*logger)) + client.AddQueryHook(newQueryLogger(logger)) } return client, nil diff --git a/lib/store.go b/lib/store.go index 9526de0..3611919 100644 --- a/lib/store.go +++ b/lib/store.go @@ -49,6 +49,7 @@ func (r relation) Target() table { } type column struct { + // nolint this field is required by go-pg tableName struct{} `pg:",discard_unknown_columns"` Schema string `pg:"schema_name"` diff --git a/model/entity.go b/model/entity.go index abe001f..279d5e8 100644 --- a/model/entity.go +++ b/model/entity.go @@ -51,16 +51,12 @@ func NewEntity(schema, pgName string, columns []Column, relations []Relation) En impIndex: map[string]struct{}{}, } - if columns != nil { - for _, col := range columns { - entity.AddColumn(col) - } + for _, col := range columns { + entity.AddColumn(col) } - if relations != nil { - for _, rel := range relations { - entity.AddRelation(rel) - } + for _, rel := range relations { + entity.AddRelation(rel) } return entity diff --git a/util/texts.go b/util/texts.go index 444815e..d531976 100644 --- a/util/texts.go +++ b/util/texts.go @@ -96,7 +96,7 @@ func Underscore(s string) string { // Sanitize makes string suitable for golang var, const, field, type name func Sanitize(s string) string { rgxp := regexp.MustCompile(`[^a-zA-Z\d\-_]`) - sanitized := strings.Replace(rgxp.ReplaceAllString(s, ""), "-", "_", -1) + sanitized := strings.ReplaceAll(rgxp.ReplaceAllString(s, ""), "-", "_") if len(sanitized) != 0 && ((sanitized[0] >= '0' && sanitized[0] <= '9') || sanitized[0] == '_') { sanitized = "T" + sanitized @@ -118,7 +118,7 @@ func EntityName(s string) string { for i := ln; i >= 0; i-- { split := splitted[i] singular := Singular(split) - if strings.ToLower(singular) != strings.ToLower(split) { + if !strings.EqualFold(singular, split) { splitted[i] = strings.Title(singular) break }