Go tool to modify struct field tags

Overview

gomodifytags

Go tool to modify/update field tags in structs. gomodifytags makes it easy to update, add or delete the tags in a struct field. You can easily add new tags, update existing tags (such as appending a new key, i.e: db, xml, etc..) or remove existing tags. It also allows you to add and remove tag options. It's intended to be used by an editor, but also has modes to run it from the terminal. Read the usage section below for more information.

gomodifytags

Install

go get github.com/fatih/gomodifytags

Supported editors

  • vim-go with :GoAddTags and :GoRemoveTags
  • go-plus (atom) with commands golang:add-tags and golang:remove-tags
  • vscode-go with commands Go: Add Tags and Go: Remove Tags
  • A (Acme) with commands addtags and rmtags
  • emacs-go-tag with commands go-tag-add and go-tag-remove

Usage

gomodifytags has multiple ways to modify a tag. Let's start with an example package:

package main

type Server struct {
	Name        string
	Port        int
	EnableLogs  bool
	BaseDomain  string
	Credentials struct {
		Username string
		Password string
	}
}

We have to first pass a file. For that we can use the -file flag:

$ gomodifytags -file demo.go
-line, -offset, -struct or -all is not passed

What are these? There are four different ways of defining which field tags to change:

  • -struct: This accepts the struct name. i.e: -struct Server. The name should be a valid type name. The -struct flag selects the whole struct, and thus it will operate on all fields.
  • -field: This accepts a field name. i.e: -field Address. Useful to select a certain field. The name should be a valid field name. The -struct flag is required.
  • -offset: This accepts a byte offset of the file. Useful for editors to pass the position under the cursor. i.e: -offset 548. The offset has to be inside a valid struct. The -offset selects the whole struct. If you need more granular option see -line
  • -line: This accepts a string that defines the line or lines of which fields should be changed. I.e: -line 4 or -line 5,8
  • -all: This is a boolean. The -all flag selects all structs of the given file.

Let's continue by using the -struct tag:

$ gomodifytags -file demo.go -struct Server
one of [-add-tags, -add-options, -remove-tags, -remove-options, -clear-tags, -clear-options] should be defined

Adding tags & options

There are many options on how you can change the struct. Let us start by adding tags. The following will add the json key to all fields. The value will be automatically inherited from the field name and transformed to snake_case:

$ gomodifytags -file demo.go -struct Server -add-tags json
package main

type Server struct {
	Name        string `json:"name"`
	Port        int    `json:"port"`
	EnableLogs  bool   `json:"enable_logs"`
	BaseDomain  string `json:"base_domain"`
	Credentials struct {
		Username string `json:"username"`
		Password string `json:"password"`
	} `json:"credentials"`
}

By default every change will be printed to stdout. So it's safe to run it and see the results of it. If you want to change it permanently, pass the -w (write) flag.

$ gomodifytags -file demo.go -struct Server -add-tags json -w

You can pass multiple keys to add tags. The following will add json and xml keys:

$ gomodifytags -file demo.go -struct Server -add-tags json,xml
package main

type Server struct {
	Name        string `json:"name" xml:"name"`
	Port        int    `json:"port" xml:"port"`
	EnableLogs  bool   `json:"enable_logs" xml:"enable_logs"`
	BaseDomain  string `json:"base_domain" xml:"base_domain"`
	Credentials struct {
		Username string `json:"username" xml:"username"`
		Password string `json:"password" xml:"password"`
	} `json:"credentials" xml:"credentials"`
}

If you prefer to use camelCase instead of snake_case for the values, you can use the -transform flag to define a different transformation rule. The following example uses the camelcase transformation rule:

$ gomodifytags -file demo.go -struct Server -add-tags json,xml -transform camelcase
package main

type Server struct {
	Name        string `json:"name" xml:"name"`
	Port        int    `json:"port" xml:"port"`
	EnableLogs  bool   `json:"enableLogs" xml:"enableLogs"`
	BaseDomain  string `json:"baseDomain" xml:"baseDomain"`
	Credentials struct {
		Username string `json:"username" xml:"username"`
		Password string `json:"password" xml:"password"`
	} `json:"credentials" xml:"credentials"`
}

Formatting tag values

By default a struct tag's value is transformed from a struct's field and used directly. As an example for the field Server string, we generate a tag in the form: json:"server" (assuming -add-tags=json is used).

