Skip to content

Commit

Permalink
👔 up: replace interface{} to any, only support go 1.18+
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Jul 12, 2023
1 parent 185c68c commit a5ea78c
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 37 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ func (ma *MyApp) SetCacher(cacher gsr.SimpleCacher) {
```go
// DataParser interface for Marshal/Unmarshal data
type DataParser interface {
Marshal(v interface{}) ([]byte, error)
Unmarshal(data []byte, ptr interface{}) error
Marshal(v any) ([]byte, error)
Unmarshal(data []byte, ptr any) error
}
```

Expand Down
18 changes: 9 additions & 9 deletions cacher.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ type SimpleCacher interface {
// Has basic operation
Has(key string) bool
Del(key string) error
Get(key string) interface{}
Set(key string, val interface{}, ttl time.Duration) error
Get(key string) any
Set(key string, val any, ttl time.Duration) error

// GetMulti multi operation
GetMulti(keys []string) map[string]interface{}
SetMulti(values map[string]interface{}, ttl time.Duration) error
GetMulti(keys []string) map[string]any
SetMulti(values map[string]any, ttl time.Duration) error
DelMulti(keys []string) error
}

Expand All @@ -39,12 +39,12 @@ type ContextOpCacher interface {
// 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
GetWithCtx(ctx context.Context, key string) any
SetWithCtx(ctx context.Context, key string, val any, 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
MGetWithCtx(ctx context.Context, keys []string) map[string]any
MSetWithCtx(ctx context.Context, values map[string]any, ttl time.Duration) error
MDelWithCtx(ctx context.Context, keys []string) error
}

Expand All @@ -53,5 +53,5 @@ type CodedCacher interface {
SimpleCacher

// GetAs get and decode cache value to object ptr
GetAs(key string, ptr interface{}) error
GetAs(key string, ptr any) error
}
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.13
go 1.18
37 changes: 18 additions & 19 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,32 @@ package gsr

// Printer interface definition
type Printer interface {
Print(v ...interface{})
Printf(format string, v ...interface{})
Println(v ...interface{})
Print(v ...any)
Printf(format string, v ...any)
Println(v ...any)
}

// StdLogger interface definition.
// refer the go "log" package.
// StdLogger interface definition. refer the go "log" package.
type StdLogger interface {
Printer
Fatal(v ...interface{})
Fatalf(format string, v ...interface{})
Fatalln(v ...interface{})
Panic(v ...interface{})
Panicf(format string, v ...interface{})
Panicln(v ...interface{})
Fatal(v ...any)
Fatalf(format string, v ...any)
Fatalln(v ...any)
Panic(v ...any)
Panicf(format string, v ...any)
Panicln(v ...any)
}

// GenLogger generic logger interface definition
type GenLogger interface {
Debug(v ...interface{})
Debugf(format string, v ...interface{})
Info(v ...interface{})
Infof(format string, v ...interface{})
Warn(v ...interface{})
Warnf(format string, v ...interface{})
Error(v ...interface{})
Errorf(format string, v ...interface{})
Debug(v ...any)
Debugf(format string, v ...any)
Info(v ...any)
Infof(format string, v ...any)
Warn(v ...any)
Warnf(format string, v ...any)
Error(v ...any)
Errorf(format string, v ...any)
}

// Logger interface definition
Expand Down
12 changes: 6 additions & 6 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package gsr

// Marshaler interface
type Marshaler interface {
Marshal(v interface{}) ([]byte, error)
Marshal(v any) ([]byte, error)
}

// Unmarshaler interface
type Unmarshaler interface {
Unmarshal(v []byte, ptr interface{}) error
Unmarshal(v []byte, ptr any) error
}

// DataParser interface for Marshal/Unmarshal data
Expand All @@ -17,17 +17,17 @@ type DataParser interface {
}

// MarshalFunc define
type MarshalFunc func(v interface{}) ([]byte, error)
type MarshalFunc func(v any) ([]byte, error)

// Marshal implements the Marshaler
func (m MarshalFunc) Marshal(v interface{}) ([]byte, error) {
func (m MarshalFunc) Marshal(v any) ([]byte, error) {
return m(v)
}

// UnmarshalFunc define
type UnmarshalFunc func(v []byte, ptr interface{}) error
type UnmarshalFunc func(v []byte, ptr any) error

// Unmarshal implements the Unmarshaler
func (u UnmarshalFunc) Unmarshal(v []byte, ptr interface{}) error {
func (u UnmarshalFunc) Unmarshal(v []byte, ptr any) error {
return u(v, ptr)
}

0 comments on commit a5ea78c

Please sign in to comment.