Documentation ¶
Index ¶
- Constants
- func PublishError(pub Publisher, err error) error
- type AccessLogMiddlewareOption
- type AccessLogger
- type ChanSubscriber
- type Codec
- type Connection
- type Error
- type Handler
- type HandlerFunc
- type JsonCodec
- type Matcher
- type Middleware
- type ProtoCodec
- type ProtojsonCodec
- type PrototextCodec
- type Publisher
- type PublisherMsg
- type Request
- type RequesterMsg
- type ServeMux
- type Server
- type Subscriber
- type Subscription
- type TypedHandler
- type TypedHandlerFunc
- type TypedPublisher
- type TypedRequest
- type UIDGenerator
- type Unsubscriber
Constants ¶
View Source
const ( HeaderErrorCode = "error-code" HeaderErrorMessage = "error-message" )
View Source
const HeaderRequestUID = "Request-UID"
Variables ¶
This section is empty.
Functions ¶
func PublishError ¶
Types ¶
type AccessLogMiddlewareOption ¶
type AccessLogMiddlewareOption func(*loggingPublisher)
func AccessLogMiddlewareWithLogger ¶
func AccessLogMiddlewareWithLogger(log AccessLogger) AccessLogMiddlewareOption
func AccessLogMiddlewareWithWriter ¶
func AccessLogMiddlewareWithWriter(w io.Writer) AccessLogMiddlewareOption
type AccessLogger ¶
type AccessLogger interface {
Println(v ...any)
}
type ChanSubscriber ¶
type ChanSubscriber interface { ChanSubscribe(subj string, ch chan *nats.Msg) (Unsubscriber, error) ChanQueueSubscribe(subj, queue string, ch chan *nats.Msg) (Unsubscriber, error) }
type Connection ¶
type Connection interface { PublisherMsg RequesterMsg Subscriber ChanSubscriber Drain() error }
func NATS ¶
func NATS(nc *nats.Conn) Connection
type Handler ¶
func ChainMiddleware ¶
func ChainMiddleware(h Handler, mw ...Middleware) Handler
func ErrorHandlerMiddleware ¶
func RequestUIDMiddleware ¶
type HandlerFunc ¶
type Matcher ¶ added in v0.8.0
func NewMatcher ¶ added in v0.8.0
type Middleware ¶
func MakeAccessLogMiddleware ¶
func MakeAccessLogMiddleware(opts ...AccessLogMiddlewareOption) Middleware
MakeAccessLogMiddleware returns a middleware that logs the request and response of a handler.
WARNING: the logger is inefficient and should not be used in production. TODO: replace with efficient implementation.
func MakePublishSubjectMiddleware ¶
func MakePublishSubjectMiddleware(subject string) Middleware
type ProtoCodec ¶
type ProtoCodec struct{}
type ProtojsonCodec ¶
type ProtojsonCodec struct{}
type PrototextCodec ¶
type PrototextCodec struct{}
type Publisher ¶
type Publisher interface { PublisherMsg Subject() string WithSubject(subject string) Publisher Header() *nats.Header Publish(data []byte) error }
func NewPublisher ¶
func NewPublisher(p PublisherMsg) Publisher
func NewPublisherWithSubject ¶
func NewPublisherWithSubject(p PublisherMsg, subject string) Publisher
type PublisherMsg ¶
type PublisherMsg interface {
PublishMsg(msg *nats.Msg) error
}
type RequesterMsg ¶
type ServeMux ¶
type ServeMux struct {
// contains filtered or unexported fields
}
ServeMux is a handler multiplexer
func (*ServeMux) HandleFunc ¶
type Server ¶
type Subscriber ¶
type Subscriber interface { Subscribe(subj string) (Subscription, error) QueueSubscribe(subj, queue string) (Subscription, error) }
type Subscription ¶
type Subscription interface { Unsubscriber NextMsg(ctx context.Context) (*nats.Msg, error) }
type TypedHandler ¶
type TypedHandler[ArgT, ResT any] interface { Serve(TypedPublisher[ResT], TypedRequest[ArgT]) error }
type TypedHandlerFunc ¶
type TypedHandlerFunc[ArgT, ResT any] func(TypedPublisher[ResT], TypedRequest[ArgT]) error
func (TypedHandlerFunc[ArgT, ResT]) Serve ¶
func (f TypedHandlerFunc[ArgT, ResT]) Serve(pub TypedPublisher[ResT], req TypedRequest[ArgT]) error
type TypedPublisher ¶
type TypedPublisher[ResT any] interface { Header() *nats.Header Publish(*ResT) error Subject() string WithSubject(string) TypedPublisher[ResT] }
type TypedRequest ¶
type UIDGenerator ¶
type UIDGenerator interface {
Next() string
}
type Unsubscriber ¶
type Unsubscriber interface {
Unsubscribe() error
}
Source Files ¶
Click to show internal directories.
Click to hide internal directories.