diff --git a/Makefile b/Makefile index 7798aa7..d8574af 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/examples/time/Makefile b/examples/time/Makefile new file mode 100644 index 0000000..b0f98f5 --- /dev/null +++ b/examples/time/Makefile @@ -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 diff --git a/examples/time/output/time.go b/examples/time/output/time.go new file mode 100644 index 0000000..f9df110 --- /dev/null +++ b/examples/time/output/time.go @@ -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) +} \ No newline at end of file diff --git a/examples/time/proto/time.proto b/examples/time/proto/time.proto new file mode 100644 index 0000000..e5d1d6a --- /dev/null +++ b/examples/time/proto/time.proto @@ -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){} +} \ No newline at end of file diff --git a/examples/time/templates/time.go.tmpl b/examples/time/templates/time.go.tmpl new file mode 100644 index 0000000..1a52a96 --- /dev/null +++ b/examples/time/templates/time.go.tmpl @@ -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}} +} \ No newline at end of file diff --git a/helpers/helpers.go b/helpers/helpers.go index a83f9e7..3c1f3ed 100644 --- a/helpers/helpers.go +++ b/helpers/helpers.go @@ -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] }