Skip to content

Commit

Permalink
chore: bump
Browse files Browse the repository at this point in the history
  • Loading branch information
zenghur committed Aug 11, 2020
1 parent 0dff6d4 commit 4248dd7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
11 changes: 6 additions & 5 deletions freesia.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Freesia struct {
store Store
cache *roc.Cache
dispatcher *curlew.Dispatcher
channel string
pubSub *redis.PubSub
logger *logrus.Logger
}
Expand All @@ -41,13 +42,10 @@ func New(store Store, setters ...Setter) (*Freesia, error) {
if err != nil {
return nil, err
}

f.pubSub = f.store.Subscribe(channel)

f.sub()
f.channel = channel

logger := logrus.New()
logger.SetLevel(logrus.InfoLevel)
logger.SetLevel(logrus.WarnLevel)
logger.SetOutput(os.Stdout)
logger.SetFormatter(&logrus.JSONFormatter{
TimestampFormat: "2006-01-02 15:04:05",
Expand All @@ -61,6 +59,9 @@ func New(store Store, setters ...Setter) (*Freesia, error) {
}
}

f.pubSub = f.store.Subscribe(f.channel)
f.sub()

return f, nil
}

Expand Down
18 changes: 18 additions & 0 deletions setter.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
package freesia

import "github.com/sirupsen/logrus"

// Setter 配置函数
type Setter func(f *Freesia) error

// WithChannel sets the pub sub channel.
func WithChannel(channel string) Setter {
return func(f *Freesia) error {
f.channel = channel
return nil
}
}

// WithDebug sets the debug mode.
func WithDebug() Setter {
return func(f *Freesia) error {
f.logger.SetLevel(logrus.DebugLevel)
return nil
}
}

0 comments on commit 4248dd7

Please sign in to comment.