xhertz

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2024 License: MIT Imports: 5 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// ClientClosed is non-standard http status code,
	// which defined by nginx.
	// https://httpstatus.in/499/
	HTTPStatusClientClosed = 499
)

Variables

This section is empty.

Functions

func FromGRPCCode

func FromGRPCCode(code codes.Code) int

func HandleBadRequest

func HandleBadRequest(ctx *app.RequestContext, err error)

func HandleError

func HandleError(ctx *app.RequestContext, err error)

func Render added in v0.3.1

func Render(ctx *app.RequestContext, status int, data any)

Types

type Error

type Error struct {
	HTTPCode   int        `json:"code"`    // The HTTP status code that corresponds to `google.rpc.Status.code`.
	Message    string     `json:"message"` // This corresponds to `google.rpc.Status.message`.
	GRPCStatus codes.Code `json:"status"`  // This is the enum version for `google.rpc.Status.code`.
	Reason     string     `json:"reason"`
	Details    []any      `json:"details"` // This corresponds to `google.rpc.Status.details`.
}

func NewError

func NewError(code codes.Code, message string, opts ...ErrorOption) *Error

func (*Error) Error

func (e *Error) Error() string

type ErrorOption

type ErrorOption func(*Error)

func WithDetails

func WithDetails(details ...any) ErrorOption

func WithMessage

func WithMessage(message string) ErrorOption

type ErrorResponse

type ErrorResponse struct {
	// The actual error payload. The nested message structure is for backward
	// compatibility with [Google API Client
	// Libraries](https://developers.google.com/api-client-library). It also
	// makes the error more readable to developers.
	Status Error `json:"error"`
}

This message defines the error schema for Google's JSON HTTP APIs.

Jump to

Keyboard shortcuts

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