However, some third party libraries use tags in a different way and might require to them to have a particular formatting, such as is the case of prefixing them (field_name=). The --template flag allows you to specify a custom format for the tag value to be applied.

$ gomodifytags -file demo.go -struct Server -add-tags gaum -template "field_name=$field" 
package main

type Server struct {
	Name        string `gaum:"field_name=name"`
	Port        int    `gaum:"field_name=port"`
	EnableLogs  bool   `gaum:"field_name=enableLogs"`
	BaseDomain  string `gaum:"field_name=baseDomain"`
}

The $field is a special keyword that is replaced by the struct tag's value after the transformation.

Transformations

We currently support the following transformations:

  • snakecase: "BaseDomain" -> "base_domain"
  • camelcase: "BaseDomain" -> "baseDomain"
  • lispcase: "BaseDomain" -> "base-domain"
  • pascalcase: "BaseDomain" -> "BaseDomain"
  • keep: keeps the original field name

You can also pass a static value for each fields. This is useful if you use Go packages that validates the struct fields or extract values for certain operations. The following example adds the json key, a validate key with the value set to gt=1 and the scope key with the value read-only:

$ gomodifytags -file demo.go -struct Server -add-tags json,validate:gt=1,scope:read-only
package main

type Server struct {
	Name        string `json:"name" validate:"gt=1" scope:"read-only"`
	Port        int    `json:"port" validate:"gt=1" scope:"read-only"`
	EnableLogs  bool   `json:"enable_logs" validate:"gt=1" scope:"read-only"`
	BaseDomain  string `json:"base_domain" validate:"gt=1" scope:"read-only"`
	Credentials struct {
		Username string `json:"username" validate:"gt=1" scope:"read-only"`
		Password string `json:"password" validate:"gt=1" scope:"read-only"`
	} `json:"credentials" validate:"gt=1" scope:"read-only"`
}

To add options to for a given key, we use the -add-options flag. In the example below we're going to add the json key and the omitempty option to all json keys:

$ gomodifytags -file demo.go -struct Server -add-tags json -add-options json=omitempty
package main

type Server struct {
	Name        string `json:"name,omitempty"`
	Port        int    `json:"port,omitempty"`
	EnableLogs  bool   `json:"enable_logs,omitempty"`
	BaseDomain  string `json:"base_domain,omitempty"`
	Credentials struct {
		Username string `json:"username,omitempty"`
		Password string `json:"password,omitempty"`
	} `json:"credentials,omitempty"`
}

If the key already exists you don't have to use -add-tags

Skipping unexported fields

By default all fields are processed. This main reason for this is to allow structs to evolve with time and be ready in case a field is exported in the future. However if you don't like this behavior, you can skip it by passing the --skip-unexported flag:

$ gomodifytags -file demo.go -struct Server -add-tags json --skip-unexported
package main

type Server struct {
        Name       string `json:"name"`
        Port       int    `json:"port"`
        enableLogs bool
        baseDomain string
}

Removing tags & options

Let's continue with removing tags. We're going to use the following simple package:

package main

type Server struct {
	Name        string `json:"name,omitempty" xml:"name,attr,cdata"`
	Port        int    `json:"port,omitempty" xml:"port,attr,cdata"`
	EnableLogs  bool   `json:"enable_logs,omitempty" xml:"enable_logs,attr,cdata"`
	BaseDomain  string `json:"base_domain,omitempty" xml:"base_domain,attr,cdata"`
	Credentials struct {
		Username string `json:"username,omitempty" xml:"username,attr,cdata"`
		Password string `json:"password,omitempty" xml:"password,attr,cdata"`
	} `json:"credentials,omitempty" xml:"credentials,attr,cdata"`
}

To remove the xml tags, we're going to use the -remove-tags flag:

$ gomodifytags -file demo.go -struct Server -remove-tags xml
package main

type Server struct {
	Name        string `json:"name"`
	Port        int    `json:"port"`
	EnableLogs  bool   `json:"enable_logs"`
	BaseDomain  string `json:"base_domain"`
	Credentials struct {
		Username string `json:"username"`
		Password string `json:"password"`
	} `json:"credentials"`
}

You can also remove multiple tags. The example below removs json and xml:

$ gomodifytags -file demo.go -struct Server -remove-tags json,xml
package main

type Server struct {
	Name        string
	Port        int
	EnableLogs  bool
	BaseDomain  string
	Credentials struct {
		Username string
		Password string
	}
}

