domain

package
v0.0.0-...-5abe684 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidChannel : Given channel is not permitted in configuration
	ErrInvalidChannel = NewErrorWithCode("dsps.storage.invalid-channel")
	// ErrSubscriptionNotFound : Subscriber expired (due to infrequent access less than expire setting) or not created
	ErrSubscriptionNotFound = NewErrorWithCode("dsps.storage.subscription-not-found")
	// ErrMalformedAckHandle : Failed to decode/decrypt given AckHandle
	ErrMalformedAckHandle = NewErrorWithCode("dsps.storage.ack-handle-malformed")
	// ErrMalformedMessageJSON : Given message content is not valid JSON
	ErrMalformedMessageJSON = NewErrorWithCode("dsps.storage.message-json-malformed")
)
View Source
var PrivateCIDRs []CIDR

PrivateCIDRs is a list of private networks, link local, and loopback addresses.

Functions

func BelongsToSameChannel

func BelongsToSameChannel(msgs []Message) bool

BelongsToSameChannel returns false if messages belongs to various channels

func IsStorageNonFatalError

func IsStorageNonFatalError(err error) bool

IsStorageNonFatalError returns true if given error does not indicate storage system error

Types

type AckHandle

type AckHandle struct {
	SubscriberLocator
	Handle string
}

AckHandle is an token to remove received (acknowledged) messages from a subscriber.

type CIDR

type CIDR struct {
	// contains filtered or unexported fields
}

CIDR is IPNet wrapper struct

func ParseCIDR

func ParseCIDR(str string) (CIDR, error)

ParseCIDR parse given CIDR notation string

func (CIDR) Contains

func (cidr CIDR) Contains(ip string) bool

Contains returns true if given IP is valid and contained in this.

func (CIDR) IPNet

func (cidr CIDR) IPNet() *net.IPNet

IPNet returns net.IPNet of this range.

func (CIDR) MarshalJSON

func (cidr CIDR) MarshalJSON() ([]byte, error)

MarshalJSON method for configuration marshal/unmarshal

func (CIDR) String

func (cidr CIDR) String() string

func (*CIDR) UnmarshalJSON

func (cidr *CIDR) UnmarshalJSON(b []byte) error

UnmarshalJSON method for configuration marshal/unmarshal

type Channel

type Channel interface {
	Expire() Duration

	// Note that this method does not check revocation list.
	ValidateJwt(ctx context.Context, jwt string) error

	SendOutgoingWebhook(ctx context.Context, msg Message) error
}

Channel struct holds all objects/information of a channel

type ChannelID

type ChannelID string

ChannelID is ID of the PubSub channel, system-wide unique value

func ParseChannelID

func ParseChannelID(str string) (ChannelID, error)

ParseChannelID try to parse ID

type ChannelProvider

type ChannelProvider interface {
	Get(id ChannelID) (Channel, error)

	GetFileDescriptorPressure() int
	JWTClockSkewLeewayMax() Duration

	Shutdown(ctx context.Context)
}

ChannelProvider provides configured Channel object. If given ChannelID is not valid for this server process, returns (nil, domain.ErrInvalidChannel).

type Duration

type Duration struct {
	time.Duration
}

Duration wrapper struct

func (Duration) MarshalJSON

func (d Duration) MarshalJSON() ([]byte, error)

MarshalJSON method for configuration marshal/unmarshal

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(b []byte) error

UnmarshalJSON method for configuration marshal/unmarshal

type ErrorWithCode

type ErrorWithCode interface {
	Error() string
	Code() string
	Unwrap() error
}

ErrorWithCode is an error interface with error code

func NewErrorWithCode

func NewErrorWithCode(code string) ErrorWithCode

NewErrorWithCode is to make stateless ErrorWithCode instance.

func WrapErrorWithCode

func WrapErrorWithCode(code string, err error) ErrorWithCode

WrapErrorWithCode is to wrap error object with code

type JwtAlg

type JwtAlg string

JwtAlg is "alg" claim, signing algorithm of a JWT

func (JwtAlg) IsNone

func (alg JwtAlg) IsNone() bool

IsNone returns true only for "none" alg.

type JwtAud

type JwtAud string

JwtAud is "aud" claim, recipient of a JWT

type JwtExp

type JwtExp time.Time // Intentionally use time.Time rather than domain.Time to prevent using JSON marshaler of domain.Time

JwtExp is "exp" claim, number of seconds from 1970-01-01T00:00:00Z UTC without leap seconds.

func ParseJwtExp

func ParseJwtExp(str string) (JwtExp, error)

ParseJwtExp parses claim value

func (JwtExp) Int64

func (exp JwtExp) Int64() int64

Int64 returns integer as same as "jwt" claim spec.

func (JwtExp) String

func (exp JwtExp) String() string

String method to implement Stringer

func (JwtExp) Time

func (exp JwtExp) Time() time.Time

Time returns time.Time instance equivalent to this

type JwtIss

type JwtIss string

JwtIss is "iss" claim, issuer of a JWT

type JwtJti

type JwtJti string

JwtJti is "jti" claim, ID of a JWT

type JwtStorage

type JwtStorage interface {
	RevokeJwt(ctx context.Context, exp JwtExp, jti JwtJti) error
	IsRevokedJwt(ctx context.Context, jti JwtJti) (bool, error)
}

JwtStorage interface is an abstraction layer of JWT storage implementations

type Message

type Message struct {
	MessageLocator
	Content json.RawMessage
}

Message is an atomic datagram of the PubSub communication

