Skip to content

Commit

Permalink
Merge pull request #121 from dell/golint_errors_fix
Browse files Browse the repository at this point in the history
Fixing Golinting errors
  • Loading branch information
tssushma authored Dec 22, 2023
2 parents fb7db27 + df7cfb8 commit 5ddb356
Show file tree
Hide file tree
Showing 26 changed files with 245 additions and 239 deletions.
8 changes: 5 additions & 3 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ const (
dellEmcToken = "DELL-EMC-TOKEN" // #nosec G101
)

type ContextKey string

// RequestConfig provide options for the request
type RequestConfig struct {
// http method Name
Expand Down Expand Up @@ -95,7 +97,7 @@ type RespMeta struct {
}

// ApiClient is PowerStore API client interface
type ApiClient interface {
type Client interface {
Traceable
Query(
ctx context.Context,
Expand All @@ -121,7 +123,7 @@ type ClientIMPL struct {
password string
httpClient *http.Client
defaultTimeout uint64
requestIDKey string
requestIDKey ContextKey
customHTTPHeaders http.Header
logger Logger
apiThrottle TimeoutSemaphoreInterface
Expand All @@ -131,7 +133,7 @@ type ClientIMPL struct {

// New creates and initialize API client
func New(apiURL string, username string,
password string, insecure bool, defaultTimeout, rateLimit uint64, requestIDKey string,
password string, insecure bool, defaultTimeout, rateLimit uint64, requestIDKey ContextKey,
) (*ClientIMPL, error) {
debug, _ = strconv.ParseBool(os.Getenv("GOPOWERSTORE_DEBUG"))
if apiURL == "" || username == "" || password == "" {
Expand Down
6 changes: 3 additions & 3 deletions api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ import (
)

const (
errResponseFile = "test_data/err_response.json"
unknownErrResponseFile = "test_data/unknown_error.txt"
errResponseFile = "test_data/err_response.json"
unknownErrResponseFile = "test_data/unknown_error.txt"
key ContextKey = "key"
)

func buildResp(t *testing.T, path string, statusCode int) *http.Response {
Expand Down Expand Up @@ -72,7 +73,6 @@ func TestNew(t *testing.T) {
password := "password"
timeout := uint64(120)
limit := uint64(1000)
key := "key"
var err error
var c *ClientIMPL
c, err = New(url, user, password, false, timeout, limit, key)
Expand Down
6 changes: 3 additions & 3 deletions api/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ type Logger interface {

type defaultLogger struct{}

func (dl *defaultLogger) Info(ctx context.Context, format string, args ...interface{}) {
func (dl *defaultLogger) Info(_ context.Context, format string, args ...interface{}) {
log.Printf(format, args...)
}

func (dl *defaultLogger) Debug(ctx context.Context, format string, args ...interface{}) {
func (dl *defaultLogger) Debug(_ context.Context, format string, args ...interface{}) {
if debug {
log.Printf(format, args...)
}
}

func (dl *defaultLogger) Error(ctx context.Context, format string, args ...interface{}) {
func (dl *defaultLogger) Error(_ context.Context, format string, args ...interface{}) {
log.Printf(format, args...)
}
38 changes: 19 additions & 19 deletions api/throttling.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,49 +36,49 @@ func (e *TimeoutSemaphoreError) Error() string {
return e.msg
}

type timeoutSemaphore struct {
timeout time.Duration
semaphore chan struct{}
logger Logger
type TimeoutSemaphore struct {
Timeout time.Duration
Semaphore chan struct{}
Logger Logger
}

func NewTimeoutSemaphore(timeout, rateLimit int, logger Logger) *timeoutSemaphore {
func NewTimeoutSemaphore(timeout, rateLimit int, logger Logger) *TimeoutSemaphore {
log := logger

if log == nil {
log = &defaultLogger{}
}

return &timeoutSemaphore{
timeout: time.Duration(timeout) * time.Second,
semaphore: make(chan struct{}, rateLimit),
logger: log,
return &TimeoutSemaphore{
Timeout: time.Duration(timeout) * time.Second,
Semaphore: make(chan struct{}, rateLimit),
Logger: log,
}
}

func (ts *timeoutSemaphore) Acquire(ctx context.Context) error {
func (ts *TimeoutSemaphore) Acquire(ctx context.Context) error {
var cancelFunc func()
ctx, cancelFunc = context.WithTimeout(ctx, ts.timeout)
ctx, cancelFunc = context.WithTimeout(ctx, ts.Timeout)
defer cancelFunc()
for {
select {
case ts.semaphore <- struct{}{}:
ts.logger.Debug(ctx, "acquire a lock")
case ts.Semaphore <- struct{}{}:
ts.Logger.Debug(ctx, "acquire a lock")
return nil
case <-ctx.Done():
msg := "lock is acquire failed, timeout expired"
ts.logger.Error(ctx, msg)
ts.Logger.Error(ctx, msg)
return &TimeoutSemaphoreError{msg}
}
}
}

func (ts *timeoutSemaphore) Release(ctx context.Context) {
<-ts.semaphore
ts.logger.Debug(ctx, "release a lock")
func (ts *TimeoutSemaphore) Release(ctx context.Context) {
<-ts.Semaphore
ts.Logger.Debug(ctx, "release a lock")
}

func (ts *timeoutSemaphore) SetLogger(logger Logger) TimeoutSemaphoreInterface {
ts.logger = logger
func (ts *TimeoutSemaphore) SetLogger(logger Logger) TimeoutSemaphoreInterface {
ts.Logger = logger
return ts
}
6 changes: 3 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const (

// ApiClient defines gopowerstore client interface
type Client interface {
APIClient() api.ApiClient
APIClient() api.Client
SetTraceID(ctx context.Context, value string) context.Context
SetCustomHTTPHeaders(headers http.Header)
GetCustomHTTPHeaders() http.Header
Expand Down Expand Up @@ -192,7 +192,7 @@ type Client interface {

// ClientIMPL provides basic API client implementation
type ClientIMPL struct {
API api.ApiClient
API api.Client
}

// SetTraceID method allows to set tracing ID to context which will be used in log messages
Expand All @@ -218,7 +218,7 @@ func (c *ClientIMPL) SetLogger(logger Logger) {
}

// APIClient method returns powerstore API client may be useful for doing raw API requests
func (c *ClientIMPL) APIClient() api.ApiClient {
func (c *ClientIMPL) APIClient() api.Client {
return c.API
}

Expand Down
10 changes: 7 additions & 3 deletions client_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@

package gopowerstore

import (
"github.com/dell/gopowerstore/api"
)

// ClientOptions defaults
const (
clientOptionsDefaultInsecure = false
Expand All @@ -37,7 +41,7 @@ type ClientOptions struct {
defaultTimeout *uint64
rateLimit *uint64
// define field name in context which will be used for tracing
requestIDKey *string
requestIDKey *api.ContextKey
}

// Insecure returns insecure client option
Expand Down Expand Up @@ -65,7 +69,7 @@ func (co *ClientOptions) RateLimit() uint64 {
}

// RequestIDKey returns client requestIDKey
func (co *ClientOptions) RequestIDKey() string {
func (co *ClientOptions) RequestIDKey() api.ContextKey {
if co.requestIDKey == nil {
return clientOptionsDefaultRequestIDKey
}
Expand All @@ -91,7 +95,7 @@ func (co *ClientOptions) SetRateLimit(value uint64) *ClientOptions {
}

// SetRequestIDKey sets requestIdKey value
func (co *ClientOptions) SetRequestIDKey(value string) *ClientOptions {
func (co *ClientOptions) SetRequestIDKey(value api.ContextKey) *ClientOptions {
co.requestIDKey = &value
return co
}
10 changes: 5 additions & 5 deletions fs_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ type FsCreate struct {
LockingPolicy string `json:"locking_policy,omitempty"`
FolderRenamePolicy string `json:"folder_rename_policy,omitempty"`
IsAsyncMTimeEnabled bool `json:"is_async_MTime_enabled,omitempty"`
ProtectionPolicyId string `json:"protection_policy_id,omitempty"`
ProtectionPolicyID string `json:"protection_policy_id,omitempty"`
FileEventsPublishingMode string `json:"file_events_publishing_mode,omitempty"`
HostIOSize string `json:"host_io_size,omitempty"`
FlrCreate interface{} `json:"flr_attributes,omitempty"`
Expand Down Expand Up @@ -139,13 +139,13 @@ type FileSystem struct {
// Size used, in bytes, for the data and metadata of the file system
SizeUsed int64 `json:"size_used,omitempty"`
// Id of a parent filesystem
ParentId string `json:"parent_id,omitempty"`
ParentID string `json:"parent_id,omitempty"`
}

// NFS server instance in NAS server
type NFSServerInstance struct {
// Unique identifier for NFS server
Id string `json:"id"`
ID string `json:"id"`
// IsNFSv4Enabled is set to true if nfsv4 is enabled on NAS server
IsNFSv4Enabled bool `json:"is_nfsv4_enabled,omitempty"`
}
Expand All @@ -159,11 +159,11 @@ type NAS struct {
// Name of the NAS server
Name string `json:"name,omitempty"`
// CurrentNodeId represents on which node the nas server is present
CurrentNodeId string `json:"current_node_id,omitempty"`
CurrentNodeID string `json:"current_node_id,omitempty"`
// NAS server operational status: [ Stopped, Starting, Started, Stopping, Failover, Degraded, Unknown ]
OperationalStatus NASServerOperationalStatusEnum `json:"operational_status,omitempty"`
// IPv4 file interface id nas server currently uses
CurrentPreferredIPv4InterfaceId string `json:"current_preferred_IPv4_interface_id"`
CurrentPreferredIPv4InterfaceID string `json:"current_preferred_IPv4_interface_id"`
// NfsServers define NFS server instance if nfs exports are present
NfsServers []NFSServerInstance `json:"nfs_servers"`
}
Expand Down
Binary file removed gofmt
Binary file not shown.
Binary file removed golangci-lint
Binary file not shown.
4 changes: 2 additions & 2 deletions host_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ func (c *ClientIMPL) GetHostGroups(ctx context.Context) ([]HostGroup, error) {
var result []HostGroup
err := c.readPaginatedData(func(offset int) (api.RespMeta, error) {
var page []HostGroup
host_group := HostGroup{}
qp := c.APIClient().QueryParamsWithFields(&host_group)
hostGroup := HostGroup{}
qp := c.APIClient().QueryParamsWithFields(&hostGroup)
qp.Order("name")
qp.Offset(offset).Limit(paginationDefaultPageSize)
meta, err := c.APIClient().Query(
Expand Down
6 changes: 3 additions & 3 deletions inttests/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ func TestCustomLogger(t *testing.T) {

type customLogger struct{}

func (cl *customLogger) Info(ctx context.Context, format string, args ...interface{}) {
func (cl *customLogger) Info(_ context.Context, format string, args ...interface{}) {
log.Printf("INFO:"+format, args...)
}

func (cl *customLogger) Debug(ctx context.Context, format string, args ...interface{}) {
func (cl *customLogger) Debug(_ context.Context, format string, args ...interface{}) {
log.Printf("DEBUG:"+format, args...)
}

func (cl *customLogger) Error(ctx context.Context, format string, args ...interface{}) {
func (cl *customLogger) Error(_ context.Context, format string, args ...interface{}) {
log.Printf("ERROR:"+format, args...)
}
6 changes: 3 additions & 3 deletions inttests/fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ func (suite *FsTestSuite) TestGetFsSnapshots() {

func (suite *FsTestSuite) TestGetNonExistingFsSnapshot() {
t := suite.T()
fsId, fsName := createFS(t, suite.nasID)
defer deleteFS(t, fsId)
fsID, fsName := createFS(t, suite.nasID)
defer deleteFS(t, fsID)

snap := createFsSnap(t, fsId, fsName)
snap := createFsSnap(t, fsID, fsName)
assert.NotEmpty(t, snap.ID)

_, err := C.DeleteFsSnapshot(context.Background(), snap.ID)
Expand Down
8 changes: 4 additions & 4 deletions inttests/replication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (suite *ReplicationTestSuite) TearDownSuite() {
if len(rr.ProtectionPolicies) != 1 || len(pp.ReplicationRules) != 1 || len(vg.Volumes) != 1 || len(pp.VolumeGroups) != 1 {
suite.T().Fail()
}
C.ModifyVolumeGroup(context.Background(), &gopowerstore.VolumeGroupModify{ProtectionPolicyId: ""}, suite.vg.ID)
C.ModifyVolumeGroup(context.Background(), &gopowerstore.VolumeGroupModify{ProtectionPolicyID: ""}, suite.vg.ID)
C.RemoveMembersFromVolumeGroup(context.Background(), &gopowerstore.VolumeGroupMembers{VolumeIds: []string{suite.vol.ID}}, suite.vg.ID)
C.ModifyVolume(context.Background(), &gopowerstore.VolumeModify{ProtectionPolicyID: ""}, suite.vol.ID)
C.DeleteProtectionPolicy(context.Background(), suite.pp.ID)
Expand Down Expand Up @@ -142,11 +142,11 @@ func (suite *ReplicationTestSuite) TestReplication() {
VolumeGroupID: suite.vg.ID,
})
assert.NoError(t, err)
volId := suite.vol.ID
_, err = C.GetVolumeGroupsByVolumeID(context.Background(), volId)
volID := suite.vol.ID
_, err = C.GetVolumeGroupsByVolumeID(context.Background(), volID)
assert.NoError(t, err)

for tout := 0; tout < 30; tout += 1 {
for tout := 0; tout < 30; tout++ {
_, err = C.GetReplicationSessionByLocalResourceID(context.Background(), suite.vg.ID)
if err == nil {
break
Expand Down
2 changes: 1 addition & 1 deletion inttests/snapshotrules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func createSnapshotRule(t *testing.T) (string, string) {
createParams := gopowerstore.SnapshotRuleCreate{
Name: snapshotRuleName,
DesiredRetention: 8,
Interval: gopowerstore.SnapshotRuleIntervalEnumFour_Hours,
Interval: gopowerstore.SnapshotRuleIntervalEnumFourHours,
}
createResp, err := C.CreateSnapshotRule(context.Background(), &createParams)
checkAPIErr(t, err)
Expand Down
8 changes: 4 additions & 4 deletions inttests/volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,13 @@ func TestComputeDifferences(t *testing.T) {
assert.NotEmpty(t, snap2.ID)
// Run snap diff and validate there are no differences

base_snapshot_id := snap2.ID
basesnapShotID := snap2.ID
offset := int64(0)
chunk_size := int64(DefaultChunkSize)
chunkSize := int64(DefaultChunkSize)
length := int64(DefaultVolSize)
snapdiffParams := gopowerstore.VolumeComputeDifferences{
BaseSnapshotID: &base_snapshot_id,
ChunkSize: &chunk_size,
BaseSnapshotID: &basesnapShotID,
ChunkSize: &chunkSize,
Length: &length,
Offset: &offset,
}
Expand Down
2 changes: 1 addition & 1 deletion limit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestClientIMPL_GetMaxVolumeSize(t *testing.T) {
}
tests := []struct {
name string
API api.ApiClient
API api.Client
args args
mockResponse string
want int64
Expand Down
8 changes: 4 additions & 4 deletions mocks/Client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5ddb356

Please sign in to comment.