handle google.protobuf.timestamp
This commit is contained in:
		
							
								
								
									
										1
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								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 | ||||
|   | ||||
							
								
								
									
										13
									
								
								examples/time/Makefile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								examples/time/Makefile
									
									
									
									
									
										Normal 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 | ||||
							
								
								
									
										10
									
								
								examples/time/output/time.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								examples/time/output/time.go
									
									
									
									
									
										Normal 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) | ||||
| } | ||||
							
								
								
									
										12
									
								
								examples/time/proto/time.proto
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								examples/time/proto/time.proto
									
									
									
									
									
										Normal 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){} | ||||
| } | ||||
							
								
								
									
										10
									
								
								examples/time/templates/time.go.tmpl
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								examples/time/templates/time.go.tmpl
									
									
									
									
									
										Normal 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}} | ||||
| } | ||||
| @@ -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] | ||||
| 	} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user