If you want to remove all keys, we can also use the -clear-tags flag. This flag removes all tags and doesn't require to explicitly pass the key names:

$ gomodifytags -file demo.go -struct Server -clear-tags
package main

type Server struct {
	Name        string
	Port        int
	EnableLogs  bool
	BaseDomain  string
	Credentials struct {
		Username string
		Password string
	}
}

To remove any option, we can use the -remove-options flag. The following will remove all omitempty flags from the json key:

$ gomodifytags -file demo.go -struct Server -remove-options json=omitempty
package main

type Server struct {
	Name        string `json:"name" xml:"name,attr,cdata"`
	Port        int    `json:"port" xml:"port,attr,cdata"`
	EnableLogs  bool   `json:"enable_logs" xml:"enable_logs,attr,cdata"`
	BaseDomain  string `json:"base_domain" xml:"base_domain,attr,cdata"`
	Credentials struct {
		Username string `json:"username" xml:"username,attr,cdata"`
		Password string `json:"password" xml:"password,attr,cdata"`
	} `json:"credentials" xml:"credentials,attr,cdata"`
}

To remove multiple options from multiple tags just add another options:

$ gomodifytags -file demo.go -struct Server -remove-options json=omitempty,xml=cdata
package main

type Server struct {
	Name        string `json:"name" xml:"name,attr"`
	Port        int    `json:"port" xml:"port,attr"`
	EnableLogs  bool   `json:"enable_logs" xml:"enable_logs,attr"`
	BaseDomain  string `json:"base_domain" xml:"base_domain,attr"`
	Credentials struct {
		Username string `json:"username" xml:"username,attr"`
		Password string `json:"password" xml:"password,attr"`
	} `json:"credentials" xml:"credentials,attr"`
}

Lastly, to remove all options without explicitly defining the keys and names, we can use the -clear-options flag. The following example will remove all options for the given struct:

$ gomodifytags -file demo.go -struct Server -clear-options
package main

type Server struct {
	Name        string `json:"name" xml:"name"`
	Port        int    `json:"port" xml:"port"`
	EnableLogs  bool   `json:"enable_logs" xml:"enable_logs"`
	BaseDomain  string `json:"base_domain" xml:"base_domain"`
	Credentials struct {
		Username string `json:"username" xml:"username"`
		Password string `json:"password" xml:"password"`
	} `json:"credentials" xml:"credentials"`
}

Line based modification

So far all examples used the -struct flag. However we also can pass the line numbers to only change certain files. Suppose we only want to remove the tags for the Credentials struct (including the fields) for the following code (lines are included):

01  package main
02  
03  type Server struct {
04  	Name        string `json:"name" xml:"name"`
05  	Port        int    `json:"port" xml:"port"`
06  	EnableLogs  bool   `json:"enable_logs" xml:"enable_logs"`
07  	BaseDomain  string `json:"base_domain" xml:"base_domain"`
08  	Credentials struct {
09  		Username string `json:"username" xml:"username"`
10  		Password string `json:"password" xml:"password"`
11  	} `json:"credentials" xml:"credentials"`
12  }

To remove the tags for the credentials we're going to pass the -line flag:

$ gomodifytags -file demo.go -line 8,11 -clear-tags xml
package main

type Server struct {
	Name        string `json:"name" xml:"name"`
	Port        int    `json:"port" xml:"port"`
	EnableLogs  bool   `json:"enable_logs" xml:"enable_logs"`
	BaseDomain  string `json:"base_domain" xml:"base_domain"`
	Credentials struct {
		Username string
		Password string
	}
}

For removing the xml tags for certain lines, we can use the -remove-tags field. The following example will remove the xml tags for the lines 6 and 7 (fields with names of EnableLogs and BaseDomain):

$ gomodifytags -file demo.go -line 6,7 -remove-tags xml
package main

type Server struct {
	Name        string `json:"name" xml:"name"`
	Port        int    `json:"port" xml:"port"`
	EnableLogs  bool   `json:"enable_logs"`
	BaseDomain  string `json:"base_domain"`
	Credentials struct {
		Username string `json:"username" xml:"username"`
		Password string `json:"password" xml:"password"`
	} `json:"credentials" xml:"credentials"`
}

The same logic applies to adding tags or any other option as well. To add the bson tag to the lines between 5 and 7, we can use the following example:

$ gomodifytags -file demo.go -line 5,7 -add-tags bson
package main

