core

package
v0.0.0-...-df0240d Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorPrefix    = "ERR\x01" // ErrorPrefix ERR(Start of Heading) Denotes an API error.
	ErrorSeparator = "\x02"    // ErrorSeparator (Start of Text) Denotes the start of the API error message.
)

Variables

View Source
var DefaultHandler = make([]Handler, 0)

Functions

func ApiError

func ApiError(code codes.Code, msg any) []byte

func Call

func Call[T proto.Message, U proto.Message](ctx context.Context, con *nats.Conn, middleware []Handler, errorHandler ErrorHandler, subject string, command T, ret U) error

Call provides the functionality to call NATS req/rep APIs

func CallServerAPI

func CallServerAPI[T proto.Message, U proto.Message](ctx context.Context, panicRecovery bool, errorHandler ErrorHandler, container T, msg *nats.Msg, fn func(ctx context.Context, req T) (U, error)) error

func ErrorResponse

func ErrorResponse(m *nats.Msg, code codes.Code, msg any)

func Listen

func Listen[T proto.Message, U proto.Message](con *nats.Conn, panicRecovery bool, subList *sync.Map, middleware []Handler, errorHandler ErrorHandler, subject string, req T, fn func(ctx context.Context, req T) (U, error)) error

func RecoverAPIpanic

func RecoverAPIpanic(msg *nats.Msg)

Types

type ErrorHandler

type ErrorHandler func(err error, msg *nats.Msg) error
var DefaultErrorHandler ErrorHandler = func(err error, msg *nats.Msg) error {
	c := codes.Unknown
	ErrorResponse(msg, c, err.Error())
	return fmt.Errorf("API call: %w", err)
}

type Handler

type Handler func(ctx context.Context, msg *nats.Msg) (context.Context, error)

Jump to

Keyboard shortcuts

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