fatih / gomodifytags Goto Github PK
View Code? Open in Web Editor NEWGo tool to modify struct field tags
License: BSD 3-Clause "New" or "Revised" License
Go tool to modify struct field tags
License: BSD 3-Clause "New" or "Revised" License
I create an emacs-plugin named emacs-go-tag.
This package builds ongomodifytags and is used to edit field tags for golang struct fields.
This package is inspired by GoAddTags of vim-go and go-add-tags.
gomodifytags -file test.go -struct PostReviewProcess -field Id --add-tags gorm -w
We can specify the field option to support modifying the tag of the specific field of the structure?
in structSelection function: add codes like below:
// struct selects all lines inside a struct
start := c.fset.Position(encStruct.Pos()).Line
end := c.fset.Position(encStruct.End()).Line
if c.fieldName!=""{
for i:=0;i<len(encStruct.Fields.List);i++{
f:=encStruct.Fields.List[i]
if len(f.Names)>0{
if f.Names[0].Name==c.fieldName{
start=c.fset.Position(f.Pos()).Line
end=start
break
}
}
}
}
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
}
It would be nice if this tool could accept modified files on stdin instead of requiring editors to save them off as temp files.
I would recommend using the same archive format as guru
and gogetdoc
, which has a parser in the go/buildutil
package.
The changes should be pretty straightforward:
-modified
flag, and if present, use buildutil.ParseOverlayArchive
to read the archive from stdinsrc
argument of parser.ParseFile
With these updates, you'll be able to remove the temp files from vim-go and reuse the same code you already use for guru
and gogetdoc
.
I'm happy to take a stab at implementing these changes if you agree with the idea.
While trying to run gomodifytags
with -modified
flag on a test file, we get the below error:
"failed to parse -modified archive: parsing size of archive file .: strconv.ParseUint: parsing "}": invalid syntax"
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?
In the below example, lines from 61(start) to 66(end): 6 lines in total are expected to be in the output.
But the 7th line: line 67 (with just the }
)makes it to the output as well.
You can see this in the example in the README as well
{
"start": 4,
"end": 11,
"lines": [
"\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\"`",
"}"
]
}
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/gomodifytags@latest
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?
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.
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`
}
Hi,
Would it be possible to add support for lisp-case, where the words are separated by hyphens?
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.
As a result of this go-plus
Atom package doesn't install properly.
$ go version
go version go1.8.3 linux/amd64
$ go get -u -x github.com/fatih/gomodifytags
cd .
git clone https://github.com/fatih/gomodifytags /home/lukas/dev/go/src/github.com/fatih/gomodifytags
cd /home/lukas/dev/go/src/github.com/fatih/gomodifytags
git submodule update --init --recursive
cd /home/lukas/dev/go/src/github.com/fatih/gomodifytags
git show-ref
cd /home/lukas/dev/go/src/github.com/fatih/gomodifytags
git submodule update --init --recursive
cd /home/lukas/dev/go/src/github.com/fatih/gomodifytags
git config remote.origin.url
cd /home/lukas/dev/go/src/github.com/fatih/gomodifytags
git config remote.origin.url
cd /home/lukas/dev/go/src/github.com/fatih/gomodifytags
git config remote.origin.url
WORK=/tmp/go-build216595188
mkdir -p $WORK/github.com/fatih/gomodifytags/vendor/github.com/fatih/structtag/_obj/
mkdir -p $WORK/github.com/fatih/gomodifytags/vendor/github.com/fatih/
cd /home/lukas/dev/go/src/github.com/fatih/gomodifytags/vendor/github.com/fatih/structtag
/usr/lib/go/pkg/tool/linux_amd64/compile -o $WORK/github.com/fatih/gomodifytags/vendor/github.com/fatih/structtag.a -trimpath $WORK -p github.com/fatih/gomodifytags/vendor/github.com/fatih/structtag -complete -buildid 72cb72096acf71b6d7bca0347aae7ff2bde3d9c3 -D _/home/lukas/dev/go/src/github.com/fatih/gomodifytags/vendor/github.com/fatih/structtag -I $WORK -pack ./tags.go
mkdir -p $WORK/github.com/fatih/gomodifytags/vendor/github.com/fatih/camelcase/_obj/
mkdir -p $WORK/github.com/fatih/gomodifytags/vendor/golang.org/x/tools/go/buildutil/_obj/
cd /home/lukas/dev/go/src/github.com/fatih/gomodifytags/vendor/github.com/fatih/camelcase
/usr/lib/go/pkg/tool/linux_amd64/compile -o $WORK/github.com/fatih/gomodifytags/vendor/github.com/fatih/camelcase.a -trimpath $WORK -p github.com/fatih/gomodifytags/vendor/github.com/fatih/camelcase -complete -buildid c4d679f88a92a34fb977a677836b8e41a5e27396 -D _/home/lukas/dev/go/src/github.com/fatih/gomodifytags/vendor/github.com/fatih/camelcase -I $WORK -pack ./camelcase.go
mkdir -p $WORK/github.com/fatih/gomodifytags/vendor/golang.org/x/tools/go/
cd /home/lukas/dev/go/src/github.com/fatih/gomodifytags/vendor/golang.org/x/tools/go/buildutil
/usr/lib/go/pkg/tool/linux_amd64/compile -o $WORK/github.com/fatih/gomodifytags/vendor/golang.org/x/tools/go/buildutil.a -trimpath $WORK -p github.com/fatih/gomodifytags/vendor/golang.org/x/tools/go/buildutil -complete -buildid 02625f824d9f8b09a97009c9953709ebbb8d7293 -D _/home/lukas/dev/go/src/github.com/fatih/gomodifytags/vendor/golang.org/x/tools/go/buildutil -I $WORK -pack ./allpackages.go ./fakecontext.go ./overlay.go ./tags.go ./util.go
mkdir -p /home/lukas/dev/go/pkg/linux_amd64/github.com/fatih/gomodifytags/vendor/github.com/fatih/
cp $WORK/github.com/fatih/gomodifytags/vendor/github.com/fatih/camelcase.a /home/lukas/dev/go/pkg/linux_amd64/github.com/fatih/gomodifytags/vendor/github.com/fatih/camelcase.a
cp $WORK/github.com/fatih/gomodifytags/vendor/github.com/fatih/structtag.a /home/lukas/dev/go/pkg/linux_amd64/github.com/fatih/gomodifytags/vendor/github.com/fatih/structtag.a
mkdir -p /home/lukas/dev/go/pkg/linux_amd64/github.com/fatih/gomodifytags/vendor/golang.org/x/tools/go/
cp $WORK/github.com/fatih/gomodifytags/vendor/golang.org/x/tools/go/buildutil.a /home/lukas/dev/go/pkg/linux_amd64/github.com/fatih/gomodifytags/vendor/golang.org/x/tools/go/buildutil.a
mkdir -p $WORK/github.com/fatih/gomodifytags/_obj/
mkdir -p $WORK/github.com/fatih/gomodifytags/_obj/exe/
cd /home/lukas/dev/go/src/github.com/fatih/gomodifytags
/usr/lib/go/pkg/tool/linux_amd64/compile -o $WORK/github.com/fatih/gomodifytags.a -trimpath $WORK -p main -complete -buildid 4183ffe72db4ba7f3b7cc40f68d677722530a383 -importmap github.com/fatih/camelcase=github.com/fatih/gomodifytags/vendor/github.com/fatih/camelcase -importmap github.com/fatih/structtag=github.com/fatih/gomodifytags/vendor/github.com/fatih/structtag -importmap golang.org/x/tools/go/buildutil=github.com/fatih/gomodifytags/vendor/golang.org/x/tools/go/buildutil -D _/home/lukas/dev/go/src/github.com/fatih/gomodifytags -I $WORK -I /home/lukas/dev/go/pkg/linux_amd64 -pack ./main.go
cd .
/usr/lib/go/pkg/tool/linux_amd64/link -o $WORK/github.com/fatih/gomodifytags/_obj/exe/a.out -L $WORK -L /home/lukas/dev/go/pkg/linux_amd64 -extld=gcc -buildmode=exe -buildid=4183ffe72db4ba7f3b7cc40f68d677722530a383 $WORK/github.com/fatih/gomodifytags.a
mkdir -p /home/lukas/dev/go/bin/
cp $WORK/github.com/fatih/gomodifytags/_obj/exe/a.out /home/lukas/dev/go/bin/gomodifytags
$ go version
go version go1.8.1 gccgo (GCC) 7.1.1 20170528 linux/amd64
$ go get -u -x github.com/fatih/gomodifytags
cd .
git clone https://github.com/fatih/gomodifytags /home/lukas/dev/go/src/github.com/fatih/gomodifytags
cd /home/lukas/dev/go/src/github.com/fatih/gomodifytags
git submodule update --init --recursive
cd /home/lukas/dev/go/src/github.com/fatih/gomodifytags
git show-ref
cd /home/lukas/dev/go/src/github.com/fatih/gomodifytags
git submodule update --init --recursive
cd /home/lukas/dev/go/src/github.com/fatih/gomodifytags
git config remote.origin.url
cd /home/lukas/dev/go/src/github.com/fatih/gomodifytags
git config remote.origin.url
cd /home/lukas/dev/go/src/github.com/fatih/gomodifytags
git config remote.origin.url
WORK=/tmp/go-build286964385
mkdir -p $WORK/github.com/fatih/gomodifytags/vendor/github.com/fatih/camelcase/_obj/
mkdir -p $WORK/github.com/fatih/gomodifytags/vendor/github.com/fatih/
cd /home/lukas/dev/go/src/github.com/fatih/gomodifytags/vendor/github.com/fatih/camelcase
/usr/bin/gccgo -I $WORK -c -g -m64 -fgo-pkgpath=github.com/fatih/gomodifytags/vendor/github.com/fatih/camelcase -fgo-relative-import-path=_/home/lukas/dev/go/src/github.com/fatih/gomodifytags/vendor/github.com/fatih/camelcase -o $WORK/github.com/fatih/gomodifytags/vendor/github.com/fatih/camelcase/_obj/_go_.o ./camelcase.go
mkdir -p $WORK/github.com/fatih/gomodifytags/vendor/github.com/fatih/structtag/_obj/
cd /home/lukas/dev/go/src/github.com/fatih/gomodifytags/vendor/github.com/fatih/structtag
/usr/bin/gccgo -I $WORK -c -g -m64 -fgo-pkgpath=github.com/fatih/gomodifytags/vendor/github.com/fatih/structtag -fgo-relative-import-path=_/home/lukas/dev/go/src/github.com/fatih/gomodifytags/vendor/github.com/fatih/structtag -o $WORK/github.com/fatih/gomodifytags/vendor/github.com/fatih/structtag/_obj/_go_.o ./tags.go
mkdir -p $WORK/github.com/fatih/gomodifytags/vendor/golang.org/x/tools/go/buildutil/_obj/
mkdir -p $WORK/github.com/fatih/gomodifytags/vendor/golang.org/x/tools/go/
cd /home/lukas/dev/go/src/github.com/fatih/gomodifytags/vendor/golang.org/x/tools/go/buildutil
/usr/bin/gccgo -I $WORK -c -g -m64 -fgo-pkgpath=github.com/fatih/gomodifytags/vendor/golang.org/x/tools/go/buildutil -fgo-relative-import-path=_/home/lukas/dev/go/src/github.com/fatih/gomodifytags/vendor/golang.org/x/tools/go/buildutil -o $WORK/github.com/fatih/gomodifytags/vendor/golang.org/x/tools/go/buildutil/_obj/_go_.o ./allpackages.go ./fakecontext.go ./overlay.go ./tags.go ./util.go
cd /home/lukas/dev/go/src/github.com/fatih/gomodifytags/vendor/github.com/fatih/camelcase
ar rc $WORK/github.com/fatih/gomodifytags/vendor/github.com/fatih/libcamelcase.a $WORK/github.com/fatih/gomodifytags/vendor/github.com/fatih/camelcase/_obj/_go_.o
mkdir -p /home/lukas/dev/go/pkg/gccgo_linux_amd64/github.com/fatih/gomodifytags/vendor/github.com/fatih/
cp $WORK/github.com/fatih/gomodifytags/vendor/github.com/fatih/libcamelcase.a /home/lukas/dev/go/pkg/gccgo_linux_amd64/github.com/fatih/gomodifytags/vendor/github.com/fatih/libcamelcase.a
cd /home/lukas/dev/go/src/github.com/fatih/gomodifytags/vendor/github.com/fatih/structtag
ar rc $WORK/github.com/fatih/gomodifytags/vendor/github.com/fatih/libstructtag.a $WORK/github.com/fatih/gomodifytags/vendor/github.com/fatih/structtag/_obj/_go_.o
cp $WORK/github.com/fatih/gomodifytags/vendor/github.com/fatih/libstructtag.a /home/lukas/dev/go/pkg/gccgo_linux_amd64/github.com/fatih/gomodifytags/vendor/github.com/fatih/libstructtag.a
cd /home/lukas/dev/go/src/github.com/fatih/gomodifytags/vendor/golang.org/x/tools/go/buildutil
ar rc $WORK/github.com/fatih/gomodifytags/vendor/golang.org/x/tools/go/libbuildutil.a $WORK/github.com/fatih/gomodifytags/vendor/golang.org/x/tools/go/buildutil/_obj/_go_.o
mkdir -p /home/lukas/dev/go/pkg/gccgo_linux_amd64/github.com/fatih/gomodifytags/vendor/golang.org/x/tools/go/
cp $WORK/github.com/fatih/gomodifytags/vendor/golang.org/x/tools/go/libbuildutil.a /home/lukas/dev/go/pkg/gccgo_linux_amd64/github.com/fatih/gomodifytags/vendor/golang.org/x/tools/go/libbuildutil.a
mkdir -p $WORK/github.com/fatih/gomodifytags/_obj/
mkdir -p $WORK/github.com/fatih/gomodifytags/_obj/exe/
cd /home/lukas/dev/go/src/github.com/fatih/gomodifytags
/usr/bin/gccgo -I $WORK -I /home/lukas/dev/go/pkg/gccgo_linux_amd64 -I $WORK/github.com/fatih/gomodifytags/vendor -I /home/lukas/dev/go/pkg/gccgo_linux_amd64/github.com/fatih/gomodifytags/vendor -c -g -m64 -fgo-relative-import-path=_/home/lukas/dev/go/src/github.com/fatih/gomodifytags -o $WORK/github.com/fatih/gomodifytags/_obj/_go_.o ./main.go
ar rc $WORK/github.com/fatih/libgomodifytags.a $WORK/github.com/fatih/gomodifytags/_obj/_go_.o
cd .
/usr/bin/gccgo -o $WORK/github.com/fatih/gomodifytags/_obj/exe/a.out $WORK/github.com/fatih/gomodifytags/_obj/_go_.o -Wl,-( -m64 -Wl,--whole-archive /home/lukas/dev/go/pkg/gccgo_linux_amd64/github.com/fatih/gomodifytags/vendor/github.com/fatih/libcamelcase.a /home/lukas/dev/go/pkg/gccgo_linux_amd64/github.com/fatih/gomodifytags/vendor/github.com/fatih/libstructtag.a /home/lukas/dev/go/pkg/gccgo_linux_amd64/github.com/fatih/gomodifytags/vendor/golang.org/x/tools/go/libbuildutil.a -Wl,--no-whole-archive -Wl,-)
# github.com/fatih/gomodifytags
/tmp/go-build286964385/github.com/fatih/gomodifytags/_obj/_go_.o: In function `main.rewrite.pN11_main.config':
/home/lukas/dev/go/src/github.com/fatih/gomodifytags/main.go:184: undefined reference to `golang_org_x_tools_go_buildutil.ParseOverlayArchive'
/tmp/go-build286964385/github.com/fatih/gomodifytags/_obj/_go_.o: In function `__go_init_main':
/home/lukas/dev/go/src/github.com/fatih/gomodifytags/main.go:1: undefined reference to `golang_org_x_tools_go_buildutil..import'
collect2: error: ld returned 1 exit status
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
tested both of this didn't work:
-add-options json=string,omitempty
-add-options json=string -add-options json=omitempty
but running the command twice works:
-add-options json=string
-add-options json=omitempty
I had to search in the issues to see a way for all structs to be used in the file, almost not using this lib(which is great, by the way! only missing a few tiny things, that may hinder the usability). Which I've found the solution to be, to pass line 1,100000
.
As for the behavior I expected when I used the gomodifytags
command, it would be:
gomodifytags -file <file>.go
: parses entire file, modify all structs, because no filter option passedgomodifytags -file <file>.go -struct/-line/-offset
: gets the entire file, apply the filter, only modify structs that were filteredBut, I don't know if that's everyone's expected behavior, so to at least cover this use case, we could at least document this hidden option, or implement it the proper way(without the line workaround, at least not to the end-user)
$ cat demo.go
package main
type Example struct {
StatusID int64 `json:"status_id`
Foo string
Bar bool
Server struct {
Address string
TLS bool
}
DiskSize int64
Volumes []string
}
$ gomodifytags --file demo.go -struct Example -add-tags json
bad syntax for struct tag value
Here the struct tag is missing a quote. Two things we need to improve:
If lines end is greater than the slice here:
https://github.com/fatih/gomodifytags/blob/master/main.go#L499
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
gomodifytags -file audiovo.go -struct AudioSimpleVo -add-tags json -transform camelcase
generated content is below:
type AudioSimpleVo struct {
//音频ID
ID string `json:"id,omitempty"`
//父ID 课程ID或书的ID
ParentID string `json:"parent_id,omitempty"`
//标题
Titile string `json:"titile,omitempty"`
//音频时长
Length int64 `json:"length,omitempty"`
//是否免费 0:收费 1:免费
Free int `json:"free,omitempty"`
//标签类型 2:加餐
TadType int `json:"tadType"`
//分组ID
SectionID string `json:"section_id,omitempty"`
//分组标题
// example: 开篇词
SectionTitle string `json:"section_title,omitempty"`
//学习状态: 0:未学习 1:已学习
LearnStatus int `json:"learn_status,omitempty"`
//学习人数
LearnCount int64 `json:"learn_count,omitempty"`
//学习人数(带文案)
LearnCountText string `json:"learn_count_text,omitempty"`
//答题标志
TopicTag int `json:"topic_tag,omitempty"`
//答对几题
TopicScore int `json:"topicScore"`
}
why???
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.
I proposed a way to do this in this Pull Request
We have a code base where the following code appears :
func SomeHandler(args *struct{
Arg1 int `json:"arg1,omitempty"`
Arg2 string `json:"arg2,omitempty"`
}) error {
...
When running gomodifytags
with an offset falling within the range of this struct declaration, it returns an error : offset is not inside a struct
.
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)
}
I would like to be able to customize the format of the outputted tag, like so:
Input:
type Foo struct {
FooID int
}
What I want:
type Foo struct {
FooID int `json:"fooId"`
}
If I use the camelcase option, the FooID
, becomes, as expected, fooID
, would there be any way to convert it to fooId
?
Hey,
I just ran this tool on a struct with field name MP3
and the added tag was json:"xmp_3,omitempty"
.
This is wrong, but I wonder if it's worth fixing at all.
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? :)
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
package main
func main() {
// I believe running :GoAddTags inside this anonymous struct should add its tags accordingly
&struct {
Hello string
}{}
}
Will gladly work on this one if you have no problems with it.
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.
For the input file main.go
:
package main
type Foo struct {
BarBash string `json:"bar_bash"`
BazBob string `json:"baz_bob"`
QuuxKing int `json:"quux_king"`
}
The command gomodifytags -file main.go -struct Foo -add-tags json -transform camelcase
returns the input unmodified, instead of changing the tags from snake_case to camelCase.
For reference, the same behavior does not occur with the -sort
option. I can have an input file with xml
and json
tags (in that order), and invoke gomodifytags
with -add-tags xml,json -sort
and the order of the tags is updated as expected.
Hi, first thank you for this great library. So i have special case like this, i want to generate custom tag in my Struct, but not all the field will have it. Example
type Pokemon struct {
Name string
Age int `validate:min=5,max=10`
}
so on the example above, i only want field Age
have the custom tag with value validate:min=5,max=10
Can we have this feature? Thank you for your attention
I use the camelcase transformation, but I have one issue with it.
In my API, we use the go linter conventions regarding acronyms in our JSONs:
we use keys like userID
instead of userId
.
I did not find a way to preserve this behavior.
I don't even mind writing the PR if that's OK with you
(originally opened in vim-go)
I tried to run :GoAddTags inside a variable defined with a struct literal:
var thing struct{
id int
value string
}
I expected struct tags to be added per usual.
I got the error message:
vim-go: offset is not inside a struct
vim-go version: v1.17
vimrc
you used to reproduce (use a minimal vimrc with other plugins disabled; do not link to a 2,000 line vimrc):
My vimrc
Vim version (first three lines from :version
):
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Nov 29 2017 18:37:46)
Included patches: 1-503, 505-608, 682-1283
Compiled by [email protected]
Go version (go version
): go1.10.1
Go environment (go env
): darwin/amd64
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
Currently even with -w
flag the output still printed in stdout
it would be nice if there's a flag that print only when there's error
background: I got some error while doing scanny.pgxscan.Select
because the column is not there
without the struct tag db:"createdat"
(actually it was CreatedAt on the struct) it shows error scanning all: scanning: scanning: doing scan: scanFn: scany: column: createdat
and gomodifytags only allow PascalCase
or snake_case
(only these two that most similar), where what i need is lowercase
.
as of now you have to specify the name of each struct or know the position of each struct individually.
would be great to be able to bulk process a large file with multiple structs.
I've struct name as below
type Server struct {
Name string json:"name"
Port int json:"port"
}
I want to add the element before name (Person:name) as like below
type Server struct {
Name string json:"Person:name"
Port int json:"port"
}
Is it possible to add this option in this lib?
When using structs in combination with various ORM's like GORM you'll end up having fields like: Customer
and CustomerID
. We ignore the Customer or the CustomerID based on what we would like to output. It would be nice to skip the fields that are explicitly set to be ignored like json:"-"
.
Implementing a regex would also be a fine solution: #83
Hi.
For example, i want to have tags with prefix ex_, so it would look like json:"ex_mytag"
.
Is it possible? I can't find it in description.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.