type Server struct {
	Name        string `json:"name" xml:"name"`
	Port        int    `json:"port" xml:"port" bson:"port"`
	EnableLogs  bool   `json:"enable_logs" xml:"enable_logs" bson:"enable_logs"`
	BaseDomain  string `json:"base_domain" xml:"base_domain" bson:"base_domain"`
	Credentials struct {
		Username string `json:"username" xml:"username"`
		Password string `json:"password" xml:"password"`
	} `json:"credentials" xml:"credentials"`
}

Editor integration

Editors can use the tool by calling the tool and then either replace the buffer with the stdout or use the -w flag.

Also -line and -offset flags should be preferred to be used with editors. An editor can select a range of lines and then pass it to -line flag. The editor also can pass the offset under the cursor if it's inside the struct to -offset

Editors also can use the -format flag to output a json output with the changed lines. This is useful if you want to explicitly replace the buffer with the given lines. For the file below:

package main

type Server struct {
	Name        string
	Port        int
	EnableLogs  bool
	BaseDomain  string
	Credentials struct {
		Username string
		Password string
	}
}

If we add the xml tag and tell to output the format in json with the -format flag, the following will be printed:

$ gomodifytags -file demo.go -struct Server -add-tags xml -format json
{
  "start": 3,
  "end": 12,
  "lines": [
    "type Server struct {",
    "\tName        string `xml:\"name\"`",
    "\tPort        int    `xml:\"port\"`",
    "\tEnableLogs  bool   `xml:\"enable_logs\"`",
    "\tBaseDomain  string `xml:\"base_domain\"`",
    "\tCredentials struct {",
    "\t\tUsername string `xml:\"username\"`",
    "\t\tPassword string `xml:\"password\"`",
    "\t} `xml:\"credentials\"`",
    "}"
  ]
}

The output is defined with the following Go struct:

type output struct {
	Start int      `json:"start"`
	End   int      `json:"end"`
	Lines []string `json:"lines"`
}

The start and end specifies the positions in the file the lines will apply. With this information, you can replace the editor buffer by iterating over the lines and set it for the given range. An example how it's done in vim-go in Vimscript is:

let index = 0
for line_number in range(start, end)
  call setline(line_number, lines[index])
  let index += 1
endfor

Unsaved files

Editors can supply gomodifytags with the contents of unsaved buffers by using the -modified flag and writing an archive to stdin. Files in the archive will be preferred over those on disk.

Each archive entry consists of:

  • the file name, followed by a newline
  • the (decimal) file size, followed by a newline
  • the contents of the file

Development

At least Go v1.11.x is required. Older versions might work, but it's not recommended.

gomodifytags uses Go modules for dependency management. This means that you don't have to go get it into a GOPATH anymore. Checkout the repository:

git clone https://github.com/fatih/gomodifytags.git

Start developing the code. To build a binary, execute:

GO111MODULE=on go build -mod=vendor

This will create a gomodifytags binary in the current directory. To test the package, run the following:

GO111MODULE=on go test -v -mod=vendor

If everything works fine, feel free to open a pull request with your changes.

