content

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2020 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ContentTypeJson = "application/json; charset=utf-8"
	ContentTypeHtml = "text/html; charset=utf-8"
	DefaultHeader   = func() map[string]string {
		return map[string]string{}
	}
	TextHeader = func() map[string]string {
		return map[string]string{
			"Content-Type": ContentTypeHtml,
		}
	}
	JsonHeader = func() map[string]string {
		return map[string]string{
			"Content-Type": ContentTypeJson,
		}
	}
	HtmlHeader = func() map[string]string {
		return map[string]string{
			"Content-Type": ContentTypeHtml,
		}
	}
)

Functions

func GetJsonValue

func GetJsonValue(r RequestContract, key string) []byte

func HtmlErrorResponseFormatter

func HtmlErrorResponseFormatter(err exception.Exception, code int, debug bool, headers map[string]string) contracts.ResponseContract

func JsonErrorResponseFormatter

func JsonErrorResponseFormatter(err exception.Exception, code int, debug bool, headers map[string]string) contracts.ResponseContract

func JsonResponse

func JsonResponse(data interface{}, code int, headers map[string]string) contracts.ResponseContract

Types

type ErrorResponse

type ErrorResponse struct {
	*Response
	// contains filtered or unexported fields
}

func ErrResponse

func ErrResponse(e exception.Exception, code int, headers map[string]string) *ErrorResponse

func ErrResponseFromError

func ErrResponseFromError(e error, code int, headers map[string]string) *ErrorResponse

func ErrResponseFromOrigin

func ErrResponseFromOrigin(resp *Response) *ErrorResponse

func HttpErrorResponse

func HttpErrorResponse(message string, statusCode int, code int, headers map[string]string) *ErrorResponse

func NotFoundResponse

func NotFoundResponse(message string) *ErrorResponse

func (*ErrorResponse) E

type ErrorResponseFormatter

type ErrorResponseFormatter func(err exception.Exception, code int, debug bool, headers map[string]string) contracts.ResponseContract

type FastHttpRequest

type FastHttpRequest struct {
	SimpleParamRequest
	// contains filtered or unexported fields
}

func NewFastHttpRequest

func NewFastHttpRequest(origin *fasthttp.RequestCtx) *FastHttpRequest

func (*FastHttpRequest) Accepts

func (r *FastHttpRequest) Accepts() []byte

func (*FastHttpRequest) Authorization

func (r *FastHttpRequest) Authorization() []byte

func (*FastHttpRequest) BearerToken

func (r *FastHttpRequest) BearerToken() ([]byte, error)

func (*FastHttpRequest) Context

func (r *FastHttpRequest) Context() context.Context

func (*FastHttpRequest) ExceptsJson

func (r *FastHttpRequest) ExceptsJson() bool

func (*FastHttpRequest) File added in v0.0.2

func (r *FastHttpRequest) File(key string) (UploadFile, error)

func (*FastHttpRequest) Get

func (r *FastHttpRequest) Get(key string) []byte

func (*FastHttpRequest) GetClientIp

func (r *FastHttpRequest) GetClientIp() string

func (*FastHttpRequest) GetContent

func (r *FastHttpRequest) GetContent() []byte

func (*FastHttpRequest) GetInt

func (r *FastHttpRequest) GetInt(key string) (int, error)

func (*FastHttpRequest) GetInt64

func (r *FastHttpRequest) GetInt64(key string) (int64, error)

func (*FastHttpRequest) GetMethod

func (r *FastHttpRequest) GetMethod() string

func (*FastHttpRequest) GetPathBytes

func (r *FastHttpRequest) GetPathBytes() []byte

func (*FastHttpRequest) GetSignature

func (r *FastHttpRequest) GetSignature() []byte

func (*FastHttpRequest) GetString

func (r *FastHttpRequest) GetString(key string) string

func (*FastHttpRequest) GetUint64

func (r *FastHttpRequest) GetUint64(key string) (uint64, error)

func (*FastHttpRequest) GetUri

func (r *FastHttpRequest) GetUri() []byte

