sub

package
v1.22.2 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2026 License: Apache-2.0 Imports: 10 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 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 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 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

func RequiredClaims added in v1.22.0

func RequiredClaims(boolExp string) Option

RequiredClaims 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.

type Subscription

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

	RequiredClaims 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, route string, handler HTTPHandler, options ...Option) (*Subscription, error)

NewSub creates a new subscription. If the route does not include a hostname, it is resolved relative to the microservice's default hostname. If a port is not specified, 443 is used by default. Port 0 is used to designate any port. The subscription can be set to a single standard HTTP method such as "GET", "POST", etc. or to "ANY" in order to accept any method. Path arguments are designated by curly braces.

Examples of valid paths:

(empty)
/
/path
:1080
:1080/
:1080/path
:0/any/port
/path/with/slash
path/with/no/slash
/section/{section}/page/{page...}
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