Issues
  • Cannot modify tags: invalid line directive found

    Cannot modify tags: invalid line directive found

    Committer: GitHub [email protected] 2019-07-16 15:06:38 is normal.

    Committer: Fatih Arslan [email protected] 2019-08-12 17:45:01 prompt´╝Ü

    Cannot modify tags: invalid line directive found

    type BillStatQuery struct {
    	BuildingId string
    	SearchKey  string
    	Floor      int
    	RoomId     string
    }
    
    bug 
    opened by imkos 18
  • Wrong output when the file isn't gofmt'd

    Wrong output when the file isn't gofmt'd

    With the following file:

    $ cat tags.go
    package a
    type x struct {
        Foo int
        bar int
    }
    

    The tool gives the wrong results.

    Should be start=2:

    $ gomodifytags -format json -file tags.go -transform snakecase -line 3,4 -add-tags json -add-options json=
    {
      "start": 3,
      "end": 4,
      "lines": [
        "type x struct {",
        "\tFoo int `json:\"foo\"`"
      ]
    }
    

    Should be start=2, and one line is missing from the output:

    $ gomodifytags -format json -file tags.go -transform snakecase -line 3,3 -add-tags json -add-options json=
    {
      "start": 3,
      "end": 3,
      "lines": [
        "type x struct {"
      ]
    }
    

    start is correct, but the last line (}) missing:

    $ gomodifytags -format json -file tags.go -transform snakecase -offset 23 -add-tags json -add-options json=
    {
      "start": 2,
      "end": 5,
      "lines": [
        "",
        "type x struct {",
        "\tFoo int `json:\"foo\"`",
        "\tbar int `json:\"bar\"`"
      ]
    }
    

    It seems that the tool operates on the file as if they're gofmt'd.

    opened by arp242 7
  • Formatting tag values $field not generated

    Formatting tag values $field not generated

    I'm trying to generate with formatting tag values with -template. And I got null $field.

    script executed:

    gomodifytags -file purchase.go -all -add-tags gorm --template "column:$field" -w
    

    result:

    type PurchaseModel struct {
            BaseField         `json:",inline" gorm:"column:"`
            Code              string `json:"code,omitempty" gorm:"column:"`
            RefOrderId        string `json:"ref_order_id,omitempty" gorm:"column:"`
            Date              string `json:"date,omitempty" gorm:"column:"`
            Status            string `json:"status,omitempty" gorm:"column:"`
            PaymentStatus     string `json:"payment_status,omitempty" gorm:"column:"`
            InvoiceNumber     string `json:"invoice_number,omitempty" gorm:"column:"`
            InvoiceDate       string `json:"invoice_date,omitempty" gorm:"column:"`
            InvoiceDueDate    string `json:"invoice_due_date,omitempty" gorm:"column:"`
            InvoiceTotalPrice string `json:"invoice_total_price,omitempty" gorm:"column:"`
    }
    

    result gorm:"column:" should be gorm:"column:code"

    please help, Thanks

    opened by kecci 6
  • New Add/Remove prefix option

    New Add/Remove prefix option

    Some libraries like the gorm ORM or the gaum SQL query builder use a prefix in the tag name (ie gorm:"column:struct_field", gaum:"field_name=struct_field") to help ther Scanner/Valuer interact with the sql library in go. This PR adds the ability to add and remove said prefixes. I used these two libraries as samples in the tests files to help understand the rationale behind said feature to people reading without context, hopefully this doesn't break any project convention.

    opened by perrito666 5
  • anonymous structs?

    anonymous structs?

    Is there support for anonymous structs? gomodifytags doesn't seem to work on anonymous structs.

    Here's an example:

    Running gomodifytags -file main.go -line 7,9 -add-tags json returns selection is not inside a struct

    package main
    
    import "fmt"
    
    func main() {
    	anon := []struct {
    		ID int
    		A  string
    		B  string
    	}{}
    
    	fmt.Println(anon)
    }
    
    enhancement 
    opened by braindev 5
  • Different tags use different transforms

    Different tags use different transforms

    A tag on a struct uses the same transforms, and I want to use separate transforms for each tag.

    AppDeploymentServerModuleConfig struct {
    		ID                    int    `json:"id" gorm:"id"`
    		AppDeploymentConfigID int    `json:"appDeploymentConfigID" gorm:"app_deployment_config_id"`
    
    }
    

    json use camelcase transforms, gorm use snakecase transforms

    wontfix 
    opened by zhaogaolong 4
  • Embedded struct can not be used with -transform camelcase

    Embedded struct can not be used with -transform camelcase

    type PDetail struct {
    	PSummary //will cause problem
    	Thumbnail             string `json:"thumbnail"`
    }
    
     W
    panic: runtime error: index out of range
    
    goroutine 1 [running]:
    main.(*config).addTags(0xc4200a4200, 0x0, 0x0, 0xc4200e74e0, 0x0, 0x100eda8, 0x20)
            /Users/ / /go/src/github.com/fatih/gomodifytags/main.go:351 +0x8a5
    
    opened by davyzhang 4
  • Add

    Add "Title Case" option

    This is just a continue from this PR, anant-barlota seems to be inactive. Addressing https://github.com/fatih/gomodifytags/pull/66#discussion_r460717316 and fixed conflicts issue #65

    opened by SirUela 3
  • Adding Title Case to the list of supported cases

    Adding Title Case to the list of supported cases

    Hi, I was wondering if we could add an additional option of 'Title Case'. I came across its usefulness while adding csv tags to my structs.

    I've written a simple code fix for it, but I'm unable to push the branch to this repo. I would appreciate any feedback on this.

    opened by anant-barlota 3
  • Unexported embedded struct with skip-unexported option is still tagged

    Unexported embedded struct with skip-unexported option is still tagged

    Input:

    type stationEvent struct{}
    
    type StationConnectorUnplugged struct {
    	stationEvent
    	ConnectorID    int
    	MeterStop      int
    	TransactionID  int32
    	ChargingCardID identifier.ChargingCardID
    	Timestamp      time.Time `json:"timestamp`
    }
    

    Output:

    type stationEvent struct{}
    
    type StationConnectorUnplugged struct {
            stationEvent   `json:"stationEvent"`
            ConnectorID    int                       `json:"connectorID"`
            MeterStop      int                       `json:"meterStop"`
            TransactionID  int32                     `json:"transactionID"`
            ChargingCardID identifier.ChargingCardID `json:"chargingCardID"`
            Timestamp      time.Time                 `json:"timestamp`
    }
    

    Expected:

    type stationEvent struct{}
    
    type StationConnectorUnplugged struct {
            stationEvent
            ConnectorID    int                       `json:"connectorID"`
            MeterStop      int                       `json:"meterStop"`
            TransactionID  int32                     `json:"transactionID"`
            ChargingCardID identifier.ChargingCardID `json:"chargingCardID"`
            Timestamp      time.Time                 `json:"timestamp`
    }
    
    opened by eduhenke 3
  • Add new

    Add new "skip-private" option

    Really we never need JSON tags for private fields So this is such an option

    For example you may have following struct

    type Struct struct {
        Public  int
        private int
    }
    

    Currently gomodifytags would add these tags

    type Struct struct {
        Public  int `json:"public"`
        private int `json:"private"`
    }
    

    With new option it would add

    type Struct struct {
        Public  int `json:"public"`
        private int
    }
    
    opened by igrmk 3
  • Override flag defaults with a config file

    Override flag defaults with a config file

    I'd like to have the ability to change the defaults of the executable, e.g. to make the default transformation be camelCase instead of snake_case.

    My proposal would be to introduce a config file (e.g. ~/.config/gomodifytags/config) where you could override default flag values.

    opened by tomasger 0
  • copy tag value and options

    copy tag value and options

    I wonder if its possible and I'm missing something, or if it is something that you might want to accept as a PR.

    tl;dr: I want to copy all yaml tag options and names to json

    so, in:

    package main
    
    type Foo struct {
      Bar string `yaml:"bar,omitempty"`
    }
    

    out:

    package main
    
    type Foo struct {
      Bar string `yaml:"bar,omitempty" json:"bar,omitempty"`
    }
    

    is there a good way to do that with the current gomodifytags version?

    opened by caarlos0 1
  • Unable to install gomodifytags tool on VS Code

    Unable to install gomodifytags tool on VS Code

    I have been unable to download and install the gomodifytags package automatically via the install all option and when I attempt to do it manually via the go install github.com/fatih/[email protected] command, I get the following as feedback:

    # github.com/fatih/gomodifytags
    C:\Program Files\Go\pkg\tool\windows_amd64\link.exe: C:\Users\IAN\AppData\Local\go-build\7e\7ead9b6fbf2293b80b2d0531d108001d1e31a4fd463224b9b481fc70392a1baa-d: not package main
    

    How can I resolve this challenge?

    opened by IanoNjuguna 0
  • Extract gomodifytags into a library

    Extract gomodifytags into a library

    This PR moves the gomodifytags tool into its package to be imported by other applications (i.e.: gopls). It's currently deliberately put under internal, as I want to make sure it meets the needs of others.

    related: https://github.com/golang/vscode-go/issues/2002

    opened by fatih 0
  • Unable to add static tag value with comma.

    Unable to add static tag value with comma.

    Is it somehow possible to add tags with comma eg. with mapstructure:

    type Friend struct {
        Person `mapstructure:",squash"`
    }
    

    I tried this but then squash is treated as the next tag token, maybe I'm missing something? :)

    opened by jozuenoon 0
  • Feature Request: regex based modification

    Feature Request: regex based modification

    for example:

    gomodifytags bla.go -w -field-regex '.*Id' -add-options json=string
    gomodifytags bla.go -w -field-regex '.*At' -add-options json=string
    

    those will modify only fields that ends with Id or At

    opened by kokizzu 0
