sub

package
v1.19.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

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) (err 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 Actor added in v1.13.1

func Actor(boolExp string) Option

Actor requires that the properties of the actor associated with the request satisfy the boolean expression. For example: iss=='my_issuer' && (roles=~'admin' || roles=~'manager') && region=="US". The =~ and !~ operators evaluate the left operand against a regexp. String constants, including regexp patterns, must be quoted using single quotes, double quotes or backticks. A request that doesn't satisfy the constraint is denied with a 403 forbidden error.

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

func Pervasive

func Pervasive() Option

Pervasive is synonymous with NoQueue. Requests will be not be load-balanced, all instances of this microservice will receive the request

func Queue

func Queue(queue string) Option

Queue names the queue of the subscription. Requests will be load-balanced among all consumers with the same queue name

type Subscription

type Subscription struct {
	Host    string
	Port    string
	Method  string
	Path    string
	Queue   string
	Handler any
	Subs    []*transport.Subscription

	Actor string
	// 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 or the method.

func (*Subscription) RefreshHostname

func (sub *Subscription) RefreshHostname(defaultHost string) error

RefreshHostname refreshes the subscription for a different hostname.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL