

GitHub - brantou/emacs-go-tag: Edit field tags for golang struct fields
source link: https://github.com/brantou/emacs-go-tag
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

emacs-go-tag
Introduction
Edit field tags for golang struct fields, based on gomodifytags.
This package is inspired by GoAddTags
of vim-go and go-add-tags.
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.
It can be installed with
go get github.com/fatih/gomodifytags
Installation
Available on all major package.el
community maintained repos -
MELPA Stable and MELPA repos.
MELPA Stable is recommended as it has the latest stable version. MELPA has a development snapshot for users who don’t mind breakage but don’t want to run from a git checkout.
You can install go-tag
using the following command:
M-x package-install [RET] go-tag [RET]
or if you’d rather keep it in your dotfiles:
(unless (package-installed-p 'go-tag)
(package-refresh-contents)
(package-install 'go-tag))
If the installation doesn’t work try refreshing the package list:
M-x package-refresh-contents
Commands
If you are familiar with GoAddTags
AND GoRemoveTags
of vim-go , go-tag
you will get started quickly.
go-tag-add
:[range]go-tag-add [key],[option] [key1],[option] …
Adds field tags for the fields of a struct. If called inside a struct it automatically add field tags with the
json
key and the value automatically generated based on the field name. An error message is given if it’s called outside a struct definition or if the file is not correctly formatted.If [range] is given, only the selected fields will be changed.
The default
json
can be changed by providing one or more [key] arguments. An example of addingxml
anddb
would be::go-tag-add xml db
If [option] is passed it’ll either add a new tag with an option or will modify existing tags. An example of adding
omitempty
to alljson
fields would be::go-tag-add json,omitempty
You can define a constant value instead of the default field based value. For example the following command will add
`valid:"1"`
to all fields.:go-tag-add valid=1
go-tag-remove
:[range]go-tag-remove [key],[option] [key1],[option1] …
Rmove field tags for the fields of a struct. If called inside a struct it automatically remove all field tags. An error message is given if it’s called outside a struct definition or if the file is not correctly formatted
If [range] is given, only the selected fields will be changed.
If [key] is given, it will only remove those keys. Example:
:go-tag-remove json
If [option] is passed with a [key], it will only remove the options. Example, this will only remove
omitempty
options from fields containingjson
::go-tag-remove json,omitempty
go-tag-refresh
(Useful when designing structures):[range]go-tag-refresh [key],[option] [key1],[option] …
Equal to:
:[range]go-tag-remove [key] [key1] …
:[range]go-tag-add [key],[option] [key1],[option] …
Configuration
support the following transformations:
snakecase
:BaseDomain
->base_domain
camelcase
:BaseDomain
->baseDomain
lispcase
:BaseDomain
->base-domain
(setq go-tag-args (list "-transform" "camelcase"))
(with-eval-after-load 'go-mode
(define-key go-mode-map (kbd "C-c t") #'go-tag-add)
(define-key go-mode-map (kbd "C-c T") #'go-tag-remove))
</article
Recommend
-
169
crystal layer
-
87
inf-crystal.el Run a Inferior-Crystal process in a buffer inf-crystal provides a REPL buffer connected to a icr subprocess. It's based on ideas...
-
64
写代码时碰到这么一个需求,某个字段根据不同条件对应不同子结构体,通过interface返给前端,同时前端上传时也要通过这个字段将数据传给后端。 struct -> json这个比较好办,给interface赋值不同的子结构体即可。json -> str...
-
18
Saving a Third of Our Memory by Re-ordering Go Struct Fields By Lane Wagner on Aug 07, 2020
-
8
Copy link Contributor
-
5
Conversation Copy link Contributor...
-
10
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...
-
7
self.bump(); ...
-
11
HTTP Structured Fields for PHP bakame/http-structured-fields is a framework-agnostic PHP library that allows you to parse, serialize build and update HTTP Structured Fields in PHP according to the
-
10
Conversation ...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK