Skip to content

Commit

Permalink
style: Use golangci-lint's suggestions
Browse files Browse the repository at this point in the history
    run `golangci-lint run ./...`
  • Loading branch information
fmyxyz committed Jun 20, 2022
1 parent 81d49d3 commit 9cc0e64
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ func (c *Cache[T]) GetType() string {
// the key if type is string or by computing a checksum of key structure
// if its type is other than string
func (c *Cache[T]) getCacheKey(key any) string {
switch key.(type) {
switch v := key.(type) {
case string:
return key.(string)
return v
case CacheKeyGenerator:
return key.(CacheKeyGenerator).GetCacheKey()
return v.GetCacheKey()
default:
return checksum(key)
}
Expand Down
2 changes: 1 addition & 1 deletion store/go_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (s *GoCacheStore) GetWithTTL(_ context.Context, key any) (any, time.Duratio
if !exists {
return data, 0, NotFoundWithCause(errors.New("value not found in GoCache store"))
}
duration := t.Sub(time.Now())
duration := time.Until(t)
return data, duration, nil
}

Expand Down
14 changes: 7 additions & 7 deletions store/pegasus.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ func NewPegasus(ctx context.Context, options *OptionsPegasus) (*PegasusStore, er
MetaServers: options.MetaServers,
})
table, err := client.OpenTable(ctx, options.TableName)
defer table.Close()
if err != nil {
return nil, err
}
defer table.Close()

return &PegasusStore{
client: client,
Expand Down Expand Up @@ -128,10 +128,10 @@ func (p *PegasusStore) Close() error {
// Get returns data stored from a given key
func (p *PegasusStore) Get(ctx context.Context, key any) (any, error) {
table, err := p.client.OpenTable(ctx, p.options.TableName)
defer table.Close()
if err != nil {
return nil, err
}
defer table.Close()

value, err := table.Get(ctx, []byte(cast.ToString(key)), empty)
if err != nil {
Expand All @@ -146,10 +146,10 @@ func (p *PegasusStore) Get(ctx context.Context, key any) (any, error) {
// GetWithTTL returns data stored from a given key and its corresponding TTL
func (p *PegasusStore) GetWithTTL(ctx context.Context, key any) (any, time.Duration, error) {
table, err := p.client.OpenTable(ctx, p.options.TableName)
defer table.Close()
if err != nil {
return nil, 0, err
}
defer table.Close()

value, err := table.Get(ctx, []byte(cast.ToString(key)), empty)
if err != nil {
Expand All @@ -172,10 +172,10 @@ func (p *PegasusStore) Set(ctx context.Context, key, value any, options ...Optio
opts := applyOptions(options...)

table, err := p.client.OpenTable(ctx, p.options.TableName)
defer table.Close()
if err != nil {
return err
}
defer table.Close()

err = table.SetTTL(ctx, []byte(cast.ToString(key)), empty, []byte(cast.ToString(value)), opts.expiration)
if err != nil {
Expand Down Expand Up @@ -224,10 +224,10 @@ func (p *PegasusStore) setTags(ctx context.Context, key any, tags []string) erro
// Delete removes data from Pegasus for given key identifier
func (p *PegasusStore) Delete(ctx context.Context, key any) error {
table, err := p.client.OpenTable(ctx, p.options.TableName)
defer table.Close()
if err != nil {
return err
}
defer table.Close()

return table.Del(ctx, []byte(cast.ToString(key)), empty)
}
Expand Down Expand Up @@ -262,10 +262,10 @@ func (p *PegasusStore) Invalidate(ctx context.Context, options ...InvalidateOpti
// Clear resets all data in the store
func (p *PegasusStore) Clear(ctx context.Context) error {
table, err := p.client.OpenTable(ctx, p.options.TableName)
defer table.Close()
if err != nil {
return err
}
defer table.Close()

// init full scan
scanners, err := table.GetUnorderedScanners(ctx, p.options.TablePartitionNum, &pegasus.ScannerOptions{
Expand All @@ -280,7 +280,7 @@ func (p *PegasusStore) Clear(ctx context.Context) error {
// full scan and delete
for _, scanner := range scanners {
// Iterates sequentially.
for true {
for {
completed, hashKey, _, _, err := scanner.Next(ctx)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion store/pegasus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ func TestNewPegasus(t *testing.T) {
ctx := context.Background()

p, err := NewPegasus(ctx, testPegasusOptions())
defer p.Close()
So(err, ShouldBeNil)
defer p.Close()
})
}

Expand Down

0 comments on commit 9cc0e64

Please sign in to comment.