context

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// HTML text/html
	HTML contentType = iota

	// JSON application/json
	JSON

	// XML application/xml
	XML

	// Text text/plain
	Text

	// URLEncodedForm application/x-www-form-urlencoded
	URLEncodedForm
)

Variables

View Source
var ContentTypes = map[contentType]string{
	HTML:           "text/html; charset=utf-8",
	JSON:           "application/json; charset=utf-8",
	XML:            "application/xml; charset=utf-8",
	Text:           "text/plain; charset=utf-8",
	URLEncodedForm: "application/x-www-form-urlencoded; charset=utf-8",
}

ContentTypes http content type map

Functions

func ContentTypeValid

func ContentTypeValid(current string, ct contentType) bool

ContentTypeValid ...

Types

type Context

type Context struct {
	Client   *http.Client   `json:"client,omitempty"`
	Request  *http.Request  `json:"request,omitempty"`
	Response *http.Response `json:"response,omitempty"`

	TimeTrace Time
	// contains filtered or unexported fields
}

Context HTTP transactions

func New

func New() *Context

New creates an empty Context

func NewWithContext

func NewWithContext(ctx originContext.Context) *Context

NewWithContext creates an empty Context

func (*Context) Error

func (c *Context) Error() error

Error get context error

func (*Context) ErrorString

func (c *Context) ErrorString() string

ErrorString get context error as string

func (*Context) GetClient

func (c *Context) GetClient() *http.Client

GetClient get original http client

func (*Context) GetRequest

func (c *Context) GetRequest() *http.Request

GetRequest get original http request

func (*Context) GetResponse

func (c *Context) GetResponse() *http.Response

GetResponse get original http response

func (*Context) GetTimeTrace

func (c *Context) GetTimeTrace() Time

GetTimeTrace set http debug mode

func (*Context) HasError

func (c *Context) HasError() bool

HasError get context error as string

func (*Context) ResetError

func (c *Context) ResetError()

ResetError set context error to nil

func (*Context) SetContentType

func (ctx *Context) SetContentType(ct contentType)

SetContentType set content type on header of http request

func (*Context) SetError

func (c *Context) SetError(err error)

SetError set context error

func (*Context) TraceDo

func (c *Context) TraceDo() (err error)

TraceDo ...

type Time

type Time struct {
	Offset        time.Duration `json:"offset"`
	Duration      time.Duration `json:"duration"`
	ConnDuration  time.Duration `json:"connDuration"`  // connection setup(DNS lookup + Dial up) duration
	DNSDuration   time.Duration `json:"dnsDuration"`   // dns lookup duration
	ReqDuration   time.Duration `json:"reqDuration"`   // request "write" duration
	ResDuration   time.Duration `json:"resDuration"`   // response "read" duration
	DelayDuration time.Duration `json:"delayDuration"` // delay between response and request
}

Time ...

Jump to

Keyboard shortcuts

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