fxrf

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2024 License: Apache-2.0 Imports: 11 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

Functions

This section is empty.

Types

type Config

type Config struct {
	WriteLogs bool
}

type ErrorResp

type ErrorResp struct {
	Status   Status    `json:"status"`
	Message  string    `json:"message"`
	Metadata *Metadata `json:"metadata"`
}

type Factory

type Factory interface {
	NewWriter(rw http.ResponseWriter) Writer
}

func NewFactory

func NewFactory(l *zap.Logger, cfg *Config, version fxecumenos.Version) Factory

type FailureResp

type FailureResp[T interface{}] struct {
	Status   Status    `json:"status"`
	Data     T         `json:"data"`
	Message  string    `json:"message"`
	Metadata *Metadata `json:"metadata"`
}

type Metadata added in v0.0.5

type Metadata struct {
	RequestID string `json:"requestId"`
	Duration  int    `json:"duration"`
	Timestamp string `json:"timestamp"`
	Version   string `json:"version"`
}

type ResponseBuildOption

type ResponseBuildOption func(b *responseBuilder)

func WithCause

func WithCause(err error) ResponseBuildOption

func WithData

func WithData(data interface{}) ResponseBuildOption

func WithHTTPStatusCode

func WithHTTPStatusCode(code int) ResponseBuildOption

func WithLogger

func WithLogger(l *zap.Logger) ResponseBuildOption

func WithMessage

func WithMessage(msg string) ResponseBuildOption

type Status

type Status string
const (
	SuccessStatus Status = "success"
	FailureStatus Status = "failure"
	ErrorStatus   Status = "error"
)

type SuccessResp

type SuccessResp[T interface{}] struct {
	Status   Status    `json:"status"`
	Data     T         `json:"data"`
	Metadata *Metadata `json:"metadata"`
}

type Writer

type Writer interface {
	SetLogger(logger *zap.Logger)
	WriteSuccess(ctx context.Context, payload interface{}, opts ...ResponseBuildOption) error
	WriteFail(ctx context.Context, data interface{}, opts ...ResponseBuildOption) error
	WriteError(ctx context.Context, msg string, cause error, opts ...ResponseBuildOption) error
}

func NewWriter

func NewWriter(l *zap.Logger, rw http.ResponseWriter, appVersion fxecumenos.Version, writeLogs bool) Writer

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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