httpx

package
v0.1.18 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2022 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

  • @Author: Daniel TAN
  • @Description:
  • @Date: 2021-08-06 09:15:58
  • @LastEditTime: 2021-09-07 10:46:38
  • @LastEditors: Please set LastEditors
  • @FilePath: /fr-price-common-pkg/core/httpx/parse.go

Author: Daniel TAN Date: 2021-09-05 10:24:33 LastEditors: Daniel TAN LastEditTime: 2021-10-03 14:56:13 FilePath: /trinity-micro/core/httpx/response.go Description:

Index

Constants

View Source
const (
	ContentDispositionHeader = "Content-Disposition"
	ContentLengthHeader      = "Content-Length"
	ContentTypeHeader        = "Content-Type"
	AcceptRangesHeader       = "Accept-Ranges"
	ContentRangeHeader       = "Content-Range"
	LastModifiedHeader       = "Last-Modified"
	DispositionFormat        = "attachment; filename=%s"
)
View Source
const (
	DefaultHttpErrorCode   int = 400
	DefaultHttpSuccessCode int = 200
)

Variables

This section is empty.

Functions

func DIParamHandler

func DIParamHandler(handler interface{}) func(w http.ResponseWriter, r *http.Request)

func GetHTTPStatusCode

func GetHTTPStatusCode(ctx context.Context, defaultStatus int) int

func GetRawRequest

func GetRawRequest(ctx context.Context) *http.Request

func HandlerNumsIn

func HandlerNumsIn(handlerType reflect.Type) int

func HttpResponse

func HttpResponse(ctx context.Context, w http.ResponseWriter, status int, res interface{})

func HttpResponseErr

func HttpResponseErr(ctx context.Context, w http.ResponseWriter, err error)

func InvokeHandler

func InvokeHandler(handlerType reflect.Type, r *http.Request) ([]reflect.Value, error)

func InvokeMethod

func InvokeMethod(handlerType reflect.Type, r *http.Request, instance interface{}, w http.ResponseWriter) ([]reflect.Value, error)

func IsHandler

func IsHandler(handlerType reflect.Type) bool

func JsonResponse

func JsonResponse(w http.ResponseWriter, status int, res interface{})

func NewWriter

func NewWriter() http.ResponseWriter

func Parse

func Parse(r *http.Request, v interface{}) error

func SetHeaderParser added in v0.1.12

func SetHeaderParser(h HeaderParser)

func SetHttpStatusCode

func SetHttpStatusCode(ctx context.Context, status int)

func SetQueryParser added in v0.1.12

func SetQueryParser(h QueryParser)

func XMLResponse

func XMLResponse(w http.ResponseWriter, status int, res interface{})

Types

type Context added in v0.1.12

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

func NewContext added in v0.1.12

func NewContext(r *http.Request, code int) *Context

type DefaultHeaderParser added in v0.1.12

type DefaultHeaderParser struct {
}

func (*DefaultHeaderParser) Exist added in v0.1.12

func (p *DefaultHeaderParser) Exist(h http.Header, k string) bool

func (*DefaultHeaderParser) Get added in v0.1.12

type DefaultQueryParser added in v0.1.12

type DefaultQueryParser struct {
}

func (*DefaultQueryParser) Exist added in v0.1.12

func (p *DefaultQueryParser) Exist(h url.Values, k string) bool

func (*DefaultQueryParser) Get added in v0.1.12

func (p *DefaultQueryParser) Get(h url.Values, k string) string

type ErrorInfo added in v0.1.14

type ErrorInfo struct {
	Code    int      `json:"code" example:"400001"`
	Message string   `json:"message" example:"ErrInvalidRequest"`
	Details []string `json:"details" example:"error detail1,error detail2"`
}

type ErrorResponse added in v0.1.14

type ErrorResponse struct {
	Status  int        `json:"status" example:"400"`
	Error   *ErrorInfo `json:"error,omitempty"`
	TraceID string     `json:"trace_id" example:"1-trace-it"`
}

type HTTPContextKey

type HTTPContextKey string
const (
	HttpxContext HTTPContextKey = "HTTPX_CONTEXT_KEY"
)

type HeaderParser added in v0.1.12

type HeaderParser interface {
	Exist(h http.Header, k string) bool
	Get(h http.Header, k string) string
}

type PaginationDTO added in v0.1.14

type PaginationDTO struct {
	Total     int64 `json:"total" example:"120"`
	Current   int   `json:"current" example:"3"`
	TotalPage int   `json:"total_page" example:"6"`
	PageSize  int   `json:"page_size" example:"20"`
}

func NewPaginationDTO added in v0.1.14

func NewPaginationDTO(pageSize, pageNum int, total int64) *PaginationDTO

type QueryParser added in v0.1.12

type QueryParser interface {
	Exist(h url.Values, k string) bool
	Get(h url.Values, k string) string
}

type SuccessResponse added in v0.1.14

type SuccessResponse struct {
	Status  int         `json:"status" example:"200"`
	Result  interface{} `json:"result,omitempty" `
	TraceID string      `json:"trace_id" example:"1-trace-it"`
}

Jump to

Keyboard shortcuts

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