From 41935690ccc1a0851f8caa8e46026ab213c7a9b7 Mon Sep 17 00:00:00 2001 From: zenghur Date: Tue, 7 Apr 2020 19:49:42 +0800 Subject: [PATCH] chore:golint --- entry/entry.go | 2 +- entry/load_source.go | 2 +- error.go | 2 ++ freesia.go | 13 +++++++++---- setter.go | 1 + store.go | 1 + 6 files changed, 15 insertions(+), 6 deletions(-) diff --git a/entry/entry.go b/entry/entry.go index 54c0e35..023050e 100644 --- a/entry/entry.go +++ b/entry/entry.go @@ -15,7 +15,7 @@ type Entry struct { localExp time.Duration data []byte ttl float64 - loadFrom int + loadFrom int codec codec.Codec enableLocalCache bool } diff --git a/entry/load_source.go b/entry/load_source.go index b4f96db..699c8eb 100644 --- a/entry/load_source.go +++ b/entry/load_source.go @@ -1,7 +1,7 @@ package entry const ( - _ int = iota + _ int = iota SourceLocal SourceCenter ) diff --git a/error.go b/error.go index e0b6b27..388e4e8 100644 --- a/error.go +++ b/error.go @@ -1,7 +1,9 @@ package freesia +// Error 错误类型 type Error string +// Error 错误接口 func (e Error) Error() string { return string(e) } diff --git a/freesia.go b/freesia.go index d29574c..ced9a02 100644 --- a/freesia.go +++ b/freesia.go @@ -2,18 +2,17 @@ package freesia import ( "context" - "os" - - "github.com/xiaojiaoyu100/lizard/mass" - "github.com/go-redis/redis" "github.com/sirupsen/logrus" "github.com/vmihailenco/msgpack" "github.com/xiaojiaoyu100/curlew" "github.com/xiaojiaoyu100/freesia/entry" + "github.com/xiaojiaoyu100/lizard/mass" "github.com/xiaojiaoyu100/roc" + "os" ) +// Freesia 多级缓存 type Freesia struct { store Store cache *roc.Cache @@ -22,6 +21,7 @@ type Freesia struct { logger *logrus.Logger } +// New 生成一个实例 func New(store Store, setters ...Setter) (*Freesia, error) { var err error @@ -61,6 +61,7 @@ func New(store Store, setters ...Setter) (*Freesia, error) { return f, nil } +// Set sets a key-value. func (f *Freesia) Set(e *entry.Entry) error { if err := e.Encode(); err != nil { return err @@ -76,6 +77,7 @@ func (f *Freesia) Set(e *entry.Entry) error { return nil } +// MSet batch sets entries. func (f *Freesia) MSet(es ...*entry.Entry) error { pipe := f.store.Pipeline() for _, e := range es { @@ -130,6 +132,7 @@ func (f *Freesia) Get(e *entry.Entry) error { } } +// GetWithTTL gets value with ttl. func (f *Freesia) GetWithTTL(e *entry.Entry) error { if e.EnableLocalExp() { data, err := f.cache.Get(e.Key()) @@ -236,6 +239,7 @@ func (f *Freesia) batchGet(es ...*entry.Entry) ([]*entry.Entry, error) { return missEntries, nil } +// MGet batch get entries. func (f *Freesia) MGet(es ...*entry.Entry) ([]*entry.Entry, error) { batch := mass.New(len(es), 3000) missEntries := make([]*entry.Entry, 0, len(es)) @@ -250,6 +254,7 @@ func (f *Freesia) MGet(es ...*entry.Entry) ([]*entry.Entry, error) { return missEntries, nil } +// Del deletes keys. func (f *Freesia) Del(keys ...string) error { if len(keys) == 0 { return nil diff --git a/setter.go b/setter.go index babea4c..e6c0b8f 100644 --- a/setter.go +++ b/setter.go @@ -1,3 +1,4 @@ package freesia +// Setter 配置函数 type Setter func(f *Freesia) error diff --git a/store.go b/store.go index c31e37e..dea8f5b 100644 --- a/store.go +++ b/store.go @@ -6,6 +6,7 @@ import ( "github.com/go-redis/redis" ) +// Store represents redis op. type Store interface { Set(key string, value interface{}, expiration time.Duration) *redis.StatusCmd MSet(pairs ...interface{}) *redis.StatusCmd