httpx

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var KeyHandler key = "custom_handler"

KeyHandler custom handler

Functions

func ErrorHandler

func ErrorHandler(err error, c echo.Context)

ErrorHandler override echo.HTTPErrorHandler

func NewHandler

func NewHandler(ctxFunc ContextFunc) echo.HandlerFunc

NewHandler generate a base handler

Types

type ConfFunc

type ConfFunc func(*Config) error

ConfFunc implements http functions

type Config

type Config struct {
	*echo.Echo
	// contains filtered or unexported fields
}

Config struct

func New

func New() *Config

New HTTP server

func Setup

func Setup() *Config

Setup gets the global httpx instance.

func (*Config) HealthCheck

func (h *Config) HealthCheck(enabled bool)

HealthCheck will enable the health_check URL

func (*Config) Serve

func (h *Config) Serve() error

Serve the HTTP server

func (*Config) Set

func (h *Config) Set(conf ...ConfFunc) error

Set HTTP implementation

func (*Config) SetPort

func (h *Config) SetPort(port string)

SetPort config

func (*Config) Stop

func (h *Config) Stop() error

Stop the HTTP server

type Context

type Context struct {
	echo.Context
}

Context struct

func (*Context) GetContext

func (c *Context) GetContext() context.Context

GetContext return request context

func (*Context) JSONErr

func (c *Context) JSONErr(err *HTTPError) error

JSONErr return JSONErr response

func (*Context) JSONR

func (c *Context) JSONR(statusCode int, data interface{}) error

JSONR return JSON response

func (*Context) Trace

func (c *Context) Trace() string

type ContextFunc

type ContextFunc func(*Context) error

ContextFunc typefunc

type HTTPError

type HTTPError struct {
	RequestID string `json:"request_id"`
	// StatusCode is http status code
	StatusCode int `json:"status_code"`
	// Code is the error code
	Code string `json:"code"`
	// Message is the error message that may be displayed to end users
	Message string `json:"error_message"`
	// DeveloperMessage is the error message that is mainly meant for developers
	DeveloperMessage string `json:"developer_message,omitempty"`
	DeveloperTrace   string `json:"developer_trace,omitempty"`
	// Details specifies the additional error information
	Details interface{} `json:"details"`
}

HTTPError struct

func ErrInternalServerError

func ErrInternalServerError(err error) *HTTPError

InternalServerError creates a new API error representing an internal server error (HTTP 500)

func ErrNotFound

func ErrNotFound() *HTTPError

NotFound creates a new API error representing a resource-not-found error (HTTP 404)

func ErrUnauthorized

func ErrUnauthorized(err error) *HTTPError

Unauthorized creates a new API error representing an authentication failure (HTTP 401)

func ErrValidation

func ErrValidation(errs validation.Errors) *HTTPError

ErrValidation converts a data validation error into an API error (HTTP 400)

func (HTTPError) Error

func (e HTTPError) Error() string

Error returns the error message.

type JSONResponse

type JSONResponse struct {
	RequestID string      `json:"request_id"`
	Code      int         `json:"status_code"`
	Result    interface{} `json:"data"`
}

JSONResponse struct

type Params

type Params map[string]interface{}

HTTPError struct

Jump to

Keyboard shortcuts

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