Releases(v1.16.0)
  • v1.16.0(Sep 22, 2021)

    This release introduces a new titlecase transformation option. By passing the --transform titlecase flag, gomodifytags will transform the tags in the form of:

    "BaseDomain"` -> `"Base Domain"
    

    See related issue https://github.com/fatih/gomodifytags/issues/65 and the PR introducing this change: https://github.com/fatih/gomodifytags/pull/87

    Source code(tar.gz)
    Source code(zip)
  • v1.15.0(Sep 17, 2021)

    This release adds the new --quiet flag. When passed, gomodifytags won't output the results to stdout. This flag might be helpful for users who use gomodifytags for scripting in conjunction with the -w flag.

    Changes: https://github.com/fatih/gomodifytags/pull/86

    Source code(tar.gz)
    Source code(zip)
  • v1.14.0(Aug 25, 2021)

    This release changes the special keyword to format tag values from $field to {field}. It fixes the issue described in:

    https://github.com/fatih/gomodifytags/issues/76

    Changes included in this release are: https://github.com/fatih/gomodifytags/pull/85

    Source code(tar.gz)
    Source code(zip)
  • v1.13.0(Nov 4, 2020)

    This release includes the changes from the PR: https://github.com/fatih/gomodifytags/pull/64 gomodifytags handles now the following cases:

    • anonymous structs as function parameters
    func test(arg struct {
     	Field int `json:"field"`
     }) {
     }
    
    • "pointer to struct" type declaration
    var x *struct {
     	Field int `json:"field"`
     }
    
    • "array of struct" type declaration
    var x []struct {
     	Field int
     }
    

    and nested variants : "array of pointers to array of structs".

    Source code(tar.gz)
    Source code(zip)
  • v1.12.0(Oct 25, 2020)

    This release uses flag.CommandLine.Parse() instead of flag.Parse() to check for errors during flag parsing. This let us catch re-defined flag names.

    Related changes: https://github.com/fatih/gomodifytags/pull/75

    Source code(tar.gz)
    Source code(zip)
  • v1.11.0(Oct 22, 2020)

    The flag --format was already in use. v1.10.0 introduced a new feature that also provided the --format flag. This releases changes the flag to --template.

    PR: https://github.com/fatih/gomodifytags/pull/74

    Source code(tar.gz)
    Source code(zip)
  • v1.10.0(Oct 22, 2020)

    This release includes a new --format flag to change a struct tag's values based on the field name. This allows us to generate custom struct tags that don't follow the standard definition listed in https://golang.org/pkg/reflect/#StructTag. For a concrete example checkout the readme: https://github.com/fatih/gomodifytags#formatting-tag-values

    Includes the changes from PR: https://github.com/fatih/gomodifytags/pull/69

    Source code(tar.gz)
    Source code(zip)
  • v1.9.0(Oct 12, 2020)

  • v1.8.0(Oct 12, 2020)

  • v1.7.0(Oct 5, 2020)

    This release includes the new -field flag to modify a single field. It only works in conjunction with the -struct field and is a way to use gomodifytags from the terminal. Editors modify tags based on offset and are capable of editing single fields, hence they don't need this flag.

    PR: https://github.com/fatih/gomodifytags/pull/68

    Source code(tar.gz)
    Source code(zip)
  • v1.6.0(May 13, 2020)

    This releases fixes the case where gomodifytags would skip embedded unexported fields, even if -skip-unexported was enabled. Changes: https://github.com/fatih/gomodifytags/pull/62

    Source code(tar.gz)
    Source code(zip)
  • v1.5.0(May 12, 2020)

    Includes the new -all selection flag which can be used to select all structs in a given file. Changes: https://github.com/fatih/gomodifytags/pull/61

    Source code(tar.gz)
    Source code(zip)
  • v1.4.0(Apr 2, 2020)

  • v1.3.0(Feb 26, 2020)

  • v1.2.0(Jan 19, 2020)

    Includes the following change:

    • Rename the --skip-private flag to --skip-unexported to use the usual Go nomenclature https://github.com/fatih/gomodifytags/pull/54
    Source code(tar.gz)
    Source code(zip)
  • v1.1.0(Jan 17, 2020)

    A new --skip-private option has been added to skip private fields. By default it's disabled. https://github.com/fatih/gomodifytags/pull/53

    Source code(tar.gz)
    Source code(zip)
  • v1.0.1(Sep 4, 2019)

  • v1.0.0(Aug 6, 2019)

    gomodifytags is now in a good shape with a good feature set. Let's start tagging the release, which also sets the ground for future releases.

    Source code(tar.gz)
    Source code(zip)
