Skip to content

Overriding types when directory name doesn't match package name #598

Closed
@torrayne

Description

@torrayne

When overriding a type, the name is just generated from the import path. So if the directory doesn't match the package name you will get invalid types.

Example: https://github.com/guregu/null

overrides: 
  - db_type: "varchar"
    go_type: "gopkg.in/guregu/null.v4.String"
    nullable: true

Will produce:

type Click struct {
  ID int `json:"id"`
  Code null.v4.String `json:"code"`
  DiscountCode null.v4.String `json:"discount_code"`
  Mode null.v4.String `json:"mode"`
  Language null.v4.String `json:"language"`
  Link string `json:"link"`
  Ip null.v4.String `json:"ip"`
  InsertedAt time.Time `json:"inserted_at"`
}

The package is null not null.v4. Expected null.String got null.v4.String.

Maybe something like go_package_name could be added?

In the meantime, if anyone needs JSON friendly null, you can use github.com/emvi/null

With these overrides
overrides:
  - db_type: "varchar"
    go_type: "github.com/emvi/null.String"
    nullable: true
  - db_type: "text"
    go_type: "github.com/emvi/null.String"
    nullable: true
  - db_type: "char"
    go_type: "github.com/emvi/null.String"
    nullable: true
  - db_type: "tinytext"
    go_type: "github.com/emvi/null.String"
    nullable: true
  - db_type: "mediumtext"
    go_type: "github.com/emvi/null.String"
    nullable: true
  - db_type: "longtext"
    go_type: "github.com/emvi/null.String"
    nullable: true
  - db_type: "int"
    go_type: "github.com/emvi/null.Int64"
    nullable: true
  - db_type: "integer"
    go_type: "github.com/emvi/null.Int64"
    nullable: true
  - db_type: "smallint"
    go_type: "github.com/emvi/null.Int64"
    nullable: true
  - db_type: "mediumint"
    go_type: "github.com/emvi/null.Int64"
    nullable: true
  - db_type: "bigint"
    go_type: "github.com/emvi/null.Int64"
    nullable: true
  - db_type: "year"
    go_type: "github.com/emvi/null.Int64"
    nullable: true
  - db_type: "date"
    go_type: "github.com/emvi/null.Time"
    nullable: true
  - db_type: "timestamp"
    go_type: "github.com/emvi/null.Time"
    nullable: true
  - db_type: "datetime"
    go_type: "github.com/emvi/null.Time"
    nullable: true
  - db_type: "time"
    go_type: "github.com/emvi/null.Time"
    nullable: true

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions