Skip to content
This repository has been archived by the owner on Aug 23, 2023. It is now read-only.

Commit

Permalink
fix: golangci-lint errors (#7)
Browse files Browse the repository at this point in the history
fix: resolve lint errors

Signed-off-by: Max Xu <[email protected]>
  • Loading branch information
maxsxu authored Mar 16, 2023
1 parent fa1891e commit 0b629fd
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 13 deletions.
4 changes: 3 additions & 1 deletion pkg/admin/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,9 @@ func (f *functions) Upload(sourceFile, path string) error {
if err != nil {
return err
}
w.WriteField("path", path)
if err := w.WriteField("path", path); err != nil {
return err
}
err = w.Close()
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion pkg/admin/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"strconv"
"strings"

"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/proto" //nolint:staticcheck

"github.com/streamnative/pulsar-admin-go/pkg/utils"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/admin/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (t *token) CreateToken(
headers map[string]interface{}) (string, error) {
signMethod := parseAlgorithmToJwtSignMethod(algorithm)
tokenString := jwt.NewWithClaims(signMethod, mapClaims)
if headers != nil && len(headers) > 0 {
if len(headers) > 0 {
for s, i := range headers {
tokenString.Header[s] = i
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/algorithm/hmac/hs256.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ type HS256 struct{}

func (h *HS256) GenerateSecret() ([]byte, error) {
bytes := make([]byte, 32)
rand.Read(bytes)
if _, err := rand.Read(bytes); err != nil {
return nil, err
}
s := hmac.New(sha256.New, bytes)
return s.Sum(nil), nil
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/algorithm/hmac/hs384.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ type HS384 struct{}

func (h *HS384) GenerateSecret() ([]byte, error) {
bytes := make([]byte, 48)
rand.Read(bytes)
if _, err := rand.Read(bytes); err != nil {
return nil, err
}
s := hmac.New(sha512.New384, bytes)
return s.Sum(nil), nil
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/algorithm/hmac/hs512.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ type HS512 struct{}

func (h *HS512) GenerateSecret() ([]byte, error) {
bytes := make([]byte, 64)
rand.Read(bytes)
if _, err := rand.Read(bytes); err != nil {
return nil, err
}
s := hmac.New(sha512.New, bytes)
return s.Sum(nil), nil
}
Expand Down
12 changes: 7 additions & 5 deletions pkg/rest/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ func (c *Client) GetWithOptions(endpoint string, obj interface{}, params map[str
req.params = query
}

//nolint:bodyclose
resp, err := checkSuccessful(c.doRequest(req))
if err != nil {
return nil, err
Expand Down Expand Up @@ -174,6 +175,7 @@ func (c *Client) PutWithQueryParams(endpoint string, in, obj interface{}, params
req.params = query
}

//nolint:bodyclose
resp, err := checkSuccessful(c.doRequest(req))
if err != nil {
return err
Expand All @@ -197,7 +199,7 @@ func (c *Client) PutWithMultiPart(endpoint string, body io.Reader, contentType s
req.body = body
req.contentType = contentType

// nolint
//nolint
resp, err := checkSuccessful(c.doRequest(req))
if err != nil {
return err
Expand Down Expand Up @@ -225,7 +227,7 @@ func (c *Client) DeleteWithQueryParams(endpoint string, params map[string]string
req.params = query
}

// nolint
//nolint
resp, err := checkSuccessful(c.doRequest(req))
if err != nil {
return err
Expand All @@ -246,7 +248,7 @@ func (c *Client) PostWithObj(endpoint string, in, obj interface{}) error {
}
req.obj = in

// nolint
//nolint
resp, err := checkSuccessful(c.doRequest(req))
if err != nil {
return err
Expand All @@ -270,7 +272,7 @@ func (c *Client) PostWithMultiPart(endpoint string, in interface{}, body io.Read
req.body = body
req.contentType = contentType

// nolint
//nolint
resp, err := checkSuccessful(c.doRequest(req))
if err != nil {
return err
Expand All @@ -295,7 +297,7 @@ func (c *Client) PostWithQueryParams(endpoint string, in interface{}, params map
}
req.params = query
}
// nolint
//nolint
resp, err := checkSuccessful(c.doRequest(req))
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package utils

// nolint
//nolint
import (
"github.com/golang/protobuf/proto"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/namespace_name.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func validateNamespaceName(tenant, namespace string) error {
// allowed characters for property, namespace, cluster and topic
// names are alphanumeric (a-zA-Z0-9) and these special chars -=:.
// and % is allowed as part of valid URL encoding
var patten = regexp.MustCompile("^[-=:.\\w]*$")
var patten = regexp.MustCompile(`^[-=:.\w]*$`)

func CheckName(name string) bool {
return patten.MatchString(name)
Expand Down

0 comments on commit 0b629fd

Please sign in to comment.