Owner
Fatih Arslan
Software Engineer. Gopher and Coffee geek. Creator of vim-go. Tool maker.
Fatih Arslan
Copier for golang, copy value from struct to struct and more

Copier I am a copier, I copy everything from one to another Features Copy from field to field with same name Copy from method to field with same name

Jinzhu 3.4k Aug 6, 2022
Access and modify property values in deeply nested maps, using dot-separated paths

Dig lets you access and modify property values in deeply nested, unstructured maps, using dot-separated paths: source := make(map[string]interface{})

Preslav Rachev 12 May 7, 2022
Postgres uuid[] field for gorm.io - Golang

Postgres uuid[] field for gorm.io - Golang

Jeoga - Ubgo 2 Jan 17, 2022
gormuuid array field example

gormuuid - Examples An testing repo for https://github.com/ubgo/gormuuid module How to test Install the postgres and create a new database testdb Upda

Examples 2 Oct 20, 2021
A Runtime Struct Builder for Go

A Runtime Struct Builder for Go

null 31 Jul 8, 2022
Robust & Easy to use struct mapper and utility methods for Go

go-model Robust & Easy to use model mapper and utility methods for Go struct. Typical methods increase productivity and make Go development more fun ?

Jeevanandam M. 356 Aug 8, 2022
gin struct controller