type MessageID

type MessageID string

MessageID is ID of the message, unique within channel

func ParseMessageID

func ParseMessageID(str string) (MessageID, error)

ParseMessageID try to parse ID

type MessageLocator

type MessageLocator struct {
	ChannelID ChannelID
	MessageID MessageID
}

MessageLocator is unique identifier of the Message, unique within channel

type PubSubStorage

type PubSubStorage interface {
	NewSubscriber(ctx context.Context, sl SubscriberLocator) error
	RemoveSubscriber(ctx context.Context, sl SubscriberLocator) error

	// All messages must belong to same channel.
	PublishMessages(ctx context.Context, msgs []Message) error
	// Storage implementation can return more messages than given max count.
	// When length of the returned messages is zero, returned AckHandle is not valid thus caller should ignore it.
	FetchMessages(ctx context.Context, sl SubscriberLocator, max int, waituntil Duration) (messages []Message, moreMessages bool, ackHandle AckHandle, err error)
	AcknowledgeMessages(ctx context.Context, handle AckHandle) error
	// If the message had been acknowledged or sent before subscriber creation, returns true. Otherwise false (can includes unsure messages).
	IsOldMessages(ctx context.Context, sl SubscriberLocator, msgs []MessageLocator) (map[MessageLocator]bool, error)
}

PubSubStorage interface is an abstraction layer of PubSub storage implementations

type Regex

type Regex struct {
	// contains filtered or unexported fields
}

Regex wrapper struct

func NewRegex

func NewRegex(regex string) (*Regex, error)

NewRegex compiles regex

func (*Regex) GroupNames

func (regex *Regex) GroupNames() []string

GroupNames returns list of group (subregex) names

func (Regex) MarshalJSON

func (regex Regex) MarshalJSON() ([]byte, error)

MarshalJSON method for configuration marshal/unmarshal

func (*Regex) Match

func (regex *Regex) Match(entire bool, str string) map[string]string

Match against given string and returns map of named groups. If not match returns nil.

func (*Regex) String

func (regex *Regex) String() string

String represents original regex

func (*Regex) UnmarshalJSON

func (regex *Regex) UnmarshalJSON(b []byte) error

UnmarshalJSON method for configuration marshal/unmarshal

type Storage

type Storage interface {
	String() string // Stringer
	Shutdown(ctx context.Context) error

	// Liveness probe, returns "encoding/json" encodable value.
	Liveness(ctx context.Context) (interface{}, error)
	// Readiness probe, returns "encoding/json" encodable value.
	Readiness(ctx context.Context) (interface{}, error)

	// Retruns nil if neither supported nor supported.
	AsPubSubStorage() PubSubStorage
	// Retruns nil if neither supported nor supported.
	AsJwtStorage() JwtStorage

	// Estimated maximum pressure of syscall.RLIMIT_NOFILE
	GetFileDescriptorPressure() int
}

Storage interface is an abstraction layer of storage implementations

type StorageID

type StorageID string

StorageID is unique & persistent ID of the Storage

type SubscriberID

type SubscriberID string

SubscriberID is ID of the subscriber, unique within channel

func ParseSubscriberID

func ParseSubscriberID(str string) (SubscriberID, error)

ParseSubscriberID try to parse ID

type SubscriberLocator

type SubscriberLocator struct {
	ChannelID    ChannelID
	SubscriberID SubscriberID
}

SubscriberLocator is unique identifier of the PubSub subscriber, unique within channel

type SystemClock

type SystemClock interface {
	Now() Time
}

SystemClock is an interface to get current time Do not use time.Now() directly to make codes testable.

var RealSystemClock SystemClock = &realSystemClock

RealSystemClock is just a time.Now()

type TemplateString

type TemplateString struct {
	// contains filtered or unexported fields
}

TemplateString is Template wrappwer struct

func NewTemplateString

func NewTemplateString(value string) (TemplateString, error)

NewTemplateString initialize template

func (TemplateString) Execute

func (tpl TemplateString) Execute(data TemplateStringEnv) (string, error)

Execute evaluates template

func (TemplateString) MarshalJSON

func (tpl TemplateString) MarshalJSON() ([]byte, error)

MarshalJSON method for configuration marshal/unmarshal

func (TemplateString) String

func (tpl TemplateString) String() string

String returns original template string

func (*TemplateString) UnmarshalJSON

func (tpl *TemplateString) UnmarshalJSON(b []byte) error

UnmarshalJSON method for configuration marshal/unmarshal

type TemplateStringEnv

type TemplateStringEnv interface{}

TemplateStringEnv is an parameters for template evaluation

type TemplateStrings

type TemplateStrings struct {
	Templates []TemplateString
}

TemplateStrings is list of TemplateString

func NewTemplateStrings

func NewTemplateStrings(templates ...TemplateString) TemplateStrings

NewTemplateStrings initialize templates

func (TemplateStrings) Execute

func (ts TemplateStrings) Execute(data TemplateStringEnv) ([]string, error)

Execute evaluates templates

func (TemplateStrings) MarshalJSON

func (ts TemplateStrings) MarshalJSON() ([]byte, error)

MarshalJSON method for configuration marshal/unmarshal

func (TemplateStrings) String

func (ts TemplateStrings) String() string

String returns original template strings

func (*TemplateStrings) UnmarshalJSON

func (ts *TemplateStrings) UnmarshalJSON(b []byte) error

UnmarshalJSON method for configuration marshal/unmarshal

type Time

type Time struct {
	time.Time
}

Time wrapper struct

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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