From 657c7c9253c9b7f573fb00625371bd5842273a8c Mon Sep 17 00:00:00 2001 From: Chiman Jain Date: Mon, 6 May 2024 21:26:48 +0530 Subject: [PATCH 1/7] fix golangci-lint errors --- .github/workflows/actions.yml | 8 ++++---- .github/workflows/linters.yaml | 10 +++++----- api/api.go | 34 ++++++++++++++++------------------ api/api_logging.go | 2 +- api/json/json_encode.go | 2 +- api/json/json_scanner.go | 4 ++-- api/v1/api_v1.go | 25 +++++++++++-------------- api/v1/api_v1_exports.go | 11 +++++------ api/v1/api_v1_roles.go | 10 +++++----- api/v1/api_v1_user_groups.go | 30 +++++++++++++++--------------- api/v1/api_v1_users.go | 14 +++++++------- exports.go | 2 +- snapshots.go | 11 +++++------ 13 files changed, 78 insertions(+), 85 deletions(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 7da674a..6d03e5b 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -1,16 +1,16 @@ name: Workflow on: push: - branches: [ main ] + branches: [main] pull_request: - branches: [ main ] + branches: [main] jobs: go_security_scan: name: Go security runs-on: ubuntu-latest steps: - name: Checkout the code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Run Go Security uses: securego/gosec@master with: @@ -21,7 +21,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout the code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Run malware scan uses: dell/common-github-actions/malware-scanner@main with: diff --git a/.github/workflows/linters.yaml b/.github/workflows/linters.yaml index e7aad32..6e8a6ca 100644 --- a/.github/workflows/linters.yaml +++ b/.github/workflows/linters.yaml @@ -14,17 +14,17 @@ jobs: name: golangci-lint runs-on: ubuntu-latest steps: - - uses: actions/setup-go@v4 + - uses: actions/setup-go@v5 with: - go-version: "1.20" + go-version: "1.22" cache: false - name: Checkout the code - uses: actions/checkout@v3.2.0 + uses: actions/checkout@v4 - name: Vendor packages run: | go mod vendor - name: golangci-lint - uses: golangci/golangci-lint-action@v3 + uses: golangci/golangci-lint-action@v5 with: - version: v1.53 + version: latest skip-cache: true diff --git a/api/api.go b/api/api.go index d05648a..2071299 100755 --- a/api/api.go +++ b/api/api.go @@ -627,19 +627,18 @@ func parseJSONHTMLError(r *http.Response) error { htmlError.Message = doc.Find("title").Text() } return htmlError - } else { - jsonErr := &JSONError{} - // decode JSON error response - err := json.NewDecoder(r.Body).Decode(jsonErr) - if err != nil { - return err - } - jsonErr.StatusCode = r.StatusCode - if len(jsonErr.Err) > 0 && jsonErr.Err[0].Message == "" { - jsonErr.Err[0].Message = r.Status - } - return jsonErr } + jsonErr := &JSONError{} + // decode JSON error response + err := json.NewDecoder(r.Body).Decode(jsonErr) + if err != nil { + return err + } + jsonErr.StatusCode = r.StatusCode + if len(jsonErr.Err) > 0 && jsonErr.Err[0].Message == "" { + jsonErr.Err[0].Message = r.Status + } + return jsonErr } // Authenticate make a REST API call [/session/1/session] to PowerScale to authenticate the given credentials. @@ -650,7 +649,7 @@ func (c *client) authenticate(ctx context.Context, username string, password str data := &setupConnection{Services: []string{"platform", "namespace"}, Username: username, Password: password} resp, _, err := c.DoAndGetResponseBody(ctx, http.MethodPost, "/session/1/session", "", nil, headers, data) if err != nil { - return errors.New(fmt.Sprintf("Authentication error: %v", err)) + return fmt.Errorf("Authentication error: %v", err) } if resp != nil { @@ -669,20 +668,19 @@ func (c *client) authenticate(ctx context.Context, username string, password str case resp.StatusCode == 401: { log.Debug(ctx, "Response Code %v", resp) - return errors.New(fmt.Sprintf("Authentication failed. Unable to login to PowerScale. Verify username and password.")) + return fmt.Errorf("authentication failed. unable to login to powerscale. verify username and password") } default: - return errors.New(fmt.Sprintf("Authenticate error. Response:")) + return fmt.Errorf("authenticate error. response-") } headerRes := strings.Join(resp.Header.Values(isiSessCsrfToken), " ") startIndex, endIndex, matchStrLen := FetchValueIndexForKey(headerRes, "isisessid=", ";") if startIndex < 0 || endIndex < 0 { - return errors.New(fmt.Sprintf("Session ID not retrieved")) - } else { - c.SetAuthToken(headerRes[startIndex : startIndex+matchStrLen+endIndex]) + return fmt.Errorf("Session ID not retrieved") } + c.SetAuthToken(headerRes[startIndex : startIndex+matchStrLen+endIndex]) startIndex, endIndex, matchStrLen = FetchValueIndexForKey(headerRes, "isicsrf=", ";") if startIndex < 0 || endIndex < 0 { diff --git a/api/api_logging.go b/api/api_logging.go index 2cd09a2..fddc580 100644 --- a/api/api_logging.go +++ b/api/api_logging.go @@ -33,7 +33,7 @@ func isBinOctetBody(h http.Header) bool { return h.Get(headerKeyContentType) == headerValContentTypeBinaryOctetStream } -func logRequest(ctx context.Context, w io.Writer, req *http.Request, verbose VerboseType) { +func logRequest(_ context.Context, w io.Writer, req *http.Request, verbose VerboseType) { fmt.Fprintln(w, "") fmt.Fprint(w, " -------------------------- ") fmt.Fprint(w, "GOISILON HTTP REQUEST") diff --git a/api/json/json_encode.go b/api/json/json_encode.go index 775c897..d3a1bd6 100644 --- a/api/json/json_encode.go +++ b/api/json/json_encode.go @@ -418,7 +418,7 @@ func newTypeEncoder(t reflect.Type, allowAddr bool) encoderFunc { } } -func invalidValueEncoder(e *encodeState, v reflect.Value, _ encOpts) { +func invalidValueEncoder(e *encodeState, _ reflect.Value, _ encOpts) { e.WriteString("null") } diff --git a/api/json/json_scanner.go b/api/json/json_scanner.go index a6d8706..2c9ee8f 100644 --- a/api/json/json_scanner.go +++ b/api/json/json_scanner.go @@ -577,7 +577,7 @@ func stateNul(s *scanner, c byte) int { // stateError is the state after reaching a syntax error, // such as after reading `[1}` or `5.1.2`. -func stateError(s *scanner, c byte) int { +func stateError(_ *scanner, _ byte) int { return scanError } @@ -616,7 +616,7 @@ func (s *scanner) undo(scanCode int) { } // stateRedo helps implement the scanner's 1-byte undo. -func stateRedo(s *scanner, c byte) int { +func stateRedo(s *scanner, _ byte) int { s.redo = false s.step = s.redoState return s.redoCode diff --git a/api/v1/api_v1.go b/api/v1/api_v1.go index 91199ac..01b7a8d 100644 --- a/api/v1/api_v1.go +++ b/api/v1/api_v1.go @@ -49,15 +49,14 @@ func realexportsPath(client api.Client) string { return path.Join(exportsPath, client.VolumesPath()) } -func realVolumeSnapshotPath(client api.Client, name, zonePath, accessZone string) string { +func realVolumeSnapshotPath(client api.Client, name, zonePath, _ string) string { // Isi path is different from zone path volumeSnapshotPath := strings.Join([]string{zonePath, snapshotParentDir}, "/") if strings.Compare(zonePath, client.VolumesPath()) != 0 { parts := strings.SplitN(realNamespacePath(client), "/ifs", 2) return path.Join(parts[0], volumeSnapshotPath, name, parts[1]) - } else { - return path.Join(volumeSnapshotPath, name) } + return path.Join(volumeSnapshotPath, name) } // GetAbsoluteSnapshotPath get the absolute path of a snapshot @@ -79,31 +78,29 @@ func GetRealVolumeSnapshotPathWithIsiPath(isiPath, zonePath, name, accessZone st if accessZone == "System" { parts := strings.SplitN(GetRealNamespacePathWithIsiPath(isiPath), "/ifs", 2) return path.Join(parts[0], volumeSnapshotPath, name, parts[1]) - } else { - // if Isi path is different then zone path get remaining isiPath - _, remainIsiPath, found := strings.Cut(isiPath, zonePath) - if found { - return path.Join(namespacePath, zonePath, snapshotParentDir, name, remainIsiPath) - } else { - return path.Join(namespacePath, zonePath, snapshotParentDir, name) - } } + // if Isi path is different then zone path get remaining isiPath + _, remainIsiPath, found := strings.Cut(isiPath, zonePath) + if found { + return path.Join(namespacePath, zonePath, snapshotParentDir, name, remainIsiPath) + } + return path.Join(namespacePath, zonePath, snapshotParentDir, name) } // getAuthMemberId reutrns actual auth id, which can be 'UID:0', 'USER:name', 'GID:0', 'GROUP:wheel', // memberType can be user/group. -func getAuthMemberId(memberType string, memberName *string, memberId *int32) (authMemberId string, err error) { +func getAuthMemberId(memberType string, memberName *string, memberId *int32) (authMemberID string, err error) { memberType = strings.ToLower(memberType) if memberType != fileGroupTypeUser && memberType != fileGroupTypeGroup { return "", fmt.Errorf("member type is wrong, only support %s and %s", fileGroupTypeUser, fileGroupTypeGroup) } if memberName != nil && *memberName != "" { - authMemberId = fmt.Sprintf("%s:%s", strings.ToUpper(memberType), *memberName) + authMemberID = fmt.Sprintf("%s:%s", strings.ToUpper(memberType), *memberName) } if memberId != nil { - authMemberId = fmt.Sprintf("%sID:%d", strings.ToUpper(memberType)[0:1], *memberId) + authMemberID = fmt.Sprintf("%sID:%d", strings.ToUpper(memberType)[0:1], *memberId) } return } diff --git a/api/v1/api_v1_exports.go b/api/v1/api_v1_exports.go index 60c2885..46dcb5c 100644 --- a/api/v1/api_v1_exports.go +++ b/api/v1/api_v1_exports.go @@ -47,7 +47,6 @@ func Export( var resp *postIsiExportResp err = client.Post(ctx, exportsPath, "", nil, nil, data, &resp) - if err != nil { return err } @@ -59,7 +58,7 @@ func Export( func SetExportClients( ctx context.Context, client api.Client, - Id int, clients []string, + ID int, clients []string, ) (err error) { // PAPI call: PUT https://1.2.3.4:8080/platform/1/protocols/nfs/exports/Id // Content-Type: application/json @@ -68,7 +67,7 @@ func SetExportClients( data := &ExportClientList{Clients: clients} var resp *postIsiExportResp - err = client.Put(ctx, exportsPath, strconv.Itoa(Id), nil, nil, data, &resp) + err = client.Put(ctx, exportsPath, strconv.Itoa(ID), nil, nil, data, &resp) return err } @@ -77,15 +76,15 @@ func SetExportClients( func Unexport( ctx context.Context, client api.Client, - Id int, + ID int, ) (err error) { // PAPI call: DELETE https://1.2.3.4:8080/platform/1/protocols/nfs/exports/23 - if Id == 0 { + if ID == 0 { return errors.New("no path Id set") } - exportPath := fmt.Sprintf("%s/%d", exportsPath, Id) + exportPath := fmt.Sprintf("%s/%d", exportsPath, ID) var resp postIsiExportResp err = client.Delete(ctx, exportPath, "", nil, nil, &resp) diff --git a/api/v1/api_v1_roles.go b/api/v1/api_v1_roles.go index 7e37530..68dcdac 100644 --- a/api/v1/api_v1_roles.go +++ b/api/v1/api_v1_roles.go @@ -24,11 +24,11 @@ import ( ) // GetIsiRole queries the role by role-id. -func GetIsiRole(ctx context.Context, client api.Client, roleId string) (role *IsiRole, err error) { +func GetIsiRole(ctx context.Context, client api.Client, roleID string) (role *IsiRole, err error) { // PAPI call: GET https://1.2.3.4:8080/platform/1/auth/roles/ var roleResp *isiRoleListResp - if err = client.Get(ctx, rolePath, roleId, nil, nil, &roleResp); err != nil { + if err = client.Get(ctx, rolePath, roleID, nil, nil, &roleResp); err != nil { return } @@ -37,7 +37,7 @@ func GetIsiRole(ctx context.Context, client api.Client, roleId string) (role *Is return } - return nil, fmt.Errorf("role not found: %s", roleId) + return nil, fmt.Errorf("role not found: %s", roleID) } // GetIsiRoleList queries all roles on the cluster, filter by limit or resolveNames. @@ -108,10 +108,10 @@ func AddIsiRoleMember(ctx context.Context, client api.Client, roleID string, mem func RemoveIsiRoleMember(ctx context.Context, client api.Client, roleID string, member IsiAuthMemberItem) error { // PAPI call: DELETE https://1.2.3.4:8080/platform/1/roles/{role-id}/members/ - authMemberId, err := getAuthMemberId(member.Type, member.Name, member.Id) + authMemberID, err := getAuthMemberId(member.Type, member.Name, member.Id) if err != nil { return err } - return client.Delete(ctx, fmt.Sprintf(roleMemberPath, roleID), authMemberId, nil, nil, nil) + return client.Delete(ctx, fmt.Sprintf(roleMemberPath, roleID), authMemberID, nil, nil, nil) } diff --git a/api/v1/api_v1_user_groups.go b/api/v1/api_v1_user_groups.go index 020b2b6..925ad31 100644 --- a/api/v1/api_v1_user_groups.go +++ b/api/v1/api_v1_user_groups.go @@ -27,13 +27,13 @@ import ( func GetIsiGroup(ctx context.Context, client api.Client, groupName *string, gid *int32) (group *IsiGroup, err error) { // PAPI call: GET https://1.2.3.4:8080/platform/1/auth/groups/ - authGroupId, err := getAuthMemberId(fileGroupTypeGroup, groupName, gid) + authGroupID, err := getAuthMemberId(fileGroupTypeGroup, groupName, gid) if err != nil { return } var groupListResp *isiGroupListResp - if err = client.Get(ctx, groupPath, authGroupId, nil, nil, &groupListResp); err != nil { + if err = client.Get(ctx, groupPath, authGroupID, nil, nil, &groupListResp); err != nil { return } @@ -42,7 +42,7 @@ func GetIsiGroup(ctx context.Context, client api.Client, groupName *string, gid return } - return nil, fmt.Errorf("group not found: %s", authGroupId) + return nil, fmt.Errorf("group not found: %s", authGroupID) } // GetIsiGroupList queries all groups on the cluster with filter, @@ -108,14 +108,14 @@ func getIsiGroupListWithResume(ctx context.Context, client api.Client, resume st func GetIsiGroupMembers(ctx context.Context, client api.Client, groupName *string, gid *int32) (members []*IsiAccessItemFileGroup, err error) { // PAPI call: GET https://1.2.3.4:8080/platform/1/groups/{group-id}/members - authGroupId, err := getAuthMemberId(fileGroupTypeGroup, groupName, gid) + authGroupID, err := getAuthMemberId(fileGroupTypeGroup, groupName, gid) if err != nil { return } var groupMemberListResp *IsiGroupMemberListRespResume // First call without Resume param - if err = client.Get(ctx, fmt.Sprintf(groupMemberPath, authGroupId), "", nil, nil, &groupMemberListResp); err != nil { + if err = client.Get(ctx, fmt.Sprintf(groupMemberPath, authGroupID), "", nil, nil, &groupMemberListResp); err != nil { return } @@ -125,7 +125,7 @@ func GetIsiGroupMembers(ctx context.Context, client api.Client, groupName *strin break } - if groupMemberListResp, err = getIsiGroupMemberListWithResume(ctx, client, authGroupId, groupMemberListResp.Resume); err != nil { + if groupMemberListResp, err = getIsiGroupMemberListWithResume(ctx, client, authGroupID, groupMemberListResp.Resume); err != nil { return nil, err } } @@ -147,7 +147,7 @@ func AddIsiGroupMember(ctx context.Context, client api.Client, groupName *string // "id":"UID:1522" // } - authGroupId, err := getAuthMemberId(fileGroupTypeGroup, groupName, gid) + authGroupID, err := getAuthMemberId(fileGroupTypeGroup, groupName, gid) if err != nil { return err } @@ -165,24 +165,24 @@ func AddIsiGroupMember(ctx context.Context, client api.Client, groupName *string data.Name = *member.Name } - return client.Post(ctx, fmt.Sprintf(groupMemberPath, authGroupId), "", nil, nil, data, nil) + return client.Post(ctx, fmt.Sprintf(groupMemberPath, authGroupID), "", nil, nil, data, nil) } // RemoveIsiGroupMember remove a member from the group, member can be user/group. func RemoveIsiGroupMember(ctx context.Context, client api.Client, groupName *string, gid *int32, member IsiAuthMemberItem) error { // PAPI call: DELETE https://1.2.3.4:8080/platform/1/groups/{group-id}/members/ - authGroupId, err := getAuthMemberId(fileGroupTypeGroup, groupName, gid) + authGroupID, err := getAuthMemberId(fileGroupTypeGroup, groupName, gid) if err != nil { return err } - authMemberId, err := getAuthMemberId(member.Type, member.Name, member.Id) + authMemberID, err := getAuthMemberId(member.Type, member.Name, member.Id) if err != nil { return err } - return client.Delete(ctx, fmt.Sprintf(groupMemberPath, authGroupId), authMemberId, nil, nil, nil) + return client.Delete(ctx, fmt.Sprintf(groupMemberPath, authGroupID), authMemberID, nil, nil, nil) } // CreateIsiGroup creates a new group. @@ -272,21 +272,21 @@ func UpdateIsiGroupGID(ctx context.Context, client api.Client, groupName *string values.StringAdd("provider", *queryProvider) } - authGroupId, err := getAuthMemberId(fileGroupTypeGroup, groupName, gid) + authGroupID, err := getAuthMemberId(fileGroupTypeGroup, groupName, gid) if err != nil { return } - return client.Put(ctx, groupPath, authGroupId, values, nil, &IsiUpdateGroupReq{newGid}, nil) + return client.Put(ctx, groupPath, authGroupID, values, nil, &IsiUpdateGroupReq{newGid}, nil) } // DeleteIsiGroup removes the group by group-id. func DeleteIsiGroup(ctx context.Context, client api.Client, groupName *string, gid *int32) (err error) { // PAPI call: DELETE https://1.2.3.4:8080/platform/1/auth/groups/ - authGroupId, err := getAuthMemberId(fileGroupTypeGroup, groupName, gid) + authGroupID, err := getAuthMemberId(fileGroupTypeGroup, groupName, gid) if err != nil { return } - return client.Delete(ctx, groupPath, authGroupId, nil, nil, nil) + return client.Delete(ctx, groupPath, authGroupID, nil, nil, nil) } diff --git a/api/v1/api_v1_users.go b/api/v1/api_v1_users.go index 2d4bd58..82a5ab3 100644 --- a/api/v1/api_v1_users.go +++ b/api/v1/api_v1_users.go @@ -26,13 +26,13 @@ import ( func GetIsiUser(ctx context.Context, client api.Client, userName *string, uid *int32) (user *IsiUser, err error) { // PAPI call: GET https://1.2.3.4:8080/platform/1/auth/users/ - authUserId, err := getAuthMemberId(fileGroupTypeUser, userName, uid) + authUserID, err := getAuthMemberId(fileGroupTypeUser, userName, uid) if err != nil { return } var userListResp *isiUserListResp - if err = client.Get(ctx, userPath, authUserId, nil, nil, &userListResp); err != nil { + if err = client.Get(ctx, userPath, authUserID, nil, nil, &userListResp); err != nil { return } @@ -41,7 +41,7 @@ func GetIsiUser(ctx context.Context, client api.Client, userName *string, uid *i return } - return nil, fmt.Errorf("user not found: %s", authUserId) + return nil, fmt.Errorf("user not found: %s", authUserID) } // GetIsiUserList queries all users on the cluster, @@ -203,7 +203,7 @@ func UpdateIsiUser(ctx context.Context, client api.Client, userName *string, uid // "uid": "int", // "unlock": "bool" // } - authUserId, err := getAuthMemberId(fileGroupTypeUser, userName, uid) + authUserID, err := getAuthMemberId(fileGroupTypeUser, userName, uid) if err != nil { return } @@ -247,17 +247,17 @@ func UpdateIsiUser(ctx context.Context, client api.Client, userName *string, uid Unlock: unlock, } - return client.Put(ctx, userPath, authUserId, values, nil, data, nil) + return client.Put(ctx, userPath, authUserID, values, nil, data, nil) } // DeleteIsiUser removes the user by user-id. func DeleteIsiUser(ctx context.Context, client api.Client, userName *string, uid *int32) (err error) { // PAPI call: DELETE https://1.2.3.4:8080/platform/1/auth/users/ - authUserId, err := getAuthMemberId(fileGroupTypeUser, userName, uid) + authUserID, err := getAuthMemberId(fileGroupTypeUser, userName, uid) if err != nil { return } - return client.Delete(ctx, userPath, authUserId, nil, nil, nil) + return client.Delete(ctx, userPath, authUserID, nil, nil, nil) } diff --git a/exports.go b/exports.go index b971f76..4df9405 100644 --- a/exports.go +++ b/exports.go @@ -764,7 +764,7 @@ func (c *Client) exportAddReadWriteClients(ctx context.Context, export Export, c ctx, c.API, &apiv2.Export{ID: export.ID, ReadWriteClients: updatedReadWriteClients}, export.Zone, ignoreUnresolvableHosts) } -func (c *Client) getUpdatedClients(ctx context.Context, exportID int, clients *[]string, clientsToAdd []string) *[]string { +func (c *Client) getUpdatedClients(_ context.Context, _ int, clients *[]string, clientsToAdd []string) *[]string { if clients == nil { clients = &clientsToAdd } else { diff --git a/snapshots.go b/snapshots.go index 6dca598..e64c436 100644 --- a/snapshots.go +++ b/snapshots.go @@ -231,14 +231,14 @@ func (c *Client) GetSnapshotFolderSize(ctx context.Context, // GetSnapshotIsiPath returns the snapshot directory path func (c *Client) GetSnapshotIsiPath( ctx context.Context, - isiPath, snapshotId string, accessZone string, + isiPath, snapshotID string, accessZone string, ) (string, error) { - snapshot, err := c.GetIsiSnapshotByIdentity(ctx, snapshotId) + snapshot, err := c.GetIsiSnapshotByIdentity(ctx, snapshotID) if err != nil { return "", err } if snapshot == nil { - return "", fmt.Errorf("Snapshot doesn't exist for snapshot id: (%s) and access Zone (%s)", snapshotId, accessZone) + return "", fmt.Errorf("Snapshot doesn't exist for snapshot id: (%s) and access Zone (%s)", snapshotID, accessZone) } // get zone base path @@ -253,10 +253,9 @@ func (c *Client) GetSnapshotIsiPath( if strings.Compare(zone.Path, isiPath) != 0 { parts := strings.SplitN(snapshotPath, namespacePath, 2) if len(parts) < 2 { - return "", fmt.Errorf("Snapshot doesn't exist for snapshot id: (%s)", snapshotId) + return "", fmt.Errorf("Snapshot doesn't exist for snapshot id: (%s)", snapshotID) } return parts[1], nil - } else { - return path.Join(zone.Path, snapShot, snapshot.Name, path.Base(snapshot.Path)), nil } + return path.Join(zone.Path, snapShot, snapshot.Name, path.Base(snapshot.Path)), nil } From 90383982423f12f92e18f7cf6109c718e9a627f4 Mon Sep 17 00:00:00 2001 From: Chiman Jain Date: Tue, 7 May 2024 11:23:13 +0530 Subject: [PATCH 2/7] fix more errors --- api/v1/api_v1.go | 6 +++--- api/v1/api_v1_quotas.go | 2 +- api/v1/api_v1_user_groups.go | 4 ++-- user_test.go | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/api/v1/api_v1.go b/api/v1/api_v1.go index 01b7a8d..b061636 100644 --- a/api/v1/api_v1.go +++ b/api/v1/api_v1.go @@ -89,7 +89,7 @@ func GetRealVolumeSnapshotPathWithIsiPath(isiPath, zonePath, name, accessZone st // getAuthMemberId reutrns actual auth id, which can be 'UID:0', 'USER:name', 'GID:0', 'GROUP:wheel', // memberType can be user/group. -func getAuthMemberId(memberType string, memberName *string, memberId *int32) (authMemberID string, err error) { +func getAuthMemberId(memberType string, memberName *string, memberID *int32) (authMemberID string, err error) { memberType = strings.ToLower(memberType) if memberType != fileGroupTypeUser && memberType != fileGroupTypeGroup { return "", fmt.Errorf("member type is wrong, only support %s and %s", fileGroupTypeUser, fileGroupTypeGroup) @@ -99,8 +99,8 @@ func getAuthMemberId(memberType string, memberName *string, memberId *int32) (au authMemberID = fmt.Sprintf("%s:%s", strings.ToUpper(memberType), *memberName) } - if memberId != nil { - authMemberID = fmt.Sprintf("%sID:%d", strings.ToUpper(memberType)[0:1], *memberId) + if memberID != nil { + authMemberID = fmt.Sprintf("%sID:%d", strings.ToUpper(memberType)[0:1], *memberID) } return } diff --git a/api/v1/api_v1_quotas.go b/api/v1/api_v1_quotas.go index cea343e..cef79b1 100644 --- a/api/v1/api_v1_quotas.go +++ b/api/v1/api_v1_quotas.go @@ -148,7 +148,7 @@ func CreateIsiQuota( if softGracePrd == 0 { thresholds.SoftGrace = nil } - var data *IsiQuotaReq = &IsiQuotaReq{ + var data = &IsiQuotaReq{ Enforced: true, IncludeSnapshots: false, Path: path, diff --git a/api/v1/api_v1_user_groups.go b/api/v1/api_v1_user_groups.go index 925ad31..d929531 100644 --- a/api/v1/api_v1_user_groups.go +++ b/api/v1/api_v1_user_groups.go @@ -133,8 +133,8 @@ func GetIsiGroupMembers(ctx context.Context, client api.Client, groupName *strin } // getIsiGroupMemberListWithResume queries the next page group members based on resume token. -func getIsiGroupMemberListWithResume(ctx context.Context, client api.Client, groupId, resume string) (members *IsiGroupMemberListRespResume, err error) { - err = client.Get(ctx, fmt.Sprintf(groupMemberPath, groupId), "", api.OrderedValues{{[]byte("resume"), []byte(resume)}}, nil, &members) +func getIsiGroupMemberListWithResume(ctx context.Context, client api.Client, groupID, resume string) (members *IsiGroupMemberListRespResume, err error) { + err = client.Get(ctx, fmt.Sprintf(groupMemberPath, groupID), "", api.OrderedValues{{[]byte("resume"), []byte(resume)}}, nil, &members) return } diff --git a/user_test.go b/user_test.go index 3732c86..5cd13fb 100644 --- a/user_test.go +++ b/user_test.go @@ -84,11 +84,11 @@ func TestUserUpdate(t *testing.T) { email := "test.dell.com" pw := "testPW" - newUid := int32(100000) + newUID := int32(100000) queryForce := true - err = client.UpdateUserByNameOrUID(defaultCtx, &userName, nil, &queryForce, nil, nil, &email, nil, &pw, nil, nil, nil, &newUid, nil, nil, nil, nil, nil, nil) + err = client.UpdateUserByNameOrUID(defaultCtx, &userName, nil, &queryForce, nil, nil, &email, nil, &pw, nil, nil, nil, &newUID, nil, nil, nil, nil, nil, nil) assertNoError(t, err) - userNew, err := client.GetUserByNameOrUID(defaultCtx, &userName, &newUid) + userNew, err := client.GetUserByNameOrUID(defaultCtx, &userName, &newUID) assertNoError(t, err) assertNotNil(t, userNew) assertEqual(t, user.Dn, userNew.Dn) @@ -96,6 +96,6 @@ func TestUserUpdate(t *testing.T) { assertEqual(t, user.Provider, userNew.Provider) assertEqual(t, email, userNew.Email) assertNotEqual(t, user.Email, userNew.Uid.Id) - assertEqual(t, fmt.Sprintf("UID:%d", newUid), userNew.Uid.Id) + assertEqual(t, fmt.Sprintf("UID:%d", newUID), userNew.Uid.Id) assertNotEqual(t, user.Uid.Id, userNew.Uid.Id) } From 21810330b534039e256c07d0fbd2629e0e517664 Mon Sep 17 00:00:00 2001 From: Chiman Jain Date: Tue, 7 May 2024 15:13:59 +0530 Subject: [PATCH 3/7] fix more errors --- exports_test.go | 19 ++++++------ replication.go | 81 ++++++++++++++++++++++++------------------------- role_test.go | 24 +++++++-------- shares_test.go | 4 +-- 4 files changed, 63 insertions(+), 65 deletions(-) diff --git a/exports_test.go b/exports_test.go index f782bf6..5013c70 100644 --- a/exports_test.go +++ b/exports_test.go @@ -285,10 +285,10 @@ func testUserMapping( } var ( - getClients = func(ctx context.Context, e Export) []string { + getClients = func(_ context.Context, e Export) []string { return *e.Clients } - getRootClients = func(ctx context.Context, e Export) []string { + getRootClients = func(_ context.Context, e Export) []string { return *e.RootClients } ) @@ -707,9 +707,8 @@ func TestGetExportsWithPagination(t *testing.T) { if err != nil { if resume == "" { panic("The last call got the last page") - } else { - panic(err) } + panic(err) } resumeCallID := exports.Exports[0].ID @@ -762,10 +761,10 @@ func TestClient_ExportLifeCycleWithStructParams(t *testing.T) { assertNil(t, err) assert.Equal(t, 1, len(listExports.Exports)) - exportId := strconv.Itoa(int(res.Id)) + exportID := strconv.Itoa(int(res.Id)) // Test getExport getExport, err := client.GetExportWithStructParams(defaultCtx, apiv4.GetV2NfsExportRequest{ - V2NfsExportId: exportId, + V2NfsExportId: exportID, }) assertNil(t, err) assert.Equal(t, 1, len(getExport.Exports)) @@ -774,22 +773,22 @@ func TestClient_ExportLifeCycleWithStructParams(t *testing.T) { // Test getExport readOnly := true err = client.UpdateExportWithStructParams(defaultCtx, apiv4.UpdateV4NfsExportRequest{ - V2NfsExportId: exportId, + V2NfsExportId: exportID, V2NfsExport: &openapi.V2NfsExportExtendedExtended{ ReadOnly: &readOnly, }, }) assertNil(t, err) getUpdatedExport, err := client.GetExportWithStructParams(defaultCtx, apiv4.GetV2NfsExportRequest{ - V2NfsExportId: exportId, + V2NfsExportId: exportID, }) assert.Equal(t, true, *(getUpdatedExport.Exports[0].ReadOnly)) // Test delete export - err = client.DeleteExportWithStructParams(defaultCtx, apiv4.DeleteV4NfsExportRequest{V2NfsExportId: exportId}) + err = client.DeleteExportWithStructParams(defaultCtx, apiv4.DeleteV4NfsExportRequest{V2NfsExportId: exportID}) assertNil(t, err) _, err = client.GetExportWithStructParams(defaultCtx, apiv4.GetV2NfsExportRequest{ - V2NfsExportId: exportId, + V2NfsExportId: exportID, }) assertNotNil(t, err) } diff --git a/replication.go b/replication.go index 9990320..cc0ccf6 100644 --- a/replication.go +++ b/replication.go @@ -367,54 +367,53 @@ func (c *Client) SyncPolicy(ctx context.Context, policyName string) error { return err } return nil - } else { - jobReq := &apiv11.JobRequest{ - Id: policyName, + } + jobReq := &apiv11.JobRequest{ + Id: policyName, + } + log.Info(ctx, "found no active sync jobs, starting a new one") + + // workaround for PowerScale KB article + // https://www.dell.com/support/kbdoc/en-us/000019414/quotas-on-synciq-source-directories + for i := 0; i < maxRetries; i++ { + _, err := c.StartSyncIQJob(ctx, jobReq) + if err == nil { + break } - log.Info(ctx, "found no active sync jobs, starting a new one") - - // workaround for PowerScale KB article - // https://www.dell.com/support/kbdoc/en-us/000019414/quotas-on-synciq-source-directories - for i := 0; i < maxRetries; i++ { - _, err := c.StartSyncIQJob(ctx, jobReq) - if err == nil { - break - } - if strings.Contains(err.Error(), retryablePolicyError) { - if i+1 == maxRetries { - return err - } - - reports, err := c.GetReportsByPolicyName(ctx, policyName, 1) - if err != nil { - return fmt.Errorf("error while retrieving reports for failed sync job %s %s", policyName, err.Error()) - } - if !(len(reports.Reports) > 0 && len(reports.Reports[0].Errors) > 0 && - strings.Contains(reports.Reports[0].Errors[0], retryableReportError)) { - return fmt.Errorf("found no retryable error in reports for failed sync job %s", policyName) - } - - log.Info(ctx, "Sync job failed with error: %s. %v of %v - retrying in %v...", - reports.Reports[0].Errors[0], i+1, maxRetries, retryInterval) - time.Sleep(retryInterval) - - // Resolve policy with error before retrying - err = c.ResolvePolicy(ctx, policyName) - if err != nil { - return err - } - } else { // not a retryable error + if strings.Contains(err.Error(), retryablePolicyError) { + if i+1 == maxRetries { return err } - } - time.Sleep(3 * time.Second) - err = c.WaitForNoActiveJobs(ctx, policyName) - if err != nil { + reports, err := c.GetReportsByPolicyName(ctx, policyName, 1) + if err != nil { + return fmt.Errorf("error while retrieving reports for failed sync job %s %s", policyName, err.Error()) + } + if !(len(reports.Reports) > 0 && len(reports.Reports[0].Errors) > 0 && + strings.Contains(reports.Reports[0].Errors[0], retryableReportError)) { + return fmt.Errorf("found no retryable error in reports for failed sync job %s", policyName) + } + + log.Info(ctx, "Sync job failed with error: %s. %v of %v - retrying in %v...", + reports.Reports[0].Errors[0], i+1, maxRetries, retryInterval) + time.Sleep(retryInterval) + + // Resolve policy with error before retrying + err = c.ResolvePolicy(ctx, policyName) + if err != nil { + return err + } + } else { // not a retryable error return err } - return nil } + + time.Sleep(3 * time.Second) + err = c.WaitForNoActiveJobs(ctx, policyName) + if err != nil { + return err + } + return nil } func (c *Client) GetJobsByPolicyName(ctx context.Context, policyName string) ([]apiv11.Job, error) { diff --git a/role_test.go b/role_test.go index 6c2eb1e..66f5f31 100644 --- a/role_test.go +++ b/role_test.go @@ -44,10 +44,10 @@ func TestRoleGet(t *testing.T) { // Test GetRoleByID(), AddRoleMember(), RemoveRoleMember() and IsRoleMemberOf() func TestRoleMemberAdd(t *testing.T) { - roleId := "SystemAdmin" + roleID := "SystemAdmin" userName := "test_user_roleMember" - role, err := client.GetRoleByID(defaultCtx, roleId) + role, err := client.GetRoleByID(defaultCtx, roleID) if err != nil { panic(err) } @@ -68,27 +68,27 @@ func TestRoleMemberAdd(t *testing.T) { Name: &userName, } - isRoleMember, err := client.IsRoleMemberOf(defaultCtx, roleId, memberUserWithName) + isRoleMember, err := client.IsRoleMemberOf(defaultCtx, roleID, memberUserWithName) if err != nil { panic(err) } assertFalse(t, isRoleMember) - err = client.AddRoleMember(defaultCtx, roleId, memberUserWithName) + err = client.AddRoleMember(defaultCtx, roleID, memberUserWithName) if err != nil { panic(err) } - isRoleMember, err = client.IsRoleMemberOf(defaultCtx, roleId, memberUserWithName) + isRoleMember, err = client.IsRoleMemberOf(defaultCtx, roleID, memberUserWithName) if err != nil { panic(err) } assertTrue(t, isRoleMember) - err = client.RemoveRoleMember(defaultCtx, roleId, memberUserWithName) + err = client.RemoveRoleMember(defaultCtx, roleID, memberUserWithName) if err != nil { panic(err) } - isRoleMember, err = client.IsRoleMemberOf(defaultCtx, roleId, memberUserWithName) + isRoleMember, err = client.IsRoleMemberOf(defaultCtx, roleID, memberUserWithName) if err != nil { panic(err) } @@ -100,25 +100,25 @@ func TestRoleMemberAdd(t *testing.T) { if err != nil { panic(err) } - memberUserWithUid := api.IsiAuthMemberItem{ + memberUserWithUID := api.IsiAuthMemberItem{ Type: "user", Id: &uid32, } - err = client.AddRoleMember(defaultCtx, roleId, memberUserWithUid) + err = client.AddRoleMember(defaultCtx, roleID, memberUserWithUID) if err != nil { panic(err) } - isRoleMember, err = client.IsRoleMemberOf(defaultCtx, roleId, memberUserWithUid) + isRoleMember, err = client.IsRoleMemberOf(defaultCtx, roleID, memberUserWithUID) if err != nil { panic(err) } assertTrue(t, isRoleMember) - err = client.RemoveRoleMember(defaultCtx, roleId, memberUserWithUid) + err = client.RemoveRoleMember(defaultCtx, roleID, memberUserWithUID) if err != nil { panic(err) } - isRoleMember, err = client.IsRoleMemberOf(defaultCtx, roleId, memberUserWithUid) + isRoleMember, err = client.IsRoleMemberOf(defaultCtx, roleID, memberUserWithUID) if err != nil { panic(err) } diff --git a/shares_test.go b/shares_test.go index e2776b0..026b0dd 100644 --- a/shares_test.go +++ b/shares_test.go @@ -33,7 +33,7 @@ func TestClient_SmbShareWithStructParams(t *testing.T) { } func TestClient_SmbShareLifeCycleWithStructParams(t *testing.T) { - trusteeId := "SID:S-1-1-0" + trusteeID := "SID:S-1-1-0" trusteeName := "Everyone" trusteeType := "wellknown" shareName := "tf_share" @@ -45,7 +45,7 @@ func TestClient_SmbShareLifeCycleWithStructParams(t *testing.T) { Permission: "full", PermissionType: "allow", Trustee: openapi.V1AuthAccessAccessItemFileGroup{ - Id: &trusteeId, + Id: &trusteeID, Name: &trusteeName, Type: &trusteeType, }, From 0faad3e5b40fc0cabad7ca7c3952ffadac43cb93 Mon Sep 17 00:00:00 2001 From: Chiman Jain Date: Fri, 10 May 2024 15:25:49 +0530 Subject: [PATCH 4/7] fix more golangci errors --- .golangci.yaml | 2 -- api/api.go | 6 +++--- api/common/utils/utils_test.go | 2 +- api/v1/api_v1.go | 4 ++-- api/v1/api_v1_quotas.go | 2 +- api/v1/api_v1_roles.go | 2 +- api/v1/api_v1_user_groups.go | 14 +++++++------- api/v1/api_v1_users.go | 6 +++--- cluster_test.go | 2 +- exports_test.go | 2 +- quota_test.go | 10 +++++----- replication_test.go | 2 +- snapshots_test.go | 22 +++++++++++----------- zones_test.go | 2 +- 14 files changed, 38 insertions(+), 40 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index 56f5332..3157d04 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -1,8 +1,6 @@ run: timeout: 20m - issue-exit-code: 0 # we will change this later tests: true - skip-dirs-use-default: true modules-download-mode: readonly issues: diff --git a/api/api.go b/api/api.go index 2071299..3465a65 100755 --- a/api/api.go +++ b/api/api.go @@ -47,7 +47,7 @@ const ( defaultVolumesPathPermissions = "0777" defaultIgnoreUnresolvableHosts = false headerISISessToken = "Cookie" - headerISICSRFToken = "X-CSRF-Token" + headerISICSRFToken = "X-CSRF-Token" //nolint:gosec,G101 headerISIReferer = "Referer" isiSessCsrfToken = "Set-Cookie" authTypeBasic = 0 @@ -266,7 +266,7 @@ func New( if opts.Insecure { c.http.Transport = &http.Transport{ TLSClientConfig: &tls.Config{ - InsecureSkipVerify: true, + InsecureSkipVerify: true, //nolint:gosec,G402 }, } } else { @@ -275,7 +275,7 @@ func New( return nil, err } c.http.Transport = &http.Transport{ - TLSClientConfig: &tls.Config{ + TLSClientConfig: &tls.Config{ //nolint:gosec,G402 RootCAs: pool, InsecureSkipVerify: false, }, diff --git a/api/common/utils/utils_test.go b/api/common/utils/utils_test.go index 493e91f..3f5b18e 100644 --- a/api/common/utils/utils_test.go +++ b/api/common/utils/utils_test.go @@ -22,7 +22,7 @@ import ( "github.com/stretchr/testify/assert" ) -func TestMain(m *testing.M) { +func TestMain(_ *testing.M) { fmt.Print("executing TestMain\n") } diff --git a/api/v1/api_v1.go b/api/v1/api_v1.go index b061636..43c4b0f 100644 --- a/api/v1/api_v1.go +++ b/api/v1/api_v1.go @@ -87,9 +87,9 @@ func GetRealVolumeSnapshotPathWithIsiPath(isiPath, zonePath, name, accessZone st return path.Join(namespacePath, zonePath, snapshotParentDir, name) } -// getAuthMemberId reutrns actual auth id, which can be 'UID:0', 'USER:name', 'GID:0', 'GROUP:wheel', +// getAuthMemberID returns actual auth id, which can be 'UID:0', 'USER:name', 'GID:0', 'GROUP:wheel', // memberType can be user/group. -func getAuthMemberId(memberType string, memberName *string, memberID *int32) (authMemberID string, err error) { +func getAuthMemberID(memberType string, memberName *string, memberID *int32) (authMemberID string, err error) { memberType = strings.ToLower(memberType) if memberType != fileGroupTypeUser && memberType != fileGroupTypeGroup { return "", fmt.Errorf("member type is wrong, only support %s and %s", fileGroupTypeUser, fileGroupTypeGroup) diff --git a/api/v1/api_v1_quotas.go b/api/v1/api_v1_quotas.go index cef79b1..7d70b40 100644 --- a/api/v1/api_v1_quotas.go +++ b/api/v1/api_v1_quotas.go @@ -148,7 +148,7 @@ func CreateIsiQuota( if softGracePrd == 0 { thresholds.SoftGrace = nil } - var data = &IsiQuotaReq{ + data := &IsiQuotaReq{ Enforced: true, IncludeSnapshots: false, Path: path, diff --git a/api/v1/api_v1_roles.go b/api/v1/api_v1_roles.go index 68dcdac..41211d3 100644 --- a/api/v1/api_v1_roles.go +++ b/api/v1/api_v1_roles.go @@ -108,7 +108,7 @@ func AddIsiRoleMember(ctx context.Context, client api.Client, roleID string, mem func RemoveIsiRoleMember(ctx context.Context, client api.Client, roleID string, member IsiAuthMemberItem) error { // PAPI call: DELETE https://1.2.3.4:8080/platform/1/roles/{role-id}/members/ - authMemberID, err := getAuthMemberId(member.Type, member.Name, member.Id) + authMemberID, err := getAuthMemberID(member.Type, member.Name, member.Id) if err != nil { return err } diff --git a/api/v1/api_v1_user_groups.go b/api/v1/api_v1_user_groups.go index d929531..b249ed6 100644 --- a/api/v1/api_v1_user_groups.go +++ b/api/v1/api_v1_user_groups.go @@ -27,7 +27,7 @@ import ( func GetIsiGroup(ctx context.Context, client api.Client, groupName *string, gid *int32) (group *IsiGroup, err error) { // PAPI call: GET https://1.2.3.4:8080/platform/1/auth/groups/ - authGroupID, err := getAuthMemberId(fileGroupTypeGroup, groupName, gid) + authGroupID, err := getAuthMemberID(fileGroupTypeGroup, groupName, gid) if err != nil { return } @@ -108,7 +108,7 @@ func getIsiGroupListWithResume(ctx context.Context, client api.Client, resume st func GetIsiGroupMembers(ctx context.Context, client api.Client, groupName *string, gid *int32) (members []*IsiAccessItemFileGroup, err error) { // PAPI call: GET https://1.2.3.4:8080/platform/1/groups/{group-id}/members - authGroupID, err := getAuthMemberId(fileGroupTypeGroup, groupName, gid) + authGroupID, err := getAuthMemberID(fileGroupTypeGroup, groupName, gid) if err != nil { return } @@ -147,7 +147,7 @@ func AddIsiGroupMember(ctx context.Context, client api.Client, groupName *string // "id":"UID:1522" // } - authGroupID, err := getAuthMemberId(fileGroupTypeGroup, groupName, gid) + authGroupID, err := getAuthMemberID(fileGroupTypeGroup, groupName, gid) if err != nil { return err } @@ -172,12 +172,12 @@ func AddIsiGroupMember(ctx context.Context, client api.Client, groupName *string func RemoveIsiGroupMember(ctx context.Context, client api.Client, groupName *string, gid *int32, member IsiAuthMemberItem) error { // PAPI call: DELETE https://1.2.3.4:8080/platform/1/groups/{group-id}/members/ - authGroupID, err := getAuthMemberId(fileGroupTypeGroup, groupName, gid) + authGroupID, err := getAuthMemberID(fileGroupTypeGroup, groupName, gid) if err != nil { return err } - authMemberID, err := getAuthMemberId(member.Type, member.Name, member.Id) + authMemberID, err := getAuthMemberID(member.Type, member.Name, member.Id) if err != nil { return err } @@ -272,7 +272,7 @@ func UpdateIsiGroupGID(ctx context.Context, client api.Client, groupName *string values.StringAdd("provider", *queryProvider) } - authGroupID, err := getAuthMemberId(fileGroupTypeGroup, groupName, gid) + authGroupID, err := getAuthMemberID(fileGroupTypeGroup, groupName, gid) if err != nil { return } @@ -283,7 +283,7 @@ func UpdateIsiGroupGID(ctx context.Context, client api.Client, groupName *string // DeleteIsiGroup removes the group by group-id. func DeleteIsiGroup(ctx context.Context, client api.Client, groupName *string, gid *int32) (err error) { // PAPI call: DELETE https://1.2.3.4:8080/platform/1/auth/groups/ - authGroupID, err := getAuthMemberId(fileGroupTypeGroup, groupName, gid) + authGroupID, err := getAuthMemberID(fileGroupTypeGroup, groupName, gid) if err != nil { return } diff --git a/api/v1/api_v1_users.go b/api/v1/api_v1_users.go index 82a5ab3..ad09fa9 100644 --- a/api/v1/api_v1_users.go +++ b/api/v1/api_v1_users.go @@ -26,7 +26,7 @@ import ( func GetIsiUser(ctx context.Context, client api.Client, userName *string, uid *int32) (user *IsiUser, err error) { // PAPI call: GET https://1.2.3.4:8080/platform/1/auth/users/ - authUserID, err := getAuthMemberId(fileGroupTypeUser, userName, uid) + authUserID, err := getAuthMemberID(fileGroupTypeUser, userName, uid) if err != nil { return } @@ -203,7 +203,7 @@ func UpdateIsiUser(ctx context.Context, client api.Client, userName *string, uid // "uid": "int", // "unlock": "bool" // } - authUserID, err := getAuthMemberId(fileGroupTypeUser, userName, uid) + authUserID, err := getAuthMemberID(fileGroupTypeUser, userName, uid) if err != nil { return } @@ -254,7 +254,7 @@ func UpdateIsiUser(ctx context.Context, client api.Client, userName *string, uid func DeleteIsiUser(ctx context.Context, client api.Client, userName *string, uid *int32) (err error) { // PAPI call: DELETE https://1.2.3.4:8080/platform/1/auth/users/ - authUserID, err := getAuthMemberId(fileGroupTypeUser, userName, uid) + authUserID, err := getAuthMemberID(fileGroupTypeUser, userName, uid) if err != nil { return } diff --git a/cluster_test.go b/cluster_test.go index 755bf97..caec1da 100644 --- a/cluster_test.go +++ b/cluster_test.go @@ -42,7 +42,7 @@ func TestGetFloatStatistics(*testing.T) { } // Test if the local serial can be returned normally -func TestGetLocalSerial(t *testing.T) { +func TestGetLocalSerial(_ *testing.T) { // Get local serial localSerial, err := client.GetLocalSerial(defaultCtx) if err != nil { diff --git a/exports_test.go b/exports_test.go index 5013c70..442a040 100644 --- a/exports_test.go +++ b/exports_test.go @@ -686,7 +686,7 @@ func testExportClientsClear( assert.Len(t, getClients(defaultCtx, export), 0) } -func TestGetExportsWithPagination(t *testing.T) { +func TestGetExportsWithPagination(_ *testing.T) { // This test makes assumption that the number of exports is no less than 2 limit := "2" params := api.OrderedValues{ diff --git a/quota_test.go b/quota_test.go index 18818d2..0cecabe 100644 --- a/quota_test.go +++ b/quota_test.go @@ -23,7 +23,7 @@ import ( ) // Test both GetQuota() and SetQuota() -func TestQuotaGetSet(t *testing.T) { +func TestQuotaGetSet(_ *testing.T) { volumeName := "test_quota_get_set" quotaSize := int64(1234567) var softLimit, advisoryLimit, softGracePrd int64 @@ -76,7 +76,7 @@ func TestAllQuotasGet(t *testing.T) { } // Test UpdateQuota() -func TestQuotaUpdate(t *testing.T) { +func TestQuotaUpdate(_ *testing.T) { volumeName := "test_quota_update" quotaSize := int64(1234567) updatedQuotaSize := int64(22345000) @@ -127,7 +127,7 @@ func TestQuotaUpdate(t *testing.T) { } // Test ClearQuota() -func TestQuotaClear(t *testing.T) { +func TestQuotaClear(_ *testing.T) { volumeName := "test_quota_clear" quotaSize := int64(1234567) var softLimit, advisoryLimit, softGracePrd int64 @@ -174,7 +174,7 @@ func TestQuotaClear(t *testing.T) { } // Test ClearQuotaByID() -func TestQuotaClearByID(t *testing.T) { +func TestQuotaClearByID(_ *testing.T) { volumeName := "test_quota_clear_by_id" quotaSize := int64(1234567) var softLimit, advisoryLimit, softGracePrd int64 @@ -222,7 +222,7 @@ func TestIsQuotaLicenseActivated(t *testing.T) { } // Test TestQuotaUpdateByID() -func TestQuotaUpdateByID(t *testing.T) { +func TestQuotaUpdateByID(_ *testing.T) { volumeName := "test_quota_update" quotaSize := int64(1234567) updatedQuotaSize := int64(22345000) diff --git a/replication_test.go b/replication_test.go index af422f5..7b89dce 100644 --- a/replication_test.go +++ b/replication_test.go @@ -292,6 +292,6 @@ func (suite *ReplicationTestSuite) TestReplication() { suite.NoError(err) } -func TestReplicationSuite(t *testing.T) { +func TestReplicationSuite(_ *testing.T) { // suite.Run(t, new(ReplicationTestSuite)) } diff --git a/snapshots_test.go b/snapshots_test.go index 16685b9..b3e61c7 100644 --- a/snapshots_test.go +++ b/snapshots_test.go @@ -23,7 +23,7 @@ import ( apiv1 "github.com/dell/goisilon/api/v1" ) -func TestSnapshotsGet(t *testing.T) { +func TestSnapshotsGet(_ *testing.T) { snapshotPath := "test_snapshots_get_volume" snapshotName1 := "test_snapshots_get_snapshot_0" snapshotName2 := "test_snapshots_get_snapshot_1" @@ -93,7 +93,7 @@ func TestSnapshotsGet(t *testing.T) { } } -func TestSnapshotsGetByPath(t *testing.T) { +func TestSnapshotsGetByPath(_ *testing.T) { snapshotPath1 := "test_snapshots_get_by_path_volume_1" snapshotPath2 := "test_snapshots_get_by_path_volume_2" snapshotName1 := "test_snapshots_get_by_path_snapshot_1" @@ -177,7 +177,7 @@ func TestSnapshotsGetByPath(t *testing.T) { } } -func TestSnapshotCreate(t *testing.T) { +func TestSnapshotCreate(_ *testing.T) { snapshotPath := "test_snapshot_create_volume" snapshotName := "test_snapshot_create_snapshot" @@ -220,7 +220,7 @@ func TestSnapshotCreate(t *testing.T) { } } -func TestSnapshotRemove(t *testing.T) { +func TestSnapshotRemove(_ *testing.T) { snapshotPath := "test_snapshot_remove_volume" snapshotName := "test_snapshot_remove_snapshot" @@ -257,7 +257,7 @@ func TestSnapshotRemove(t *testing.T) { } } -func TestSnapshotCopy(t *testing.T) { +func TestSnapshotCopy(_ *testing.T) { accessZone := "System" sourceSnapshotPath := "test_snapshot_copy_src_volume" sourceSnapshotName := "test_snapshot_copy_src_snapshot" @@ -329,7 +329,7 @@ func TestSnapshotCopy(t *testing.T) { } } -func TestSnapshotCopyWithIsiPath(t *testing.T) { +func TestSnapshotCopyWithIsiPath(_ *testing.T) { sourceSnapshotPath := "test_snapshot_copy_src_volume" sourceSnapshotName := "test_snapshot_copy_src_snapshot" destinationVolume := "test_snapshot_copy_dst_volume" @@ -402,7 +402,7 @@ func TestSnapshotCopyWithIsiPath(t *testing.T) { } } -func TestSnapshotGetByIdentity(t *testing.T) { +func TestSnapshotGetByIdentity(_ *testing.T) { snapshotPath := "test_snapshots_get_volume" snapshotName1 := "test_snapshots_get_snapshot_0" snapshotName2 := "test_snapshots_get_snapshot_1" @@ -445,7 +445,7 @@ func TestSnapshotGetByIdentity(t *testing.T) { } } -func TestSnapshotIsExistent(t *testing.T) { +func TestSnapshotIsExistent(_ *testing.T) { snapshotPath := "test_snapshots_exist_volume" snapshotName1 := "test_snapshots_exist_snapshot_0" @@ -477,7 +477,7 @@ func TestSnapshotIsExistent(t *testing.T) { } } -func TestSnapshotExportWithZone(t *testing.T) { +func TestSnapshotExportWithZone(_ *testing.T) { snapshotPath := "test_snapshots_export_volume" snapshotName1 := "test_snapshots_export_snapshot_0" defaultAccessZone := "System" @@ -509,7 +509,7 @@ func TestSnapshotExportWithZone(t *testing.T) { defer client.UnexportByIDWithZone(defaultCtx, id, defaultAccessZone) } -func TestGetRealVolumeSnapshotPathWithIsiPath(t *testing.T) { +func TestGetRealVolumeSnapshotPathWithIsiPath(_ *testing.T) { volName := "volFromSnap0" newIsiPath := os.Getenv("GOISILON_VOLUMEPATH") accessZone := "System" @@ -517,7 +517,7 @@ func TestGetRealVolumeSnapshotPathWithIsiPath(t *testing.T) { fmt.Printf(apiv1.GetRealVolumeSnapshotPathWithIsiPath(newIsiPath, volName, name, accessZone)) } -func TestSnapshotSizeGet(t *testing.T) { +func TestSnapshotSizeGet(_ *testing.T) { snapshotPath := "test_snapshots_get_volume" snapshotName1 := "test_snapshots_get_snapshot_0" accessZone := "System" diff --git a/zones_test.go b/zones_test.go index f6321d4..fcc11a3 100644 --- a/zones_test.go +++ b/zones_test.go @@ -18,7 +18,7 @@ package goisilon import "testing" // Test if the zone returns correctly matched the name parsed in -func TestGetZoneByName(t *testing.T) { +func TestGetZoneByName(_ *testing.T) { // Get local serial name := "csi0zone" zone, err := client.GetZoneByName(defaultCtx, name) From a63ab002462da0cfc007bf2111c5e321fe390f91 Mon Sep 17 00:00:00 2001 From: Chiman Jain Date: Fri, 10 May 2024 15:56:54 +0530 Subject: [PATCH 5/7] add exclude rules --- .golangci.yaml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.golangci.yaml b/.golangci.yaml index 3157d04..77f8319 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -7,6 +7,15 @@ issues: max-issues-per-linter: 0 max-same-issues: 0 new: false + exclude: + - "error-naming: error var invalidFileMode should have name of the form errFoo" + - "var-naming: struct field" + - "var-naming: don't use underscores in Go names" + - "var-naming: func parameter" + - "var-naming: don't use ALL_CAPS in Go names; use CamelCase" + - "var-naming: method parameter" + - "var-naming: type" + - "unexported-return: exported func" output: print-linter-name: true From a16c0425cb3d501cec505de1bd1b9a70a9c2ca21 Mon Sep 17 00:00:00 2001 From: Chiman Jain Date: Fri, 10 May 2024 15:58:31 +0530 Subject: [PATCH 6/7] remove gosec exclusion --- .github/workflows/actions.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 6d03e5b..2e3220d 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -15,7 +15,7 @@ jobs: uses: securego/gosec@master with: # added additional exclude arguments after gosec v2.9.4 came out - args: -exclude=G104,G402,G101 ./... + args: -exclude=G402,G101 ./... malware_security_scan: name: Malware Scanner runs-on: ubuntu-latest From 8dfec37c5f5280c3afd4600b4d512e46b53248c0 Mon Sep 17 00:00:00 2001 From: Chiman Jain Date: Fri, 10 May 2024 17:59:23 +0530 Subject: [PATCH 7/7] fix gosec issues --- .github/workflows/actions.yml | 2 +- api/api.go | 2 +- api/api_logging.go | 4 +- api/api_ordered_values.go | 2 +- api/json/json_encode.go | 160 +++++++++++++++++----------------- api/json/json_stream.go | 2 +- 6 files changed, 86 insertions(+), 86 deletions(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 2e3220d..553ccd8 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -15,7 +15,7 @@ jobs: uses: securego/gosec@master with: # added additional exclude arguments after gosec v2.9.4 came out - args: -exclude=G402,G101 ./... + args: -exclude=G101,G402 ./... malware_security_scan: name: Malware Scanner runs-on: ubuntu-latest diff --git a/api/api.go b/api/api.go index 3465a65..5816d6c 100755 --- a/api/api.go +++ b/api/api.go @@ -284,7 +284,7 @@ func New( } if c.authType == authTypeSessionBased { - c.authenticate(ctx, username, password, hostname) + _ = c.authenticate(ctx, username, password, hostname) } resp := &apiVerResponse{} if err := c.Get(ctx, "/platform/latest", "", nil, nil, resp); err != nil && diff --git a/api/api_logging.go b/api/api_logging.go index fddc580..2e5e4b9 100644 --- a/api/api_logging.go +++ b/api/api_logging.go @@ -47,7 +47,7 @@ func logRequest(_ context.Context, w io.Writer, req *http.Request, verbose Verbo // full logging, i.e. print full request message content buf, _ := httputil.DumpRequest(req, !isBinOctetBody(req.Header)) decodedBuf := encryptPassword(buf) - WriteIndented(w, decodedBuf) + _ = WriteIndented(w, decodedBuf) fmt.Fprintln(w) } } @@ -75,7 +75,7 @@ func logResponse(ctx context.Context, res *http.Response, verbose VerboseType) { } // when DumpResponse gets err, buf will be nil. No message content will be printed - WriteIndented(w, buf) + _ = WriteIndented(w, buf) log.Debug(ctx, w.String()) } diff --git a/api/api_ordered_values.go b/api/api_ordered_values.go index e3d85e6..17f46c6 100644 --- a/api/api_ordered_values.go +++ b/api/api_ordered_values.go @@ -201,7 +201,7 @@ func (v *OrderedValues) Del(key []byte) { // using insertion order. func (v *OrderedValues) Encode() string { buf := &bytes.Buffer{} - v.EncodeTo(buf) + _ = v.EncodeTo(buf) return buf.String() } diff --git a/api/json/json_encode.go b/api/json/json_encode.go index d3a1bd6..d4b1b0a 100644 --- a/api/json/json_encode.go +++ b/api/json/json_encode.go @@ -419,12 +419,12 @@ func newTypeEncoder(t reflect.Type, allowAddr bool) encoderFunc { } func invalidValueEncoder(e *encodeState, _ reflect.Value, _ encOpts) { - e.WriteString("null") + _, _ = e.WriteString("null") } func marshalerEncoder(e *encodeState, v reflect.Value, opts encOpts) { if v.Kind() == reflect.Ptr && v.IsNil() { - e.WriteString("null") + _, _ = e.WriteString("null") return } m := v.Interface().(Marshaler) @@ -441,7 +441,7 @@ func marshalerEncoder(e *encodeState, v reflect.Value, opts encOpts) { func addrMarshalerEncoder(e *encodeState, v reflect.Value, _ encOpts) { va := v.Addr() if va.IsNil() { - e.WriteString("null") + _, _ = e.WriteString("null") return } m := va.Interface().(Marshaler) @@ -457,7 +457,7 @@ func addrMarshalerEncoder(e *encodeState, v reflect.Value, _ encOpts) { func textMarshalerEncoder(e *encodeState, v reflect.Value, opts encOpts) { if v.Kind() == reflect.Ptr && v.IsNil() { - e.WriteString("null") + _, _ = e.WriteString("null") return } m := v.Interface().(encoding.TextMarshaler) @@ -471,7 +471,7 @@ func textMarshalerEncoder(e *encodeState, v reflect.Value, opts encOpts) { func addrTextMarshalerEncoder(e *encodeState, v reflect.Value, opts encOpts) { va := v.Addr() if va.IsNil() { - e.WriteString("null") + _, _ = e.WriteString("null") return } m := va.Interface().(encoding.TextMarshaler) @@ -484,37 +484,37 @@ func addrTextMarshalerEncoder(e *encodeState, v reflect.Value, opts encOpts) { func boolEncoder(e *encodeState, v reflect.Value, opts encOpts) { if opts.quoted { - e.WriteByte('"') + _ = e.WriteByte('"') } if v.Bool() { - e.WriteString("true") + _, _ = e.WriteString("true") } else { - e.WriteString("false") + _, _ = e.WriteString("false") } if opts.quoted { - e.WriteByte('"') + _ = e.WriteByte('"') } } func intEncoder(e *encodeState, v reflect.Value, opts encOpts) { b := strconv.AppendInt(e.scratch[:0], v.Int(), 10) if opts.quoted { - e.WriteByte('"') + _ = e.WriteByte('"') } - e.Write(b) + _, _ = e.Write(b) if opts.quoted { - e.WriteByte('"') + _ = e.WriteByte('"') } } func uintEncoder(e *encodeState, v reflect.Value, opts encOpts) { b := strconv.AppendUint(e.scratch[:0], v.Uint(), 10) if opts.quoted { - e.WriteByte('"') + _ = e.WriteByte('"') } - e.Write(b) + _, _ = e.Write(b) if opts.quoted { - e.WriteByte('"') + _ = e.WriteByte('"') } } @@ -527,11 +527,11 @@ func (bits floatEncoder) encode(e *encodeState, v reflect.Value, opts encOpts) { } b := strconv.AppendFloat(e.scratch[:0], f, 'g', -1, int(bits)) if opts.quoted { - e.WriteByte('"') + _ = e.WriteByte('"') } - e.Write(b) + _, _ = e.Write(b) if opts.quoted { - e.WriteByte('"') + _ = e.WriteByte('"') } } @@ -551,7 +551,7 @@ func stringEncoder(e *encodeState, v reflect.Value, opts encOpts) { if !isValidNumber(numStr) { e.error(fmt.Errorf("json: invalid number literal %q", numStr)) } - e.WriteString(numStr) + _, _ = e.WriteString(numStr) return } if opts.quoted { @@ -567,7 +567,7 @@ func stringEncoder(e *encodeState, v reflect.Value, opts encOpts) { func interfaceEncoder(e *encodeState, v reflect.Value, opts encOpts) { if v.IsNil() { - e.WriteString("null") + _, _ = e.WriteString("null") return } e.reflectValue(v.Elem(), opts) @@ -583,7 +583,7 @@ type structEncoder struct { } func (se *structEncoder) encode(e *encodeState, v reflect.Value, opts encOpts) { - e.WriteByte('{') + _ = e.WriteByte('{') first := true for i, f := range se.fields { if f.omitMarshal { @@ -596,14 +596,14 @@ func (se *structEncoder) encode(e *encodeState, v reflect.Value, opts encOpts) { if first { first = false } else { - e.WriteByte(',') + _ = e.WriteByte(',') } e.string(f.name, opts.escapeHTML) - e.WriteByte(':') + _ = e.WriteByte(':') opts.quoted = f.quoted se.fieldEncs[i](e, fv, opts) } - e.WriteByte('}') + _ = e.WriteByte('}') } func newStructEncoder(t reflect.Type) encoderFunc { @@ -624,10 +624,10 @@ type mapEncoder struct { func (me *mapEncoder) encode(e *encodeState, v reflect.Value, opts encOpts) { if v.IsNil() { - e.WriteString("null") + _, _ = e.WriteString("null") return } - e.WriteByte('{') + _ = e.WriteByte('{') // Extract and sort the keys. keys := v.MapKeys() @@ -642,13 +642,13 @@ func (me *mapEncoder) encode(e *encodeState, v reflect.Value, opts encOpts) { for i, kv := range sv { if i > 0 { - e.WriteByte(',') + _ = e.WriteByte(',') } e.string(kv.s, opts.escapeHTML) - e.WriteByte(':') + _ = e.WriteByte(':') me.elemEnc(e, v.MapIndex(kv.v), opts) } - e.WriteByte('}') + _ = e.WriteByte('}') } func newMapEncoder(t reflect.Type) encoderFunc { @@ -667,24 +667,24 @@ func newMapEncoder(t reflect.Type) encoderFunc { func encodeByteSlice(e *encodeState, v reflect.Value, _ encOpts) { if v.IsNil() { - e.WriteString("null") + _, _ = e.WriteString("null") return } s := v.Bytes() - e.WriteByte('"') + _ = e.WriteByte('"') if len(s) < 1024 { // for small buffers, using Encode directly is much faster. dst := make([]byte, base64.StdEncoding.EncodedLen(len(s))) base64.StdEncoding.Encode(dst, s) - e.Write(dst) + _, _ = e.Write(dst) } else { // for large buffers, avoid unnecessary extra temporary // buffer space. enc := base64.NewEncoder(base64.StdEncoding, e) - enc.Write(s) - enc.Close() + _, _ = enc.Write(s) + _ = enc.Close() } - e.WriteByte('"') + _ = e.WriteByte('"') } // sliceEncoder just wraps an arrayEncoder, checking to make sure the value isn't nil. @@ -694,7 +694,7 @@ type sliceEncoder struct { func (se *sliceEncoder) encode(e *encodeState, v reflect.Value, opts encOpts) { if v.IsNil() { - e.WriteString("null") + _, _ = e.WriteString("null") return } se.arrayEnc(e, v, opts) @@ -717,15 +717,15 @@ type arrayEncoder struct { } func (ae *arrayEncoder) encode(e *encodeState, v reflect.Value, opts encOpts) { - e.WriteByte('[') + _ = e.WriteByte('[') n := v.Len() for i := 0; i < n; i++ { if i > 0 { - e.WriteByte(',') + _ = e.WriteByte(',') } ae.elemEnc(e, v.Index(i), opts) } - e.WriteByte(']') + _ = e.WriteByte(']') } func newArrayEncoder(t reflect.Type) encoderFunc { @@ -739,7 +739,7 @@ type ptrEncoder struct { func (pe *ptrEncoder) encode(e *encodeState, v reflect.Value, opts encOpts) { if v.IsNil() { - e.WriteString("null") + _, _ = e.WriteString("null") return } pe.elemEnc(e, v.Elem(), opts) @@ -849,7 +849,7 @@ func (sv byString) Less(i, j int) bool { return sv[i].s < sv[j].s } // NOTE: keep in sync with stringBytes below. func (e *encodeState) string(s string, escapeHTML bool) int { len0 := e.Len() - e.WriteByte('"') + _ = e.WriteByte('"') start := 0 for i := 0; i < len(s); { if b := s[i]; b < utf8.RuneSelf { @@ -859,30 +859,30 @@ func (e *encodeState) string(s string, escapeHTML bool) int { continue } if start < i { - e.WriteString(s[start:i]) + _, _ = e.WriteString(s[start:i]) } switch b { case '\\', '"': - e.WriteByte('\\') - e.WriteByte(b) + _ = e.WriteByte('\\') + _ = e.WriteByte(b) case '\n': - e.WriteByte('\\') - e.WriteByte('n') + _ = e.WriteByte('\\') + _ = e.WriteByte('n') case '\r': - e.WriteByte('\\') - e.WriteByte('r') + _ = e.WriteByte('\\') + _ = e.WriteByte('r') case '\t': - e.WriteByte('\\') - e.WriteByte('t') + _ = e.WriteByte('\\') + _ = e.WriteByte('t') default: // This encodes bytes < 0x20 except for \t, \n and \r. // If escapeHTML is set, it also escapes <, >, and & // because they can lead to security holes when // user-controlled strings are rendered into JSON // and served to some browsers. - e.WriteString(`\u00`) - e.WriteByte(hex[b>>4]) - e.WriteByte(hex[b&0xF]) + _, _ = e.WriteString(`\u00`) + _ = e.WriteByte(hex[b>>4]) + _ = e.WriteByte(hex[b&0xF]) } i++ start = i @@ -891,9 +891,9 @@ func (e *encodeState) string(s string, escapeHTML bool) int { c, size := utf8.DecodeRuneInString(s[i:]) if c == utf8.RuneError && size == 1 { if start < i { - e.WriteString(s[start:i]) + _, _ = e.WriteString(s[start:i]) } - e.WriteString(`\ufffd`) + _, _ = e.WriteString(`\ufffd`) i += size start = i continue @@ -907,10 +907,10 @@ func (e *encodeState) string(s string, escapeHTML bool) int { // See http://timelessrepo.com/json-isnt-a-javascript-subset for discussion. if c == '\u2028' || c == '\u2029' { if start < i { - e.WriteString(s[start:i]) + _, _ = e.WriteString(s[start:i]) } - e.WriteString(`\u202`) - e.WriteByte(hex[c&0xF]) + _, _ = e.WriteString(`\u202`) + _ = e.WriteByte(hex[c&0xF]) i += size start = i continue @@ -918,16 +918,16 @@ func (e *encodeState) string(s string, escapeHTML bool) int { i += size } if start < len(s) { - e.WriteString(s[start:]) + _, _ = e.WriteString(s[start:]) } - e.WriteByte('"') + _ = e.WriteByte('"') return e.Len() - len0 } // NOTE: keep in sync with string above. func (e *encodeState) stringBytes(s []byte, escapeHTML bool) int { len0 := e.Len() - e.WriteByte('"') + _ = e.WriteByte('"') start := 0 for i := 0; i < len(s); { if b := s[i]; b < utf8.RuneSelf { @@ -937,30 +937,30 @@ func (e *encodeState) stringBytes(s []byte, escapeHTML bool) int { continue } if start < i { - e.Write(s[start:i]) + _, _ = e.Write(s[start:i]) } switch b { case '\\', '"': - e.WriteByte('\\') - e.WriteByte(b) + _ = e.WriteByte('\\') + _ = e.WriteByte(b) case '\n': - e.WriteByte('\\') - e.WriteByte('n') + _ = e.WriteByte('\\') + _ = e.WriteByte('n') case '\r': - e.WriteByte('\\') - e.WriteByte('r') + _ = e.WriteByte('\\') + _ = e.WriteByte('r') case '\t': - e.WriteByte('\\') - e.WriteByte('t') + _ = e.WriteByte('\\') + _ = e.WriteByte('t') default: // This encodes bytes < 0x20 except for \t, \n and \r. // If escapeHTML is set, it also escapes <, >, and & // because they can lead to security holes when // user-controlled strings are rendered into JSON // and served to some browsers. - e.WriteString(`\u00`) - e.WriteByte(hex[b>>4]) - e.WriteByte(hex[b&0xF]) + _, _ = e.WriteString(`\u00`) + _ = e.WriteByte(hex[b>>4]) + _ = e.WriteByte(hex[b&0xF]) } i++ start = i @@ -969,9 +969,9 @@ func (e *encodeState) stringBytes(s []byte, escapeHTML bool) int { c, size := utf8.DecodeRune(s[i:]) if c == utf8.RuneError && size == 1 { if start < i { - e.Write(s[start:i]) + _, _ = e.Write(s[start:i]) } - e.WriteString(`\ufffd`) + _, _ = e.WriteString(`\ufffd`) i += size start = i continue @@ -985,10 +985,10 @@ func (e *encodeState) stringBytes(s []byte, escapeHTML bool) int { // See http://timelessrepo.com/json-isnt-a-javascript-subset for discussion. if c == '\u2028' || c == '\u2029' { if start < i { - e.Write(s[start:i]) + _, _ = e.Write(s[start:i]) } - e.WriteString(`\u202`) - e.WriteByte(hex[c&0xF]) + _, _ = e.WriteString(`\u202`) + _ = e.WriteByte(hex[c&0xF]) i += size start = i continue @@ -996,9 +996,9 @@ func (e *encodeState) stringBytes(s []byte, escapeHTML bool) int { i += size } if start < len(s) { - e.Write(s[start:]) + _, _ = e.Write(s[start:]) } - e.WriteByte('"') + _ = e.WriteByte('"') return e.Len() - len0 } diff --git a/api/json/json_stream.go b/api/json/json_stream.go index 7892c65..83ac722 100644 --- a/api/json/json_stream.go +++ b/api/json/json_stream.go @@ -201,7 +201,7 @@ func (enc *Encoder) Encode(v interface{}) error { // is required if the encoded value was a number, // so that the reader knows there aren't more // digits coming. - e.WriteByte('\n') + _ = e.WriteByte('\n') b := e.Bytes() if enc.indentPrefix != "" || enc.indentValue != "" {