func (*FastHttpRequest) Header

func (r *FastHttpRequest) Header(key string) []byte

func (*FastHttpRequest) HeaderString

func (r *FastHttpRequest) HeaderString(key string) string

func (*FastHttpRequest) IsXmlHttpRequest

func (r *FastHttpRequest) IsXmlHttpRequest() bool

func (*FastHttpRequest) Origin

func (r *FastHttpRequest) Origin() *fasthttp.RequestCtx

func (*FastHttpRequest) RequestWithJson added in v0.0.2

func (r *FastHttpRequest) RequestWithJson() bool

func (*FastHttpRequest) SetHeader

func (r *FastHttpRequest) SetHeader(key string, value []byte) RequestContract

func (*FastHttpRequest) SetHeaderString

func (r *FastHttpRequest) SetHeaderString(key, value string) RequestContract

func (*FastHttpRequest) Unmarshal

func (r *FastHttpRequest) Unmarshal(to interface{}) error

type File

type File struct {
	*Response
	// contains filtered or unexported fields
}

func (*File) Path

func (f *File) Path() string

type JsonMessage

type JsonMessage int

func (JsonMessage) MarshalJSON

func (m JsonMessage) MarshalJSON() ([]byte, error)

type NetHttpRequest

type NetHttpRequest struct {
	SimpleParamRequest
	// contains filtered or unexported fields
}

func NewNetHttpRequest

func NewNetHttpRequest(origin *http.Request, w http.ResponseWriter) *NetHttpRequest

func (*NetHttpRequest) Accepts

func (n *NetHttpRequest) Accepts() []byte

func (*NetHttpRequest) Authorization

func (n *NetHttpRequest) Authorization() []byte

func (*NetHttpRequest) BearerToken

func (n *NetHttpRequest) BearerToken() ([]byte, error)

func (*NetHttpRequest) Context

func (n *NetHttpRequest) Context() context.Context

func (*NetHttpRequest) ExceptsJson

func (n *NetHttpRequest) ExceptsJson() bool

func (*NetHttpRequest) File added in v0.0.2

func (n *NetHttpRequest) File(key string) (UploadFile, error)

func (*NetHttpRequest) Get

func (n *NetHttpRequest) Get(key string) []byte

func (*NetHttpRequest) GetClientIp

func (n *NetHttpRequest) GetClientIp() string

/ GetClientIp get client ip / reverse proxy need implement

func (*NetHttpRequest) GetContent

func (n *NetHttpRequest) GetContent() []byte

func (*NetHttpRequest) GetInt

func (n *NetHttpRequest) GetInt(key string) (int, error)

func (*NetHttpRequest) GetInt64

func (n *NetHttpRequest) GetInt64(key string) (int64, error)

func (*NetHttpRequest) GetMethod

func (n *NetHttpRequest) GetMethod() string

func (*NetHttpRequest) GetPathBytes

func (n *NetHttpRequest) GetPathBytes() []byte

func (*NetHttpRequest) GetSignature

func (n *NetHttpRequest) GetSignature() []byte

func (*NetHttpRequest) GetString

func (n *NetHttpRequest) GetString(key string) string

func (*NetHttpRequest) GetUint64

func (n *NetHttpRequest) GetUint64(key string) (uint64, error)

func (*NetHttpRequest) GetUri

func (n *NetHttpRequest) GetUri() []byte

func (*NetHttpRequest) Header

func (n *NetHttpRequest) Header(key string) []byte

func (*NetHttpRequest) HeaderString

func (n *NetHttpRequest) HeaderString(key string) string

func (*NetHttpRequest) IsXmlHttpRequest

func (n *NetHttpRequest) IsXmlHttpRequest() bool

func (*NetHttpRequest) Origin

func (n *NetHttpRequest) Origin() *http.Request

func (*NetHttpRequest) OriginWriter

func (n *NetHttpRequest) OriginWriter() http.ResponseWriter

func (*NetHttpRequest) RequestWithJson added in v0.0.2

func (n *NetHttpRequest) RequestWithJson() bool

