Skip to content

Commit

Permalink
feat: add ContextCacher, GenLogger interface
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Apr 22, 2022
1 parent e9ede1e commit 1246581
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
fail-fast: true
matrix:
go: [1.15]
go: [1.17]

steps:
- name: Checkout
Expand Down
19 changes: 18 additions & 1 deletion cacher.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gsr

import (
"context"
"io"
"time"
)
Expand All @@ -9,7 +10,7 @@ import (
type SimpleCacher interface {
// Closer close cache handle
io.Closer
// Clear clear all caches
// Clear all cache data
Clear() error

// Has basic operation
Expand All @@ -24,6 +25,22 @@ type SimpleCacher interface {
DelMulti(keys []string) error
}

// ContextCacher interface.
type ContextCacher interface {
SimpleCacher

// HasWithCtx basic operation
HasWithCtx(ctx context.Context, key string) bool
DelWithCtx(ctx context.Context, key string) error
GetWithCtx(ctx context.Context, key string) interface{}
SetWithCtx(ctx context.Context, key string, val interface{}, ttl time.Duration) error

// MGetWithCtx multi keys operation
MGetWithCtx(ctx context.Context, keys []string) map[string]interface{}
MSetWithCtx(ctx context.Context, values map[string]interface{}, ttl time.Duration) error
MDelWithCtx(ctx context.Context, keys []string) error
}

// CodedCacher interface.
type CodedCacher interface {
SimpleCacher
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/gookit/gsr

go 1.12
go 1.13
11 changes: 8 additions & 3 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ type StdLogger interface {
Panicln(v ...interface{})
}

// Logger interface definition
type Logger interface {
StdLogger
// GenLogger generic logger interface definition
type GenLogger interface {
Debug(v ...interface{})
Debugf(format string, v ...interface{})
Info(v ...interface{})
Expand All @@ -31,3 +30,9 @@ type Logger interface {
Error(v ...interface{})
Errorf(format string, v ...interface{})
}

// Logger interface definition
type Logger interface {
StdLogger
GenLogger
}

0 comments on commit 1246581

Please sign in to comment.