mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-04 20:23:59 +00:00
* ci: Fix linter complaint (#9645)
Fixes a very silly linter complaint that makes absolutely no sense and is blocking the merging of several PRs.
---
#### PR checklist
- [x] Tests written/updated, or no tests needed
- [x] `CHANGELOG_PENDING.md` updated, or no changelog entry needed
- [x] Updated relevant documentation (`docs/`) and code comments, or no
documentation updates needed
(cherry picked from commit 83b7f4ad5b)
# Conflicts:
# .github/workflows/lint.yml
# .golangci.yml
# cmd/tendermint/commands/debug/util.go
* Resolve conflicts
Signed-off-by: Thane Thomson <connect@thanethomson.com>
* ci: Sync golangci-lint config with main
Minus the spelling configuration that restricts spelling to US English
only.
Signed-off-by: Thane Thomson <connect@thanethomson.com>
* make format
Signed-off-by: Thane Thomson <connect@thanethomson.com>
* Remove usage of deprecated io/ioutil package
Signed-off-by: Thane Thomson <connect@thanethomson.com>
* Remove unused mockBlockStore
Signed-off-by: Thane Thomson <connect@thanethomson.com>
* blockchain/v2: Remove unused method
Signed-off-by: Thane Thomson <connect@thanethomson.com>
* Bulk fix lints
Signed-off-by: Thane Thomson <connect@thanethomson.com>
* lint: Ignore auto-generated query PEG
Signed-off-by: Thane Thomson <connect@thanethomson.com>
Signed-off-by: Thane Thomson <connect@thanethomson.com>
Co-authored-by: Thane Thomson <connect@thanethomson.com>
86 lines
1.8 KiB
Go
86 lines
1.8 KiB
Go
package client
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
"strings"
|
|
|
|
types "github.com/tendermint/tendermint/rpc/jsonrpc/types"
|
|
)
|
|
|
|
const (
|
|
// URIClientRequestID in a request ID used by URIClient
|
|
URIClientRequestID = types.JSONRPCIntID(-1)
|
|
)
|
|
|
|
// URIClient is a JSON-RPC client, which sends POST form HTTP requests to the
|
|
// remote server.
|
|
//
|
|
// URIClient is safe for concurrent use by multiple goroutines.
|
|
type URIClient struct {
|
|
address string
|
|
client *http.Client
|
|
}
|
|
|
|
var _ HTTPClient = (*URIClient)(nil)
|
|
|
|
// NewURI returns a new client.
|
|
// An error is returned on invalid remote.
|
|
// The function panics when remote is nil.
|
|
func NewURI(remote string) (*URIClient, error) {
|
|
parsedURL, err := newParsedURL(remote)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
httpClient, err := DefaultHTTPClient(remote)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
parsedURL.SetDefaultSchemeHTTP()
|
|
|
|
uriClient := &URIClient{
|
|
address: parsedURL.GetTrimmedURL(),
|
|
client: httpClient,
|
|
}
|
|
|
|
return uriClient, nil
|
|
}
|
|
|
|
// Call issues a POST form HTTP request.
|
|
func (c *URIClient) Call(ctx context.Context, method string,
|
|
params map[string]interface{}, result interface{},
|
|
) (interface{}, error) {
|
|
values, err := argsToURLValues(params)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to encode params: %w", err)
|
|
}
|
|
|
|
req, err := http.NewRequestWithContext(
|
|
ctx,
|
|
http.MethodPost,
|
|
c.address+"/"+method,
|
|
strings.NewReader(values.Encode()),
|
|
)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("new request: %w", err)
|
|
}
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
resp, err := c.client.Do(req)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("post: %w", err)
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
responseBytes, err := io.ReadAll(resp.Body)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("read response body: %w", err)
|
|
}
|
|
|
|
return unmarshalResponseBytes(responseBytes, URIClientRequestID, result)
|
|
}
|