nolint: goconst // goconst wants us to make http:// a const
(req *tempopb.SearchRequest)
| 104 | |
| 105 | // nolint: goconst // goconst wants us to make http:// a const |
| 106 | func (cmd *querySearchCmd) searchHTTP(req *tempopb.SearchRequest) error { |
| 107 | httpReq, err := http.NewRequest("GET", httpScheme(cmd.Secure)+"://"+path.Join(cmd.HostPort, cmd.PathPrefix, api.PathSearch), nil) |
| 108 | if err != nil { |
| 109 | return err |
| 110 | } |
| 111 | |
| 112 | httpReq, err = api.BuildSearchRequest(httpReq, req) |
| 113 | if err != nil { |
| 114 | return err |
| 115 | } |
| 116 | |
| 117 | httpReq.Header = http.Header{} |
| 118 | err = user.InjectOrgIDIntoHTTPRequest(user.InjectOrgID(context.Background(), cmd.OrgID), httpReq) |
| 119 | if err != nil { |
| 120 | return err |
| 121 | } |
| 122 | applyHeadersHTTP(httpReq, cmd.Headers) |
| 123 | |
| 124 | httpResp, err := http.DefaultClient.Do(httpReq) |
| 125 | if err != nil { |
| 126 | return err |
| 127 | } |
| 128 | defer httpResp.Body.Close() |
| 129 | |
| 130 | body, err := io.ReadAll(httpResp.Body) |
| 131 | if err != nil { |
| 132 | return err |
| 133 | } |
| 134 | |
| 135 | if httpResp.StatusCode != http.StatusOK { |
| 136 | return errors.New("failed to query. body: " + string(body) + " status: " + httpResp.Status) |
| 137 | } |
| 138 | |
| 139 | resp := &tempopb.SearchResponse{} |
| 140 | err = jsonpb.Unmarshal(bytes.NewReader(body), resp) |
| 141 | if err != nil { |
| 142 | panic("failed to parse resp: " + err.Error()) |
| 143 | } |
| 144 | err = printAsJSON(resp) |
| 145 | if err != nil { |
| 146 | return err |
| 147 | } |
| 148 | |
| 149 | return nil |
| 150 | } |
no test coverage detected