From 14a3d33da7ac5d327a7299e5559cfdb501cdb5fd Mon Sep 17 00:00:00 2001 From: jojohappy Date: Tue, 9 Apr 2019 10:18:16 +0800 Subject: [PATCH] Simplify code Signed-off-by: jojohappy --- pkg/store/prometheus.go | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/pkg/store/prometheus.go b/pkg/store/prometheus.go index 994cdc0d108..b96b96c7b0c 100644 --- a/pkg/store/prometheus.go +++ b/pkg/store/prometheus.go @@ -375,16 +375,18 @@ func (p *PrometheusStore) LabelNames(ctx context.Context, r *storepb.LabelNamesR if resp.StatusCode == http.StatusNoContent { return &storepb.LabelNamesResponse{Names: []string{}}, nil - } else if m.Status != "success" { + } + + if m.Status != "success" { if !r.PartialResponseDisabled { return &storepb.LabelNamesResponse{Names: m.Data}, nil - } else { - code, exists := statusToCode[resp.StatusCode] - if !exists { - code = codes.Internal - } - return nil, status.Error(code, m.Error) } + + code, exists := statusToCode[resp.StatusCode] + if !exists { + code = codes.Internal + } + return nil, status.Error(code, m.Error) } return &storepb.LabelNamesResponse{Names: m.Data}, nil @@ -426,18 +428,21 @@ func (p *PrometheusStore) LabelValues(ctx context.Context, r *storepb.LabelValue } sort.Strings(m.Data) + if resp.StatusCode == http.StatusNoContent { return &storepb.LabelValuesResponse{Values: []string{}}, nil - } else if m.Status != "success" { + } + + if m.Status != "success" { if !r.PartialResponseDisabled { return &storepb.LabelValuesResponse{Values: m.Data}, nil - } else { - code, exists := statusToCode[resp.StatusCode] - if !exists { - code = codes.Internal - } - return nil, status.Error(code, m.Error) } + + code, exists := statusToCode[resp.StatusCode] + if !exists { + code = codes.Internal + } + return nil, status.Error(code, m.Error) } return &storepb.LabelValuesResponse{Values: m.Data}, nil