Documentation
¶
Overview ¶
Package sub is used for subscribing to handle requests. It contains the options to use in Connector.Subscribe
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HTTPHandler ¶
type HTTPHandler func(w http.ResponseWriter, r *http.Request) error
HTTPHandler extends the standard http.Handler to also return an error.
type Option ¶
type Option func(sub *Subscription) error
Option is used to construct a subscription in Connector.Subscribe
func DefaultQueue ¶
func DefaultQueue() Option
DefaultQueue names the queue of this subscription to the hostname of the service. Requests will be load-balanced among all instances of this microservice.
func LoadBalanced ¶
func LoadBalanced() Option
LoadBalanced is synonymous with DefaultQueue. Requests will be load-balanced among all instances of this microservice
func NoQueue ¶
func NoQueue() Option
NoQueue sets no queue for this subscription. Requests will be not be load-balanced, all instances of this microservice will receive the request
type Subscription ¶
type Subscription struct { Host string Port string Method string Path string Queue string Handler any Subs []*nats.Subscription // contains filtered or unexported fields }
Subscription handles incoming requests. Although technically public, it is used internally and should not be constructed by microservices directly.
func NewSub ¶
func NewSub(method string, defaultHost string, path string, handler HTTPHandler, options ...Option) (*Subscription, error)
NewSub creates a new subscription for the indicated path. If the path does not include a hostname, the microservice's default hostname is used. If a port is not specified, 443 is used by default. Port 0 is used to designate any port. The subscription can be limited to one HTTP method such as "GET", "POST", etc. or "ANY" can be used to accept any method.
Examples of valid paths:
(empty) / /path :1080 :1080/ :1080/path :0/any/port /path/with/slash path/with/no/slash https://www.example.com/path https://www.example.com:1080/path //www.example.com:1080/path
func (*Subscription) Apply ¶
func (sub *Subscription) Apply(options ...Option) error
Apply the provided options to the subscription.
func (*Subscription) Canonical ¶
func (sub *Subscription) Canonical() string
Canonical returns the fully-qualified canonical host:port/path of the subscription, not including the scheme.
func (*Subscription) RefreshHostname ¶
func (sub *Subscription) RefreshHostname(defaultHost string) error
RefreshHostname refreshes the subscription for a different hostname.