nats

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2025 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorHandler

func ErrorHandler(name string, a AppContext, handler AppHandler) micro.Handler

ErrorHandler wraps a normal micro endpoint and allows for returning errors natively. Errors are checked and if an error is a client error, details are returned, otherwise a 500 is returned and logged

func GetQueryHeaders

func GetQueryHeaders(headers micro.Headers, key string) []string

func HandleNotify

func HandleNotify(s micro.Service, healthFuncs ...func(chan<- string, micro.Service)) error

func MsgID

func MsgID(r micro.Request) (string, error)

func NewMsgWithID

func NewMsgWithID() *nats.Msg

func RequestLogger

func RequestLogger(l *slog.Logger, r micro.Request) (*slog.Logger, error)

func RequestToMsg

func RequestToMsg(r micro.Request) *nats.Msg

Types

type AppContext

type AppContext struct {
	Conn       *nats.Conn
	Logger     *slog.Logger
	Tracer     trace.Tracer
	Propagator propagation.TextMapPropagator
}

func (AppContext) InjectTraceHeaders added in v1.1.0

func (a AppContext) InjectTraceHeaders(ctx context.Context, headers map[string][]string)

type AppHandler

type AppHandler func(ctx context.Context, r micro.Request, h HandlerContext) error

type ClientError

type ClientError interface {
	Error() string
	Code() int
	Body() []byte
	LoggedError() []error
}

type ClientOpt

type ClientOpt func(*NATSClient)

func SetGraphQLExecutableSchema

func SetGraphQLExecutableSchema(e graphql.ExecutableSchema) ClientOpt

func SetOptions

func SetOptions(opts ...nats.Option) ClientOpt

func SetServers

func SetServers(s string) ClientOpt

func SetSubject

func SetSubject(s string) ClientOpt

type HandlerContext

type HandlerContext struct {
	Logger     *slog.Logger
	Conn       *nats.Conn
	Tracer     trace.Tracer
	Propagator propagation.TextMapPropagator
}

type HandlerWithErrors

type HandlerWithErrors func(*slog.Logger, micro.Request) error

type NATSClient

type NATSClient struct {
	Subject string
	Servers string
	Options []nats.Option
	Conn    *nats.Conn
	JS      nats.JetStreamContext
	NATSGraph
}

func NewNATSClient

func NewNATSClient(subject string, servers []string, opts ...ClientOpt) *NATSClient

func (*NATSClient) Connect

func (n *NATSClient) Connect() error

func (*NATSClient) HandleAndLogRequests

func (n *NATSClient) HandleAndLogRequests(m *nats.Msg)

func (*NATSClient) Resolve

func (n *NATSClient) Resolve(errChan chan<- error)

type NATSGraph

type NATSGraph struct {
	ExecutableSchema graphql.ExecutableSchema
	Exec             *executor.Executor
}

type NatsLogger

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

func NewNatsLogger

func NewNatsLogger(subject string, nc *nats.Conn) NatsLogger

func (NatsLogger) Write

func (n NatsLogger) Write(p []byte) (int, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