Skip to content

Commit

Permalink
ci: run linter in ./api package (hashicorp#19513)
Browse files Browse the repository at this point in the history
  • Loading branch information
lgfa29 authored Dec 19, 2023
1 parent 95766aa commit e4e70b0
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 42 deletions.
3 changes: 3 additions & 0 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ check: ## Lint the source code
@echo "==> Linting source code..."
@golangci-lint run

@echo "==> Linting ./api source code..."
@cd ./api && golangci-lint run --config ../.golangci.yml

@echo "==> Linting hclog statements..."
@hclogvet .

Expand Down
2 changes: 1 addition & 1 deletion api/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ func (a *Agent) Monitor(stopCh <-chan struct{}, q *QueryOptions) (<-chan *Stream
}

r.setQueryOptions(q)
_, resp, err := requireOK(a.client.doRequest(r))
_, resp, err := requireOK(a.client.doRequest(r)) //nolint:bodyclose
if err != nil {
errCh <- err
return nil, errCh
Expand Down
4 changes: 2 additions & 2 deletions api/allocations_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ func (s *execSession) startConnection() (*websocket.Conn, error) {
var conn *websocket.Conn

if nodeClient != nil {
conn, _, _ = nodeClient.websocket(reqPath, q)
conn, _, _ = nodeClient.websocket(reqPath, q) //nolint:bodyclose // gorilla/websocket Dialer.DialContext() does not require the body to be closed.
}

if conn == nil {
conn, _, err = s.client.websocket(reqPath, q)
conn, _, err = s.client.websocket(reqPath, q) //nolint:bodyclose // gorilla/websocket Dialer.DialContext() does not require the body to be closed.
if err != nil {
return nil, err
}
Expand Down
12 changes: 6 additions & 6 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ func (c *Client) rawQuery(endpoint string, q *QueryOptions) (io.ReadCloser, erro
return nil, err
}
r.setQueryOptions(q)
_, resp, err := requireOK(c.doRequest(r))
_, resp, err := requireOK(c.doRequest(r)) //nolint:bodyclose // Closing the body is the caller's responsibility.
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1036,7 +1036,7 @@ func (c *Client) query(endpoint string, out any, q *QueryOptions) (*QueryMeta, e
return nil, err
}
r.setQueryOptions(q)
rtt, resp, err := requireOK(c.doRequest(r))
rtt, resp, err := requireOK(c.doRequest(r)) //nolint:bodyclose // Closing the body is the caller's responsibility.
if err != nil {
return nil, err
}
Expand All @@ -1061,7 +1061,7 @@ func (c *Client) putQuery(endpoint string, in, out any, q *QueryOptions) (*Query
}
r.setQueryOptions(q)
r.obj = in
rtt, resp, err := requireOK(c.doRequest(r))
rtt, resp, err := requireOK(c.doRequest(r)) //nolint:bodyclose // Closing the body is the caller's responsibility.
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1092,7 +1092,7 @@ func (c *Client) postQuery(endpoint string, in, out any, q *QueryOptions) (*Quer
}
r.setQueryOptions(q)
r.obj = in
rtt, resp, err := requireOK(c.doRequest(r))
rtt, resp, err := requireOK(c.doRequest(r)) //nolint:bodyclose // Closing the body is the caller's responsibility.
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1125,7 +1125,7 @@ func (c *Client) write(verb, endpoint string, in, out any, q *WriteOptions) (*Wr
}
r.setWriteOptions(q)
r.obj = in
rtt, resp, err := requireOK(c.doRequest(r))
rtt, resp, err := requireOK(c.doRequest(r)) //nolint:bodyclose // Closing the body is the caller's responsibility.
if err != nil {
return nil, err
}
Expand All @@ -1151,7 +1151,7 @@ func (c *Client) delete(endpoint string, in, out any, q *WriteOptions) (*WriteMe
}
r.setWriteOptions(q)
r.obj = in
rtt, resp, err := requireOK(c.doRequest(r))
rtt, resp, err := requireOK(c.doRequest(r)) //nolint:bodyclose // Closing the body is the caller's responsibility.
if err != nil {
return nil, err
}
Expand Down
5 changes: 1 addition & 4 deletions api/consul.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ type ConsulMeshGateway struct {
func (c *ConsulMeshGateway) Canonicalize() {
// Mode may be empty string, indicating behavior will defer to Consul
// service-defaults config entry.
return
}

func (c *ConsulMeshGateway) Copy() *ConsulMeshGateway {
Expand Down Expand Up @@ -630,9 +629,7 @@ type ConsulMeshConfigEntry struct {
// nothing in here
}

func (e *ConsulMeshConfigEntry) Canonicalize() {
return
}
func (e *ConsulMeshConfigEntry) Canonicalize() {}

func (e *ConsulMeshConfigEntry) Copy() *ConsulMeshConfigEntry {
if e == nil {
Expand Down
2 changes: 1 addition & 1 deletion api/event_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func (e *EventStream) Stream(ctx context.Context, topics map[Topic][]string, ind
}
}

_, resp, err := requireOK(e.client.doRequest(r))
_, resp, err := requireOK(e.client.doRequest(r)) //nolint:bodyclose

if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion api/internal/testutil/responsewriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (r *ResponseRecorder) Header() http.Header {
func (r *ResponseRecorder) HeaderMap() http.Header {
r.mu.Lock()
defer r.mu.Unlock()
return r.rr.Result().Header
return r.rr.Result().Header //nolint:bodyclose
}

// Write to the underlying response buffer. Safe to call concurrent with Read.
Expand Down
4 changes: 2 additions & 2 deletions api/internal/testutil/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,15 +373,15 @@ func (s *TestServer) url(path string) string {

// requireOK checks the HTTP response code and ensures it is acceptable.
func (s *TestServer) requireOK(resp *http.Response) error {
if resp.StatusCode != 200 {
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("bad status code: %d", resp.StatusCode)
}
return nil
}

// put performs a new HTTP PUT request.
func (s *TestServer) put(path string, body io.Reader) *http.Response {
req, err := http.NewRequest("PUT", s.url(path), body)
req, err := http.NewRequest(http.MethodPut, s.url(path), body)
must.NoError(s.t, err)

resp, err := s.HTTPClient.Do(req)
Expand Down
19 changes: 9 additions & 10 deletions api/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (op *Operator) RaftGetConfiguration(q *QueryOptions) (*RaftConfiguration, e
return nil, err
}
r.setQueryOptions(q)
_, resp, err := requireOK(op.c.doRequest(r))
_, resp, err := requireOK(op.c.doRequest(r)) //nolint:bodyclose
if err != nil {
return nil, err
}
Expand All @@ -91,7 +91,7 @@ func (op *Operator) RaftRemovePeerByAddress(address string, q *WriteOptions) err

r.params.Set("address", address)

_, resp, err := requireOK(op.c.doRequest(r))
_, resp, err := requireOK(op.c.doRequest(r)) //nolint:bodyclose
if err != nil {
return err
}
Expand All @@ -111,7 +111,7 @@ func (op *Operator) RaftRemovePeerByID(id string, q *WriteOptions) error {

r.params.Set("id", id)

_, resp, err := requireOK(op.c.doRequest(r))
_, resp, err := requireOK(op.c.doRequest(r)) //nolint:bodyclose
if err != nil {
return err
}
Expand All @@ -131,7 +131,7 @@ func (op *Operator) RaftTransferLeadershipByAddress(address string, q *WriteOpti

r.params.Set("address", address)

_, resp, err := requireOK(op.c.doRequest(r))
_, resp, err := requireOK(op.c.doRequest(r)) //nolint:bodyclose
if err != nil {
return err
}
Expand All @@ -151,7 +151,7 @@ func (op *Operator) RaftTransferLeadershipByID(id string, q *WriteOptions) error

r.params.Set("id", id)

_, resp, err := requireOK(op.c.doRequest(r))
_, resp, err := requireOK(op.c.doRequest(r)) //nolint:bodyclose
if err != nil {
return err
}
Expand Down Expand Up @@ -262,18 +262,17 @@ func (op *Operator) Snapshot(q *QueryOptions) (io.ReadCloser, error) {
return nil, err
}
r.setQueryOptions(q)
_, resp, err := requireOK(op.c.doRequest(r))
_, resp, err := requireOK(op.c.doRequest(r)) //nolint:bodyclose
if err != nil {
return nil, err
}
defer resp.Body.Close()

digest := resp.Header.Get("Digest")

cr, err := newChecksumValidatingReader(resp.Body, digest)
if err != nil {
io.Copy(io.Discard, resp.Body)
resp.Body.Close()

return nil, err
}

Expand Down Expand Up @@ -355,7 +354,7 @@ func (op *Operator) ApplyLicense(license string, opts *ApplyLicenseOptions, q *W
r.setWriteOptions(q)
r.body = strings.NewReader(license)

rtt, resp, err := requireOK(op.c.doRequest(r))
rtt, resp, err := requireOK(op.c.doRequest(r)) //nolint:bodyclose
if err != nil {
return nil, err
}
Expand All @@ -375,7 +374,7 @@ func (op *Operator) LicenseGet(q *QueryOptions) (*LicenseReply, *QueryMeta, erro
req.setQueryOptions(q)

var reply LicenseReply
rtt, resp, err := op.c.doRequest(req)
rtt, resp, err := op.c.doRequest(req) //nolint:bodyclose
if err != nil {
return nil, nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions api/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (c *Client) retryPut(ctx context.Context, endpoint string, in, out any, q *
var err error
var wm *WriteMeta

attemptDelay := time.Duration(100 * time.Second) // Avoid a tick before starting
attemptDelay := 100 * time.Second // Avoid a tick before starting
startTime := time.Now()

t := time.NewTimer(attemptDelay)
Expand All @@ -60,7 +60,7 @@ func (c *Client) retryPut(ctx context.Context, endpoint string, in, out any, q *
wm, err = c.put(endpoint, in, out, q)

// Maximum retry period is up, don't retry
if c.config.retryOptions.maxToLastCall != 0 && time.Now().Sub(startTime) > c.config.retryOptions.maxToLastCall {
if c.config.retryOptions.maxToLastCall != 0 && time.Since(startTime) > c.config.retryOptions.maxToLastCall {
break
}

Expand Down
3 changes: 2 additions & 1 deletion api/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ func (s *Search) FuzzySearch(text string, context contexts.Context, q *QueryOpti
// ID.
//
// e.g. A Task-level service would have scope like,
// ["<namespace>", "<job>", "<group>", "<task>"]
//
// ["<namespace>", "<job>", "<group>", "<task>"]
type FuzzyMatch struct {
ID string // ID is UUID or Name of object
Scope []string `json:",omitempty"` // IDs of parent objects
Expand Down
4 changes: 2 additions & 2 deletions api/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func NewAffinity(lTarget string, operand string, rTarget string, weight int8) *A
LTarget: lTarget,
RTarget: rTarget,
Operand: operand,
Weight: pointerOf(int8(weight)),
Weight: pointerOf(weight),
}
}

Expand Down Expand Up @@ -301,7 +301,7 @@ func NewSpreadTarget(value string, percent uint8) *SpreadTarget {
func NewSpread(attribute string, weight int8, spreadTargets []*SpreadTarget) *Spread {
return &Spread{
Attribute: attribute,
Weight: pointerOf(int8(weight)),
Weight: pointerOf(weight),
SpreadTarget: spreadTargets,
}
}
Expand Down
19 changes: 10 additions & 9 deletions api/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,8 @@ func (vars *Variables) readInternal(endpoint string, out **Variable, q *QueryOpt
}
r.setQueryOptions(q)

checkFn := requireStatusIn(http.StatusOK, http.StatusNotFound, http.StatusForbidden)
rtt, resp, err := checkFn(vars.client.doRequest(r))
checkFn := requireStatusIn(http.StatusOK, http.StatusNotFound, http.StatusForbidden) //nolint:bodyclose
rtt, resp, err := checkFn(vars.client.doRequest(r)) //nolint:bodyclose
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -284,12 +284,12 @@ func (vars *Variables) deleteInternal(path string, q *WriteOptions) (*WriteMeta,
}
r.setWriteOptions(q)

checkFn := requireStatusIn(http.StatusOK, http.StatusNoContent)
rtt, resp, err := checkFn(vars.client.doRequest(r))

checkFn := requireStatusIn(http.StatusOK, http.StatusNoContent) //nolint:bodyclose
rtt, resp, err := checkFn(vars.client.doRequest(r)) //nolint:bodyclose
if err != nil {
return nil, err
}
defer resp.Body.Close()

wm := &WriteMeta{RequestTime: rtt}
_ = parseWriteMeta(resp, wm)
Expand All @@ -305,11 +305,12 @@ func (vars *Variables) deleteChecked(path string, checkIndex uint64, q *WriteOpt
return nil, err
}
r.setWriteOptions(q)
checkFn := requireStatusIn(http.StatusOK, http.StatusNoContent, http.StatusConflict)
rtt, resp, err := checkFn(vars.client.doRequest(r))
checkFn := requireStatusIn(http.StatusOK, http.StatusNoContent, http.StatusConflict) //nolint:bodyclose
rtt, resp, err := checkFn(vars.client.doRequest(r)) //nolint:bodyclose
if err != nil {
return nil, err
}
defer resp.Body.Close()

wm := &WriteMeta{RequestTime: rtt}
_ = parseWriteMeta(resp, wm)
Expand Down Expand Up @@ -341,8 +342,8 @@ func (vars *Variables) writeChecked(endpoint string, in *Variable, out *Variable
r.setWriteOptions(q)
r.obj = in

checkFn := requireStatusIn(http.StatusOK, http.StatusNoContent, http.StatusConflict)
rtt, resp, err := checkFn(vars.client.doRequest(r))
checkFn := requireStatusIn(http.StatusOK, http.StatusNoContent, http.StatusConflict) //nolint:bodyclose
rtt, resp, err := checkFn(vars.client.doRequest(r)) //nolint:bodyclose

if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion drivers/shared/executor/procstats/list_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func List(executorPID int) *set.Set[ProcessID] {
nextPPID := stack.Pop()
result.Insert(ProcessID(nextPPID))

p, err := process.NewProcessWithContext(ctx, int32(nextPPID))
p, err := process.NewProcessWithContext(ctx, nextPPID)
if err != nil {
continue
}
Expand Down

0 comments on commit e4e70b0

Please sign in to comment.