fix templates and helpers

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2021-01-12 13:39:43 +03:00
parent 9954ab8133
commit c5da16f9dd
5 changed files with 26 additions and 11 deletions

View File

@ -25,10 +25,10 @@ var Assets = func() http.FileSystem {
},
"/{{.File.Package}}_micro.pb.go.tmpl": &vfsgen۰CompressedFileInfo{
name: "{{.File.Package}}_micro.pb.go.tmpl",
modTime: time.Date(2021, 1, 8, 12, 40, 55, 173921701, time.UTC),
uncompressedSize: 4772,
modTime: time.Date(2021, 1, 12, 10, 38, 54, 81299017, time.UTC),
uncompressedSize: 4844,
compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x02\xff\xd4\x57\x4d\x6f\xdc\x36\x13\x3e\x5b\xbf\x62\x20\xbc\x08\xa4\x60\x2d\x1d\xde\xdb\x16\x39\x38\x46\x82\x16\xa8\x9d\x20\x2e\xda\x43\x10\x18\xb4\x34\xab\x25\xac\x25\x55\x92\x5a\xc7\x90\xf5\xdf\x0b\x7e\xe8\x8b\xab\xd5\xda\x86\x51\xa0\xbe\x58\x22\xe7\x19\xce\x0c\x9f\x99\x7d\x94\xa6\x70\xc9\x73\x84\x02\x19\x0a\xa2\x30\x87\xbb\x47\xa8\x04\x57\x3c\x3b\x2f\x90\x9d\xef\x68\x26\x78\x90\xa6\x20\x79\x2d\x32\x5c\x43\xd3\x24\x9f\x69\x89\xc9\x35\xd9\x61\xdb\x06\x15\xc9\xee\x49\x81\xd0\x34\x05\xff\x7a\x5f\xfc\x4e\xa4\xfa\x54\xe2\x0e\x99\x02\x63\x07\x4f\x20\xab\x92\xaa\x0b\x21\xc8\x23\x84\xbf\x84\xf0\x04\x25\x91\xaa\x6d\x83\x80\xee\x2a\x2e\x14\x44\xc1\x59\x98\x71\xa6\xf0\xa7\x0a\x83\xe0\xcc\x9c\x78\x4b\x2a\x0a\x61\x41\xd5\xb6\xbe\x4b\x32\xbe\x4b\x6b\x46\xa5\x22\xd9\xfd\x39\x17\x45\x6a\x4c\xd2\xfd\xff\x53\x52\xd1\x10\x00\xa0\x43\x65\x25\xd5\x27\x9f\x06\x5a\xc3\xb0\x07\x4a\x14\x7b\x14\xcf\x00\x5a\xc3\x30\x88\x83\xa0\x69\xce\xe1\x7f\x37\x28\xf6\x34\x43\x5d\x0d\x58\x7f\x80\xc4\xbd\x9b\xf2\xc0\x13\x28\x41\x77\x37\xf5\x66\x43\x7f\x42\xe8\xb6\x42\xd0\xb9\xa7\x29\x5c\xe3\x43\xd3\x8c\x1d\xb4\xed\x27\x96\x57\x9c\x32\x25\xf5\x15\xec\x69\x8e\x12\x74\x21\xb0\x5f\xde\xa1\xca\x89\x22\xb0\xe1\x02\x7c\x30\x48\xfb\x16\x6c\x6a\x96\x2d\x7a\x8f\x62\xf8\xfe\xe3\x7d\x5f\xe8\xa4\xdb\x80\x26\xd0\xd5\xdc\x13\x31\x3a\x72\xd6\x32\x30\x86\xba\x02\x82\xb0\x02\x87\xbc\xaf\x50\x6d\x79\xde\xb6\xfd\x3e\xdd\x00\x43\x88\xb6\x4a\x55\x7f\xa2\xb8\x83\x24\x86\xd0\x94\x40\x1b\x74\xa7\xe8\xd2\xbd\x3b\x3c\xc5\x86\xa3\xff\x74\x02\x6b\x08\xfd\x8c\x92\xa6\x71\x44\x0c\x57\xbd\xed\x57\xa2\xb6\x6b\xf8\xfe\x43\x2a\x41\x59\xd1\x84\x4d\xa3\x0f\xd7\xab\x90\xb4\x6d\xd8\x0e\x96\x36\xd8\x43\x5b\x1b\xe8\xd4\xd6\xcb\xe5\x23\xcf\x1f\xa7\xb9\xe8\x3f\xbd\x6a\xc2\x1c\x4c\x26\xa1\x69\x27\xc8\xf2\x11\xc2\xb9\xe5\x02\xa2\xe4\xd2\x90\xf2\x46\x09\x24\x3b\xca\x8a\x18\x22\x53\x56\x14\xc3\xd2\x08\x69\x17\xd7\xa0\x44\x8d\x4b\x27\xfc\x4a\x58\x5e\xa2\x58\x43\x28\xaa\xcc\xc5\xd2\x7a\xd7\xd7\x15\x48\x5e\xe4\x39\x55\x94\x33\x52\x7e\xa4\x2c\xa7\xac\x90\x90\xf8\x97\x95\x98\x52\x7e\x00\x52\x55\xc8\xf2\x68\xb2\xbc\xd2\xc9\xeb\x9c\xe3\xe0\x30\x9a\x81\x53\x07\x60\xb9\xea\x77\xe7\x90\xd3\x37\x81\xaa\x16\x6c\x70\x17\xd8\x7e\xf2\xc9\xe1\x5e\x80\x32\x85\x62\x43\x32\x0c\xd4\x63\x85\xa7\xcd\x4c\x17\x2c\x53\xdb\xb4\xbe\xc0\xbf\xed\x92\x69\xfc\xdf\x58\x55\xab\x3f\xf4\x01\xd3\x89\x97\x74\x13\x0f\x46\x48\x59\x8d\x90\x5f\x6a\xf5\x6c\x68\x47\x15\x9f\x17\x33\xec\x19\x63\x08\xcb\x67\x41\x8c\x2b\x98\x07\x6a\xa8\x6b\xad\xc8\x0d\xe7\xe4\xd2\xfe\x5f\xc1\xfb\xa6\x19\xb2\x6f\xdb\x15\x24\x49\x32\x1e\xc0\xc9\x25\x29\xcb\x2f\x95\x26\x52\x0c\x91\x5f\xf0\xdb\xde\xb3\x5b\x5e\x01\x0a\xc1\x45\xec\xe2\xc5\x52\xe2\xe9\x18\xde\xf6\x48\x36\xdc\xeb\xf3\x8e\x7f\x59\x09\x8c\x75\x77\xe9\xda\xfa\xf8\xe9\xe6\xb9\xd5\xbf\x2e\xc7\xe8\xf7\x1a\xf2\xf5\xb0\x17\x32\xcf\xe0\x5e\x46\xba\xd9\x26\x3b\xb8\x00\xaf\xdd\x00\x5c\x65\xa3\x18\xbc\x5a\x9b\xdd\x1b\x64\xf9\x95\x2c\xa2\x1e\xd5\xb4\xb1\x2d\xa2\xd9\xfe\x86\xd9\x7e\x61\x7b\xd2\x05\x87\x53\xd6\x74\xc1\x91\x49\xab\x3d\x5f\xb0\xfc\xb2\xe4\x12\xa3\xc5\x9b\xf4\xa7\x54\x07\x39\x08\xc3\x8f\xc0\xd9\xeb\x14\x23\x8f\x56\x3e\x7a\x3a\x11\xb5\x2f\x2f\xec\x51\xd4\xcf\x8f\xd6\x72\xc3\x3e\x0f\x4f\x69\x0a\x57\x9a\xd0\xe0\xb4\x91\x54\xf5\x66\x33\x3b\x68\xdd\x2f\x4c\x67\xb8\xb5\xaf\xf3\x44\xe8\x6c\xc7\xd7\x7f\xb6\x34\x6c\xff\x75\xb6\xbf\x7c\xc8\x0e\xe2\x60\x66\x9c\xbe\x62\x94\x2c\x34\x8f\xf1\x7a\xc0\x8a\x67\x4d\xac\x17\x7b\x1d\xf8\xf0\xba\x89\xe8\x91\xaf\xf3\x3f\xc7\x35\xfb\x03\xfe\x0d\x0b\x2a\x15\x8a\x63\x9c\x11\x6e\x5f\xfa\x4c\x33\x82\xf7\x04\x3a\x92\x30\x96\xfa\xee\x72\x57\x20\xb7\xc7\x38\xba\x02\x5e\x29\x39\x0c\x76\x07\x74\xbb\xdd\x6c\x37\x49\xb9\x19\x36\xc3\x78\xcd\x2c\xfe\x80\xe2\x33\x15\x9a\x5f\x53\xde\xff\xf7\x89\x7f\x82\x13\xd3\x8a\x4f\x68\xe6\x11\xeb\x8d\xc8\x65\x4b\x6a\x49\x35\x7e\x1e\x44\xef\xec\x54\x02\xa9\x44\x9d\x75\xdf\x3f\x36\x96\x85\x5b\x1c\xb9\xdb\x9a\x4f\x97\x45\x6b\x47\x98\x46\x6e\x2d\x44\x7f\xbb\xdd\xae\x26\xdf\x3e\x96\x03\x27\x3e\xd9\x86\xe0\x0c\x2f\x7b\x0d\xad\xdf\xba\x52\xeb\xaf\xa7\xbf\xa8\xda\x76\xb8\x5e\x60\xc7\xf1\x28\x68\x27\xa0\xa5\xe3\x72\x24\x93\x6b\x7c\xe8\xfa\xe4\x9d\x1f\x43\xb3\x6d\x6d\x2b\x24\x49\x12\xc7\x56\x9b\xbc\x35\x6d\x6d\x5e\xaf\x25\x6f\x07\x7e\x5b\xa1\x62\x6c\x3d\x9d\xb2\xa4\x52\x16\x35\xca\xa2\x42\x79\xb5\x3e\xd1\x47\xf6\xea\xe4\x48\x4b\x4c\x95\x83\xaf\x4a\x96\x74\xc4\xa0\x48\x4e\x79\x5d\x52\x36\x13\x2d\x32\x6e\xe1\x19\x0d\x3c\xaf\x44\xfe\x09\x00\x00\xff\xff\x18\xe4\x19\x27\xa4\x12\x00\x00"),
compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x02\xff\xd4\x57\x4b\x6f\xdc\x36\x10\x3e\x47\xbf\x62\x20\x14\x81\x14\xac\xa5\x43\x6f\x5b\xe4\x90\x18\x09\x5a\xa0\x71\x82\xb8\x68\x0f\x41\x60\xd0\xd2\xac\x96\xb5\x96\x54\x49\x6a\x1d\x43\xd6\x7f\x2f\xf8\xd0\x8b\xab\xd5\x7a\x0d\xa3\x40\x7d\xb1\x48\xce\x37\x9c\xc7\x37\xb3\xc3\x34\x85\x4b\x9e\x23\x14\xc8\x50\x10\x85\x39\xdc\x3e\x40\x25\xb8\xe2\xd9\x45\x81\xec\x62\x47\x33\xc1\x83\x34\x05\xc9\x6b\x91\xe1\x1a\x9a\x26\xf9\x48\x4b\x4c\xae\xc8\x0e\xdb\x36\xa8\x48\x76\x47\x0a\x84\xa6\x29\xf8\x97\xbb\xe2\x77\x22\xd5\x87\x12\x77\xc8\x14\x18\x39\x78\x04\x59\x95\x54\xbd\x13\x82\x3c\x40\xf8\x4b\x08\x8f\x50\x12\xa9\xda\x36\x08\xe8\xae\xe2\x42\x41\x14\xbc\x0a\x33\xce\x14\xfe\x50\x61\x10\xbc\x32\x37\xde\x90\x8a\x42\x58\x50\xb5\xad\x6f\x93\x8c\xef\xd2\x9a\x51\xa9\x48\x76\x77\xc1\x45\x91\x1a\x91\x74\xff\x73\x4a\x2a\x1a\x02\x00\x74\xa8\xac\xa4\xfa\xe6\xd3\x40\x2b\x18\xf6\x40\x89\x62\x8f\xe2\x09\x40\x2b\x18\x06\x71\x10\x34\xcd\x05\xfc\x74\x8d\x62\x4f\x33\xd4\xd1\x80\xf5\x5b\x48\xdc\xda\x84\x07\x1e\x41\x09\xba\xbb\xae\x37\x1b\xfa\x03\x42\x77\x14\x82\xf6\x3d\x4d\xe1\x0a\xef\x9b\x66\xac\xa0\x6d\x3f\xb0\xbc\xe2\x94\x29\xa9\x53\xb0\xa7\x39\x4a\xd0\x81\xc0\x7e\x7b\x87\x2a\x27\x8a\xc0\x86\x0b\xf0\xc1\x20\xed\x2a\xd8\xd4\x2c\x5b\xd4\x1e\xc5\xf0\xed\xfb\x9b\x3e\xd0\x49\x77\x00\x4d\xa0\xa3\xb9\x27\x62\x74\xe5\xac\x64\x60\x04\x75\x04\x04\x61\x05\x0e\x7e\x7f\x42\xb5\xe5\x79\xdb\xf6\xe7\x74\x03\x8c\x2b\x88\x74\x86\x09\x65\x12\xa2\xbf\x25\x67\x10\x6d\x95\xaa\x3e\x57\x8a\x72\x06\x49\x1c\x43\xc8\xea\xb2\x0c\x63\xf0\x90\x68\x05\xff\x44\x71\x0b\x49\x0c\x61\xd8\x09\x74\xf6\xe9\xa0\xbf\x3e\xb4\xcf\x3a\xa2\xff\xb4\xeb\x6b\x08\xfd\x58\x24\x4d\xe3\x28\x1c\xae\x7a\xd9\x2f\x44\x6d\xd7\xf0\xed\xbb\x54\x82\xb2\xa2\x09\x9b\x46\x5f\xae\x77\x21\x69\xdb\xb0\x1d\x24\xad\x9b\x87\xb2\xd6\xd0\xa9\xac\xe7\xcb\x7b\x9e\x3f\x4c\x7d\xd1\x7f\x7a\xd7\x98\x39\x88\x4c\x4c\xd3\x4a\x90\xe5\x23\x84\x53\xcb\x05\x44\xc9\xa5\xa1\xf3\xb5\x12\x48\x76\x94\x15\x31\x44\x26\x21\x28\x86\xad\x11\xd2\x6e\xae\x41\x89\x1a\x97\x6e\xf8\x95\xb0\xbc\x44\xb1\x86\x50\x54\x99\xb3\xa5\xf5\x12\xdf\x05\x48\xbe\xcb\x73\xaa\xb3\x49\xca\xf7\x94\xe5\x94\x15\x12\x12\x3f\x59\x89\x09\xe5\x5b\x20\x55\x85\x2c\x8f\x26\xdb\x2b\xed\xbc\xf6\x39\x0e\x0e\xad\x19\xd8\x78\x00\x96\xab\xfe\x74\x0e\xb9\xb4\x12\xa8\x6a\xc1\x06\xe5\x81\xad\x4b\x9f\x2a\x6e\x01\x94\x29\x14\x1b\x92\x61\xa0\x1e\x2a\x3c\x2d\x66\xaa\x69\xb9\x44\x4c\x0b\x11\xf8\x8f\xdd\x32\x0d\xe4\x37\x56\xd5\xea\x0f\x7d\xc1\xb4\x73\x26\x5d\xe7\x84\x11\x52\x56\x23\xe4\xe7\x5a\x3d\x19\xda\x11\xc7\x67\xc9\x0c\x97\xc6\x18\xc2\xf2\x59\x90\xae\xf0\x79\xa0\x86\xba\x42\x8b\x5c\x93\x4f\x2e\xed\xff\x15\xbc\x69\x9a\xc1\xfb\xb6\x5d\x41\x92\x24\xe3\x46\x9e\x5c\x92\xb2\xb4\x4d\x22\x86\xc8\x0f\xf8\x4d\xaf\xd9\x6d\xaf\x00\x85\xe0\x22\x76\xf6\x62\x29\xf1\xb4\x0d\x2f\x7b\x25\x1b\xf2\xfa\xb4\xeb\xcf\x0b\x81\x91\xee\x92\xae\xa5\x8f\xdf\x6e\xbe\x5b\xfd\x2b\x75\x8c\x7e\xcf\x21\x5f\x0f\x3b\x93\x79\x06\x77\x1e\xe9\x66\x8b\xec\x20\x01\x5e\xb9\x01\xb8\xc8\x46\x31\x78\xb1\x36\xa7\xd7\xc8\xf2\x4f\xb2\x88\x7a\x54\xd3\xc6\x36\x88\xe6\xf8\x2b\x66\xfb\x85\xe3\x49\x15\x1c\xf6\x5c\x53\x05\x47\xfa\xae\xd6\xfc\x8e\xe5\x97\x25\x97\x18\x2d\x66\xd2\xef\x52\x1d\xe4\xc0\x0c\xdf\x02\x27\xaf\x5d\x8c\x3c\x5a\xf9\xe8\x69\x47\xd4\xba\x3c\xb3\x47\x56\x3f\xdd\x5a\xcb\x0d\xfb\x3d\x7c\xa5\x29\x7c\xd2\x84\x06\x37\x63\x49\x55\x6f\x36\xb3\x8d\xd6\xfd\xde\x74\x82\x5b\xbb\x9c\x27\x42\x27\x3b\x4e\xff\xab\xa5\x66\xfb\x9f\xb3\xfd\xfc\x26\x3b\x19\x98\x8e\x64\xf7\x9c\x56\xb2\x50\x3c\x46\xeb\x01\x2b\x9e\xd4\xb1\xce\xd6\x3a\xf0\xe1\x79\x1d\xd1\x23\x5f\xa7\x7f\x8e\x6b\xf6\x07\xfc\x2b\x16\x54\x2a\x14\xc7\x38\x23\xdc\xb9\xf4\x99\x66\x06\xe7\x13\xe8\x48\xc2\xf8\xc9\xe0\x92\xbb\x02\xb9\x3d\xc6\xd1\x15\xf0\x4a\xc9\xa1\xb1\x3b\xa0\x3b\xed\x7a\xbb\x71\xca\xf5\xb0\x19\xc6\x6b\x66\xf1\x7b\x14\x1f\xa9\xd0\xfc\x9a\xf2\xfe\xff\x4f\xfc\x13\x9c\x98\x46\x7c\x42\x33\x8f\x58\x2f\x44\x2e\x1b\x52\x4b\xaa\xf1\xf7\x30\x02\xcf\x76\x25\x90\x4a\xd4\x59\xf7\x8e\xb2\xb6\x2c\x64\x71\xa4\x6e\x6b\x1e\x32\x8b\xd2\x8e\x30\x8d\xdc\x5a\x88\x7e\x03\xde\xac\x26\x2f\x21\xcb\x81\x13\x4f\xbf\xc1\x38\xc3\xcb\x7e\xa2\xd6\xab\x2e\xd4\xfa\x2d\xf5\x17\x55\xdb\x0e\xd7\x8f\xdb\x71\x3c\x32\xda\x0d\xd0\xd2\x71\x39\x92\xc9\x15\xde\x77\x75\xf2\xda\xb7\xa1\xd9\xb6\xb6\x14\x92\x24\x89\x63\x3b\x9b\xbc\x34\x6d\xad\x5f\xcf\x25\x6f\x07\x7e\xd9\x41\xc5\xc8\x7a\x73\xca\xd2\x94\xb2\x38\xa3\x2c\x4e\x28\xcf\x9e\x4f\xf4\x95\xfd\x74\x72\xa4\x24\xa6\x93\x83\x3f\x95\x2c\xcd\x11\xc3\x44\x72\x4a\xeb\xd2\x64\x33\x99\x45\xc6\x25\x3c\x33\x03\xcf\x4f\x22\xff\x06\x00\x00\xff\xff\x2e\x87\x12\xc6\xec\x12\x00\x00"),
},
"/{{.File.Package}}_micro_grpc.pb.go.tmpl": &vfsgen۰CompressedFileInfo{
name: "{{.File.Package}}_micro_grpc.pb.go.tmpl",

2
go.mod generated
View File

@ -11,7 +11,7 @@ require (
github.com/huandu/xstrings v1.3.1
github.com/mitchellh/reflectwalk v1.0.1 // indirect
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 // indirect
github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546 // indirect
github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546
google.golang.org/genproto v0.0.0-20210106152847-07624b53cd92
google.golang.org/protobuf v1.25.0
)

1
go.sum generated
View File

@ -372,6 +372,7 @@ golang.org/x/tools v0.0.0-20200515010526-7d3b6ebf133d/go.mod h1:EkVYQZoAsY45+roY
golang.org/x/tools v0.0.0-20200618134242-20370b0cb4b2/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
golang.org/x/tools v0.0.0-20200825202427-b303f430e36d h1:W07d4xkoAUSNOkOzdzXCdFGxT7o2rW4q8M34tB2i//k=
golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

View File

@ -51,12 +51,12 @@ var ProtoHelpersFuncMap = template.FuncMap{
}
return string(a)
},
"splitArray": func(sep string, s string) []interface{} {
var r []interface{}
t := strings.Split(s, sep)
for i := range t {
if t[i] != "" {
r = append(r, t[i])
"splitArray": func(sep string, s string) []string {
var r []string
parts := strings.Split(s, sep)
for _, part := range parts {
if part != "" {
r = append(r, part)
}
}
return r
@ -1347,6 +1347,15 @@ func openapiOption(m *descriptor.MethodDescriptorProto) *openapi_options.Operati
func httpOption(m *descriptor.MethodDescriptorProto) *HttpOption {
ext, err := proto.GetExtension(m.Options, options.E_Http)
if err != nil {
return nil
}
_, ok := ext.(*options.HttpRule)
if !ok {
panic(fmt.Sprintf("extension is %T; want an HttpRule", ext))
}
opt := &HttpOption{Method: httpVerb(m), Body: httpBody(m)}
if path := httpPath(m); path != "" {
opt.Path = append(opt.Path, path)
@ -1493,7 +1502,10 @@ func replaceDict(src string, dict map[string]interface{}) string {
}
func goPkg(f *descriptor.FileDescriptorProto) string {
return f.Options.GetGoPackage()
if name := f.Options.GetGoPackage(); name != "" {
return name
}
return f.GetPackage()
}
func goPkgLastElement(f *descriptor.FileDescriptorProto) string {

View File

@ -17,6 +17,7 @@ func New{{$ServiceName}}Endpoints() []*micro_api.Endpoint {
var endpoints []*micro_api.Endpoint
{{- range .Service.Method}}
{{- if not (contains (json (httpOption .)) "null") }}
{{- if ne (httpVerb .) "" }}
endpoint := &micro_api.Endpoint{
Name: "{{$ServiceName}}.{{.Name}}",
@ -36,6 +37,7 @@ func New{{$ServiceName}}Endpoints() []*micro_api.Endpoint {
endpoints = append(endpoints, endpoint)
{{- end}}
{{- end}}
{{- end}}
return endpoints
}