gin struct controller

null 1 Oct 4, 2021
Tugas Alta Immersive Backend Golang Fundamental Programming (Pointer, Struct, Method, Interface)

Tatacara Melakukan Setup Tugas clone project ini dengan cara git clone https://github.com/Immersive-Backend-Resource/Pointer-Struct-Method-Interface.g

null 0 Jan 9, 2022
Highly configurable struct to map converter.

Mapify Highly configurable struct to map converter. Will convert maps into other maps as well (work in progress). Features configuration outside the s

Jacek Olszak 2 Jul 30, 2022
efaceconv - Code generation tool for high performance conversion from interface{} to immutable type without allocations.

efaceconv High performance conversion from interface{} to immutable types without additional allocations This is tool for go generate and common lib (

Ivan 50 May 14, 2022
GoWrap is a command line tool for generating decorators for Go interfaces

GoWrap GoWrap is a command line tool that generates decorators for Go interface types using simple templates. With GoWrap you can easily add metrics,

Max Chechel 640 Aug 12, 2022
Perforator is a tool for recording performance metrics over subregions of a program using the Linux "perf" interface.

Perforator Perforator is a tool for recording performance metrics over subregions of a program (e.g., functions) using the Linux "perf" interface.

Zachary Yedidia 33 May 5, 2022
a tool for creating exploited media files for discord

Discord-Exploits A program for creating exploited media files for discord written in Go. Usage discord-exploits is a command line utility, meaning you

schmenn 219 Dec 29, 2021
A full-featured license tool to check and fix license headers and resolve dependencies' licenses.

SkyWalking Eyes A full-featured license tool to check and fix license headers and resolve dependencies' licenses. Usage You can use License-Eye in Git

The Apache Software Foundation 147 Aug 9, 2022
sigurls is a reconnaissance tool, it fetches URLs from AlienVault's OTX, Common Crawl, URLScan, Github and the Wayback Machine.

sigurls is a reconnaissance tool, it fetches URLs from AlienVault's OTX, Common Crawl, URLScan, Github and the Wayback Machine. DiSCLAIMER: fe

Alex Munene 128 May 22, 2021
A tool and library for using structural regular expressions.

Structural Regular Expressions sregx is a package and tool for using structural regular expressions as described by Rob Pike (link).

Zachary Yedidia 37 Jul 22, 2022
TUI grep tool respect for IntelliJ

ilse TUI grep tool respect for IntelliJ Requirements ripgrep for fast grep bat for beautiful preview Features support HeadMatch(FirstMatch), WordMatch

momochi29 34 Apr 22, 2022
A tool to check problems about meta files of Unity

A tool to check problems about meta files of Unity on Git repositories, and also the tool can do limited autofix for meta files of auto-generated files.

DeNA 60 Jun 24, 2022
A tool to find redirection chains in multiple URLs

UnChain A tool to find redirection chains in multiple URLs Introduction UnChain automates process of finding and following `30X` redirects by extracti

RedCode Labs 79 Aug 2, 2022