xcontext

package
v1.0.16 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2023 License: MIT Imports: 3 Imported by: 3

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"`
	// 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) 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 ...

Jump to

Keyboard shortcuts

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