github.com/zooyer/miskit@v1.0.71/smq/smq.go (about) 1 package smq 2 3 import ( 4 "time" 5 ) 6 7 type Options struct { 8 Ack bool 9 TTL time.Duration 10 } 11 12 type Option func(ops *Options) 13 14 type Subscriber func(client Client, topic string, message []byte, options Options) (err error) 15 16 type Client interface { 17 Connect() error 18 Pub(topic string, message []byte, option ...Option) error 19 Sub(topic string, subscriber Subscriber) error 20 Close() error 21 } 22 23 func TTL(ttl time.Duration) Option { 24 return func(ops *Options) { 25 ops.TTL = ttl 26 } 27 } 28 29 func Ack(ack bool) Option { 30 return func(ops *Options) { 31 ops.Ack = ack 32 } 33 } 34 35 func options(option ...Option) Options { 36 var options Options 37 for _, opt := range option { 38 opt(&options) 39 } 40 return options 41 }