Skip to content

Commit d79ab5f

Browse files
authored
vdl: add the ability to specify go struct tags via the vdl.config file. (#170)
This PR adds support for specifying go struct tags via the vdl.config file. The example below will add the tag json:"ja,omitempty" to TestStruct.A. config = vdltool.Config{ Go: { StructTags: map[string][]vdltool.GoStructTag{ "TestStruct": []vdltool.GoStructTag{ {Field: "A", Tag: `json:"ja,omitempty"`}, } }, }, }
1 parent edce684 commit d79ab5f

File tree

27 files changed

+921
-282
lines changed

27 files changed

+921
-282
lines changed

Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ vdlgen:
66
go run v.io/x/ref/cmd/vdl generate --errors-no-i18n=false --show-warnings=false --lang=go v.io/...
77
go generate ./v23/vdl/vdltest
88

9+
VDLROOT ?= $(shell pwd)/v23/vdlroot
10+
export VDLROOT
11+
vdlroot:
12+
cd v23/vdlroot && \
13+
go run v.io/x/ref/cmd/vdl generate --errors-no-i18n=false --show-warnings=false --lang=go \
14+
./vdltool \
15+
./math \
16+
./time \
17+
./signature
18+
919
.PHONY: test-integration
1020
test-integration:
1121
@echo "VDLPATH" "${VDLPATH}"

go.mod

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.13
55
require (
66
github.com/DATA-DOG/go-sqlmock v1.3.3
77
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect
8+
github.com/cosnicolaou/go-bindata/v3 v3.0.8 // indirect
89
github.com/go-ole/go-ole v1.2.4 // indirect
910
github.com/go-sql-driver/mysql v1.4.1
1011
github.com/golang/protobuf v1.3.2
@@ -18,9 +19,10 @@ require (
1819
github.com/vanadium/go-mdns-sd v0.0.0-20181006014439-f1a1ccd1252e
1920
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
2021
golang.org/x/mod v0.3.0
21-
golang.org/x/net v0.0.0-20200822124328-c89045814202
22+
golang.org/x/net v0.0.0-20201021035429-f5854403a974
2223
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45
23-
golang.org/x/sync v0.0.0-20190423024810-112230192c58
24+
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9
25+
golang.org/x/tools v0.0.0-20201109182053-3db8fd265862 // indirect
2426
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
2527
google.golang.org/api v0.9.0
2628
v.io/x/lib v0.1.6

go.sum

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q
88
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d h1:G0m3OIz70MZUWq3EgK3CesDbo8upS2Vm9/P3FtgI+Jk=
99
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
1010
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
11+
github.com/cosnicolaou/go-bindata/v3 v3.0.8 h1:TFkRvB8gs11F8cTN+txbTQ27uH5/nKmANv9VWjMFFhw=
12+
github.com/cosnicolaou/go-bindata/v3 v3.0.8/go.mod h1:0iCg7gGrUDn2i+XhRcis0RDdNsccqPBLJECyrlpJ21M=
1113
github.com/creack/pty v1.1.7 h1:6pwm8kMQKCmgUg0ZHTm5+/YvRK0s3THD/28+T6/kk4A=
1214
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
1315
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
@@ -58,6 +60,7 @@ github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd
5860
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
5961
github.com/vanadium/go-mdns-sd v0.0.0-20181006014439-f1a1ccd1252e h1:pHSeCN6iUoIWXqaMgi9TeKuESVQY1zThuhVjAHq3GpI=
6062
github.com/vanadium/go-mdns-sd v0.0.0-20181006014439-f1a1ccd1252e/go.mod h1:35fXDjvKtzyf89fHHhyTTNLHaG2CkI7u/GvO59PIjP4=
63+
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
6164
go.opencensus.io v0.21.0 h1:mU6zScU4U1YAFPHEHYk+3JC4SY7JxgkqS10ZOSyksNg=
6265
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
6366
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
@@ -83,8 +86,8 @@ golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn
8386
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
8487
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b h1:0mm1VjtFUOIlE1SbDlwjYaDxZVDP2S5ou6y0gSgXHu8=
8588
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
86-
golang.org/x/net v0.0.0-20200822124328-c89045814202 h1:VvcQYSHwXgi7W+TpUR6A9g6Up98WAHf3f/ulnJ62IyA=
87-
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
89+
golang.org/x/net v0.0.0-20201021035429-f5854403a974 h1:IX6qOQeG5uLjB/hjjwjedwfjND0hgjPMMyO1RoIXQNI=
90+
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
8891
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
8992
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
9093
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 h1:SVwTIAaPC2U/AvvLNZ2a7OVsmBpC8L5BlwK1whH3hm0=
@@ -95,18 +98,23 @@ golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJ
9598
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
9699
golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
97100
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
101+
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9 h1:SQFwaSi55rU7vdNs9Yr0Z324VNlrF+0wMqRXT4St8ck=
102+
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
98103
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
99104
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
100105
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
101106
golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b h1:ag/x1USPSsqHud38I9BAC88qdNLDHHtQ4mlgQIZPPNA=
102107
golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
103-
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
104108
golang.org/x/sys v0.0.0-20200331124033-c3d80250170d h1:nc5K6ox/4lTFbMVSL9WRR81ixkcwXThoiF6yf+R9scA=
105109
golang.org/x/sys v0.0.0-20200331124033-c3d80250170d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
110+
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f h1:+Nyd8tzPX9R7BWHguqsrbFdRx3WQ/1ib8I44HXV5yTA=
111+
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
106112
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
107113
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
108114
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
109115
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
116+
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
117+
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
110118
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
111119
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
112120
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
@@ -117,6 +125,8 @@ golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c h1:97SnQk1GYRXJgvwZ8fadnxD
117125
golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
118126
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e h1:aZzprAO9/8oim3qStq3wc1Xuxx4QmAGriC4VU4ojemQ=
119127
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
128+
golang.org/x/tools v0.0.0-20201109182053-3db8fd265862 h1:LeKnBqBqKuA2WEVPhyr22inXOMgckBKHfUvD0n5kyCg=
129+
golang.org/x/tools v0.0.0-20201109182053-3db8fd265862/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
120130
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
121131
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898 h1:/atklqdjdhuosWIl6AIbOeHJjicWYPqR9bpxqxYG2pA=
122132
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

v23/security/internal/ecdsaonly/ecdsaonly.vdl.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Copyright 2020 The Vanadium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
15
// This file was auto-generated by the vanadium vdl tool.
26
// Package: ecdsaonly
37

v23/security/internal/ecdsaonly/types.vdl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Copyright 2020 The Vanadium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
15
package ecdsaonly
26

37
type Hash string

v23/vdl/errors_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Copyright 2020 The Vanadium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
15
package vdl_test
26

37
import (

v23/vdl/vdltest/vdltest.vdl.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"reflect"
1515

1616
"v.io/v23/context"
17+
"v.io/v23/i18n"
1718
"v.io/v23/vdl"
1819
"v.io/v23/verror"
1920
)
@@ -93079,6 +93080,13 @@ var (
9307993080
ErrThree = verror.NewIDAction("v.io/v23/vdl/vdltest.Three", verror.NoRetry)
9308093081
)
9308193082

93083+
// NewErrNone returns an error with the ErrNone ID.
93084+
// Deprecated: this function will be removed in the future,
93085+
// use ErrorfNone or MessageNone instead.
93086+
func NewErrNone(ctx *context.T) error {
93087+
return verror.New(ErrNone, ctx)
93088+
}
93089+
9308293090
// ErrorfNone calls ErrNone.Errorf with the supplied arguments.
9308393091
func ErrorfNone(ctx *context.T, format string) error {
9308493092
return ErrNone.Errorf(ctx, format)
@@ -93105,6 +93113,13 @@ func ParamsErrNone(argumentError error) (verrorComponent string, verrorOperation
9310593113
return
9310693114
}
9310793115

93116+
// NewErrOne returns an error with the ErrOne ID.
93117+
// Deprecated: this function will be removed in the future,
93118+
// use ErrorfOne or MessageOne instead.
93119+
func NewErrOne(ctx *context.T, i int64) error {
93120+
return verror.New(ErrOne, ctx, i)
93121+
}
93122+
9310893123
// ErrorfOne calls ErrOne.Errorf with the supplied arguments.
9310993124
func ErrorfOne(ctx *context.T, format string, i int64) error {
9311093125
return ErrOne.Errorf(ctx, format, i)
@@ -93144,6 +93159,13 @@ func ParamsErrOne(argumentError error) (verrorComponent string, verrorOperation
9314493159
return
9314593160
}
9314693161

93162+
// NewErrTwo returns an error with the ErrTwo ID.
93163+
// Deprecated: this function will be removed in the future,
93164+
// use ErrorfTwo or MessageTwo instead.
93165+
func NewErrTwo(ctx *context.T, a string, err error) error {
93166+
return verror.New(ErrTwo, ctx, a, err)
93167+
}
93168+
9314793169
// ErrorfTwo calls ErrTwo.Errorf with the supplied arguments.
9314893170
func ErrorfTwo(ctx *context.T, format string, a string, err error) error {
9314993171
return ErrTwo.Errorf(ctx, format, a, err)
@@ -93191,6 +93213,13 @@ func ParamsErrTwo(argumentError error) (verrorComponent string, verrorOperation
9319193213
return
9319293214
}
9319393215

93216+
// NewErrThree returns an error with the ErrThree ID.
93217+
// Deprecated: this function will be removed in the future,
93218+
// use ErrorfThree or MessageThree instead.
93219+
func NewErrThree(ctx *context.T, a string, b int64, c float32) error {
93220+
return verror.New(ErrThree, ctx, a, b, c)
93221+
}
93222+
9319493223
// ErrorfThree calls ErrThree.Errorf with the supplied arguments.
9319593224
func ErrorfThree(ctx *context.T, format string, a string, b int64, c float32) error {
9319693225
return ErrThree.Errorf(ctx, format, a, b, c)
@@ -94398,5 +94427,11 @@ func initializeVDL() struct{} {
9439894427
vdlTypeUnion283 = vdl.TypeOf((*VWireUnionNIface)(nil))
9439994428
vdlTypeStruct284 = vdl.TypeOf((*VWireAll)(nil)).Elem()
9440094429

94430+
// Set error format strings.
94431+
i18n.Cat().SetWithBase(i18n.LangID("en"), i18n.MsgID(ErrNone.ID), "{1:}{2:} dummy")
94432+
i18n.Cat().SetWithBase(i18n.LangID("en"), i18n.MsgID(ErrOne.ID), "{1:}{2:} dummy")
94433+
i18n.Cat().SetWithBase(i18n.LangID("en"), i18n.MsgID(ErrTwo.ID), "{1:}{2:} dummy")
94434+
i18n.Cat().SetWithBase(i18n.LangID("en"), i18n.MsgID(ErrThree.ID), "{1:}{2:} dummy")
94435+
9440194436
return struct{}{}
9440294437
}

v23/vdlroot/vdltool/config.vdl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,17 @@ type GoConfig struct {
5454
// func fooToNative(x Foo, n *Native) error
5555
// func fooFromNative(x *Foo, n Native) error
5656
WireToNativeTypes map[string]GoType
57+
58+
// StructTags specifies any go struct tags to be include with the generated
59+
// go code. The StructTags map is keyed by the struct type's name.
60+
StructTags map[string][]GoStructTag
61+
}
62+
63+
// GoStructTag specifies a single go struct tag and the field to which it
64+
// should be applied.
65+
type GoStructTag struct {
66+
Field string
67+
Tag string
5768
}
5869

5970
// GoType describes the Go type information associated with a VDL type.

v23/vdlroot/vdltool/config_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ func TestLoadingVdlConfig(t *testing.T) {
3939
},
4040
},
4141
},
42+
StructTags: map[string][]GoStructTag{
43+
"StructTypeName": {
44+
{Field: "NameOfField", Tag: `json:"name,omitempty" other:"name,,'quoted'"`},
45+
},
46+
},
4247
},
4348
Java: JavaConfig{
4449
WireTypeRenames: map[string]string{

0 commit comments

Comments
 (0)