add client request timeout option support

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2021-02-28 01:42:29 +03:00
parent 7b349ba1ca
commit 254448bf74

11
util.go
View File

@ -32,9 +32,9 @@ func unexport(s string) string {
func generateServiceClient(gfile *protogen.GeneratedFile, service *protogen.Service) { func generateServiceClient(gfile *protogen.GeneratedFile, service *protogen.Service) {
serviceName := service.GoName serviceName := service.GoName
if rule, ok := getMicroApiService(service); ok { //if rule, ok := getMicroApiService(service); ok {
gfile.P("// client wrappers ", strings.Join(rule.ClientWrappers, ", ")) // gfile.P("// client wrappers ", strings.Join(rule.ClientWrappers, ", "))
} // }
gfile.P("type ", unexport(serviceName), "Client struct {") gfile.P("type ", unexport(serviceName), "Client struct {")
gfile.P("c ", microClientPackage.Ident("Client")) gfile.P("c ", microClientPackage.Ident("Client"))
gfile.P("name string") gfile.P("name string")
@ -83,6 +83,11 @@ func generateServiceClientMethods(gfile *protogen.GeneratedFile, service *protog
gfile.P(")") gfile.P(")")
} }
} }
if rule, ok := getMicroApiMethod(method); ok {
if rule.Timeout > 0 {
gfile.P("opts = append(opts, ", microClientPackage.Ident("WithRequestTimeout"), "(time.Second*", rule.Timeout, "))")
}
}
if !method.Desc.IsStreamingServer() && !method.Desc.IsStreamingClient() { if !method.Desc.IsStreamingServer() && !method.Desc.IsStreamingClient() {
gfile.P("rsp := &", gfile.QualifiedGoIdent(method.Output.GoIdent), "{}") gfile.P("rsp := &", gfile.QualifiedGoIdent(method.Output.GoIdent), "{}")