func (*NetHttpRequest) SetHeader

func (n *NetHttpRequest) SetHeader(key string, value []byte) RequestContract

func (*NetHttpRequest) SetHeaderString

func (n *NetHttpRequest) SetHeaderString(key, value string) RequestContract

func (*NetHttpRequest) Unmarshal

func (n *NetHttpRequest) Unmarshal(to interface{}) error

type Param added in v0.0.2

type Param string

func (Param) Value added in v0.0.2

func (p Param) Value() string

type ParamInt added in v0.0.2

type ParamInt int

func (ParamInt) Value added in v0.0.2

func (p ParamInt) Value() int

type ParamInt64 added in v0.0.2

type ParamInt64 int64

func (ParamInt64) Value added in v0.0.2

func (p ParamInt64) Value() int64

type ParamUint64 added in v0.0.2

type ParamUint64 uint64

func (ParamUint64) Value added in v0.0.2

func (p ParamUint64) Value() uint64

type Request

type Request struct {
	RequestContract
}

type Response

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

Response http response

func HtmlResponse

func HtmlResponse(content string, code int) *Response

func NewHandledResponse

func NewHandledResponse(code ...int) *Response

func NewResponse

func NewResponse(content []byte, headers map[string]string, code int) *Response

func TextResponse

func TextResponse(content string, code int) *Response

func (*Response) Content

func (r *Response) Content() []byte

Content response body

func (*Response) Handled

func (r *Response) Handled() bool

func (*Response) Headers

func (r *Response) Headers() map[string]string

Headers response headers

func (*Response) SetHeader

func (r *Response) SetHeader(key string, value string) contracts.ResponseContract

func (*Response) SetStatusCode

func (r *Response) SetStatusCode(code int)

func (*Response) StatusCode

func (r *Response) StatusCode() int

WithStatusCode status code

type SimpleParamRequest added in v0.0.2

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

func (*SimpleParamRequest) Param added in v0.0.2

func (shr *SimpleParamRequest) Param(key string) string

func (*SimpleParamRequest) ParamBytes added in v0.0.2

func (shr *SimpleParamRequest) ParamBytes(key string) []byte

func (*SimpleParamRequest) ParamInt added in v0.0.2

func (shr *SimpleParamRequest) ParamInt(key string) (int, error)

func (*SimpleParamRequest) ParamInt64 added in v0.0.2

func (shr *SimpleParamRequest) ParamInt64(key string) (int64, error)

func (*SimpleParamRequest) ParamUint64 added in v0.0.2

func (shr *SimpleParamRequest) ParamUint64(key string) (uint64, error)

func (*SimpleParamRequest) Params added in v0.0.2

func (shr *SimpleParamRequest) Params() map[string][]byte

func (*SimpleParamRequest) ParamsSlice added in v0.0.2

func (shr *SimpleParamRequest) ParamsSlice() [][]byte

func (*SimpleParamRequest) SetParams added in v0.0.2

func (shr *SimpleParamRequest) SetParams(params map[string][]byte)

func (*SimpleParamRequest) SetParamsSlice added in v0.0.2

func (shr *SimpleParamRequest) SetParamsSlice(paramsSlice [][]byte)

func (*SimpleParamRequest) SetUser added in v0.0.2

func (shr *SimpleParamRequest) SetUser(u contracts.User)

func (*SimpleParamRequest) User added in v0.0.2

func (shr *SimpleParamRequest) User() contracts.User

type TemplateResponse

type TemplateResponse struct {
	*Response
	// contains filtered or unexported fields
}

func TempResponse

func TempResponse(t *template.Template, code int, data interface{}) *TemplateResponse

func (*TemplateResponse) SetTemplateData

func (t *TemplateResponse) SetTemplateData(templateData interface{}) *TemplateResponse

func (*TemplateResponse) Template

func (t *TemplateResponse) Template() *template.Template

func (*TemplateResponse) TemplateData

func (t *TemplateResponse) TemplateData() interface{}

Jump to

Keyboard shortcuts

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