httpx

package
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2021 License: MIT Imports: 16 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 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 QueryParser added in v0.1.12

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

type Response

type Response struct {
	Status  int            `json:"status"`
	Result  interface{}    `json:"result,omitempty"`
	Error   *ResponseError `json:"error,omitempty"`
	TraceID string         `json:"trace_id"`
}

type ResponseError

type ResponseError struct {
	Code    int      `json:"code"`
	Message string   `json:"message"`
	Details []string `json:"details"`
}

Jump to

Keyboard shortcuts

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