handle google.protobuf.timestamp

This commit is contained in:
jhayotte 2017-06-08 16:40:52 +02:00
parent 098b247649
commit d0c5bb5a97
6 changed files with 49 additions and 0 deletions

View File

@ -8,6 +8,7 @@ install:
.PHONY: test
test: install
cd examples/time && make
cd examples/enum && make
cd examples/import && make
cd examples/dummy && make

13
examples/time/Makefile Normal file
View File

@ -0,0 +1,13 @@
.PHONY: build
build:
mkdir -p output
protoc -I. --gotemplate_out=template_dir=templates,debug=true:output proto/*.proto
.PHONY: re
re: clean build
.PHONY: clean
clean:
rm -rf output

View File

@ -0,0 +1,10 @@
// Code generated by protoc-gen-gotemplate
package foo
import (
"github.com/golang/protobuf/ptypes/timestamp"
)
type Repository interface {
GetFoo(timestamp *timestamp.Timestamp ) (*timestamp.Timestamp, error)
}

View File

@ -0,0 +1,12 @@
syntax = "proto3";
package foo;
import "google/protobuf/timestamp.proto";
message GetFooRequest { google.protobuf.Timestamp timestamp = 1;}
message GetFooResponse { string result = 1;}
service foosvc {
rpc GetFoo (GetFooRequest) returns (GetFooResponse){}
}

View File

@ -0,0 +1,10 @@
// Code generated by protoc-gen-gotemplate
package {{.File.Package}}
import (
"github.com/golang/protobuf/ptypes/timestamp"
)
type Repository interface {
{{range $m := .Service.Method}}{{with $t := $m.InputType | getMessageType $.File}} {{$m.Name}}({{range $f := $t.Field}}{{$f.Name|lowerCamelCase}} {{$f| goTypeWithPackage }} {{end}}) ({{with $out := $m.OutputType | getMessageType $.File}}{{range $f := $out.Field}}{{$f | goTypeWithPackage}}, {{end}}{{end}} error){{end}}{{end}}
}

View File

@ -263,6 +263,9 @@ func jsSuffixReservedKeyword(s string) string {
}
func getPackageTypeName(s string) string {
if strings.Compare(s, ".google.protobuf.Timestamp") == 0 {
return "timestamp"
}
if strings.Contains(s, ".") {
return strings.Split(s, ".")[1]
}