diff --git a/freesia.go b/freesia.go index a719eef..b0513af 100644 --- a/freesia.go +++ b/freesia.go @@ -19,6 +19,7 @@ type Freesia struct { store Store cache *roc.Cache dispatcher *curlew.Dispatcher + channel string pubSub *redis.PubSub logger *logrus.Logger } @@ -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", @@ -61,6 +59,9 @@ func New(store Store, setters ...Setter) (*Freesia, error) { } } + f.pubSub = f.store.Subscribe(f.channel) + f.sub() + return f, nil } diff --git a/setter.go b/setter.go index e6c0b8f..7fd7357 100644 --- a/setter.go +++ b/setter.go @@ -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 + } +}