From 254448bf7496afacadd77826e18eb3ecf2dfa36c Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sun, 28 Feb 2021 01:42:29 +0300 Subject: [PATCH] add client request timeout option support Signed-off-by: Vasiliy Tolstov --- util.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/util.go b/util.go index 73447e5..2648d1b 100644 --- a/util.go +++ b/util.go @@ -32,9 +32,9 @@ func unexport(s string) string { func generateServiceClient(gfile *protogen.GeneratedFile, service *protogen.Service) { serviceName := service.GoName - if rule, ok := getMicroApiService(service); ok { - gfile.P("// client wrappers ", strings.Join(rule.ClientWrappers, ", ")) - } + //if rule, ok := getMicroApiService(service); ok { + // gfile.P("// client wrappers ", strings.Join(rule.ClientWrappers, ", ")) + // } gfile.P("type ", unexport(serviceName), "Client struct {") gfile.P("c ", microClientPackage.Ident("Client")) gfile.P("name string") @@ -83,6 +83,11 @@ func generateServiceClientMethods(gfile *protogen.GeneratedFile, service *protog 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() { gfile.P("rsp := &", gfile.QualifiedGoIdent(method.Output.GoIdent), "{}")