github.com/xmlking/toolkit/broker/pubsub@v0.3.4/subscribe_options.go (about)

     1  package broker
     2  
     3  import (
     4  	"context"
     5  
     6  	"cloud.google.com/go/pubsub"
     7  )
     8  
     9  // RecoveryHandler is a function that is called when the recovery middleware recovers from a panic.
    10  // The func takes the receive context, message and the return value from recover
    11  // which reports whether the goroutine is panicking.
    12  // Example usages of HandlerFunc could be to log panics or nack/ack messages which cause panics.
    13  type RecoveryHandler func(context.Context, *pubsub.Message, interface{})
    14  
    15  type SubscribeOption func(*SubscribeOptions)
    16  
    17  // SubscribeOptions TODO support more pubsub.ReceiveSettings settings
    18  type SubscribeOptions struct {
    19  	// pubsub ReceiveSettings
    20  	ReceiveSettings pubsub.ReceiveSettings
    21  
    22  	RecoveryHandler RecoveryHandler
    23  }
    24  
    25  // WithRecoveryHandler sets the function for recovering from a panic.
    26  func WithRecoveryHandler(r RecoveryHandler) SubscribeOption {
    27  	return func(o *SubscribeOptions) {
    28  		o.RecoveryHandler = r
    29  	}
    30  }
    31  
    32  func WithReceiveSettings(receiveSettings pubsub.ReceiveSettings) SubscribeOption {
    33  	return func(o *SubscribeOptions) {
    34  		o.ReceiveSettings = receiveSettings
    35  	}
    36  }