content

package
v1.1.14 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2024 License: BSD-3-Clause Imports: 27 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultDataKey    = "data"
	DefaultCodeKey    = "code"
	DefaultMessageKey = "message"
	DefaultCode       = 200
)
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,
		}
	}
)
View Source
var (
	ErrInvalidRequest = errors.New("invalid request")
)

Functions

func ExchangeIpFromProxy added in v1.1.0

func ExchangeIpFromProxy(addr string, r contracts.RequestContract) string

func GetJsonValue

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

func JsonResponse

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

func NetHeaderToString

func NetHeaderToString(h http.Header) string

func Redirect added in v1.1.1

func SetTrustedProxies added in v1.1.0

func SetTrustedProxies(proxies ...string)

func SetTrustedProxyHeaderSets added in v1.1.0

func SetTrustedProxyHeaderSets(sets ...string)

Types

type ApiResouce

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

func ResourceResponse

func ResourceResponse(data interface{}) *ApiResouce

func (*ApiResouce) Code

func (ar *ApiResouce) Code(code int) *ApiResouce

func (*ApiResouce) Data

func (ar *ApiResouce) Data(data interface{}) *ApiResouce

func (*ApiResouce) MarshalJSON

func (ar *ApiResouce) MarshalJSON() ([]byte, error)

func (*ApiResouce) Message

func (ar *ApiResouce) Message(message string) *ApiResouce

func (*ApiResouce) StatusCode added in v0.0.17

func (ar *ApiResouce) StatusCode() int

func (*ApiResouce) WithStatus added in v0.0.17

func (ar *ApiResouce) WithStatus(statusCode int) *ApiResouce

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 FastHttpFileServer

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

func NewFastHttpFileServer

func NewFastHttpFileServer(root string, stripSlashes int) *FastHttpFileServer

func (*FastHttpFileServer) Root

func (ffs *FastHttpFileServer) Root() string

func (*FastHttpFileServer) StripSlashes

func (ffs *FastHttpFileServer) StripSlashes() int

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) CookieByte added in v1.1.3

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

func (*FastHttpRequest) ExceptsJson

func (r *FastHttpRequest) ExceptsJson() bool

func (*FastHttpRequest) File

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) GetURL added in v1.1.2

func (r FastHttpRequest) GetURL() *url.URL

func (*FastHttpRequest) GetUint64

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

func (*FastHttpRequest) GetUri

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

func (*FastHttpRequest) GetValue

func (r *FastHttpRequest) GetValue(key ...string) contracts.InputValue

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) RemoteAddr added in v0.0.14

func (f *FastHttpRequest) RemoteAddr() string

func (*FastHttpRequest) RequestWithJson

func (r *FastHttpRequest) RequestWithJson() bool

func (*FastHttpRequest) SetHeader

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

func (*FastHttpRequest) SetHeaderString

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

func (*FastHttpRequest) ToString added in v0.0.9

func (r *FastHttpRequest) ToString() string

func (*FastHttpRequest) Unmarshal

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

type File

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

func NewFileResponse

func NewFileResponse(path string) *File

func (*File) Path

func (f *File) Path() string

type JsonMessage

type JsonMessage int

func (JsonMessage) MarshalJSON

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

func (JsonMessage) StatusCode added in v0.0.7

func (m JsonMessage) StatusCode() int

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) CookieByte added in v1.1.3

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

func (*NetHttpRequest) ExceptsJson

func (n *NetHttpRequest) ExceptsJson() bool

func (*NetHttpRequest) File

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) GetURL added in v1.1.2

func (n *NetHttpRequest) GetURL() *url.URL

func (*NetHttpRequest) GetUint64

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

func (*NetHttpRequest) GetUri

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

func (*NetHttpRequest) GetValue

func (n *NetHttpRequest) GetValue(key ...string) contracts.InputValue

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) RemoteAddr

func (n *NetHttpRequest) RemoteAddr() string

func (*NetHttpRequest) RequestWithJson

func (n *NetHttpRequest) RequestWithJson() bool

func (*NetHttpRequest) SetHeader

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

func (*NetHttpRequest) SetHeaderString

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

func (*NetHttpRequest) ToString added in v0.0.9

func (n *NetHttpRequest) ToString() string

func (*NetHttpRequest) Unmarshal

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

type Param

type Param string

func (Param) Value

func (p Param) Value() string

type ParamInt

type ParamInt int

func (ParamInt) Value

func (p ParamInt) Value() int

type ParamInt64

type ParamInt64 int64

func (ParamInt64) Value

func (p ParamInt64) Value() int64

type ParamUint64

type ParamUint64 uint64

func (ParamUint64) Value

func (p ParamUint64) Value() uint64

type RedirectResponse added in v1.1.1

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

func (*RedirectResponse) URL added in v1.1.1

func (r *RedirectResponse) URL() string

type Request

type Request struct {
	contracts.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) ClearCookies added in v1.1.3

func (r *Response) ClearCookies()

func (*Response) Content

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

Content response body

func (*Response) Cookies added in v1.1.3

func (r *Response) Cookies() []*http.Cookie

func (*Response) Handled

func (r *Response) Handled() bool

func (*Response) Header added in v1.1.7

func (r *Response) Header(header string) string

func (*Response) Headers

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

Headers response headers

func (*Response) SetCookie added in v1.1.3

func (r *Response) SetCookie(cookie *http.Cookie)

func (*Response) SetHeader

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

func (*Response) SetHeaders added in v0.0.7

func (r *Response) SetHeaders(headers map[string]string) contracts.ResponseContract

func (*Response) SetStatusCode

func (r *Response) SetStatusCode(code int) contracts.ResponseContract

func (*Response) StatusCode

func (r *Response) StatusCode() int

WithStatusCode status code

type SimpleParamRequest

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

func (*SimpleParamRequest) GetContainer added in v0.0.10

func (shr *SimpleParamRequest) GetContainer() container.Interface

func (*SimpleParamRequest) GetRouteName added in v1.0.0

func (shr *SimpleParamRequest) GetRouteName() string

func (*SimpleParamRequest) Param

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

func (*SimpleParamRequest) ParamBytes

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

func (*SimpleParamRequest) ParamInt

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

func (*SimpleParamRequest) ParamInt64

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

func (*SimpleParamRequest) ParamUint64

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

func (*SimpleParamRequest) Params

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

func (*SimpleParamRequest) ParamsSlice

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

func (*SimpleParamRequest) SetContainer added in v0.0.10

func (shr *SimpleParamRequest) SetContainer(ioc container.Interface)

func (*SimpleParamRequest) SetParams

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

func (*SimpleParamRequest) SetParamsSlice

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

func (*SimpleParamRequest) SetRouteName added in v1.0.0

func (shr *SimpleParamRequest) SetRouteName(name string)

type StreamResponse added in v1.1.10

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

func NewDownloadResponse added in v1.1.10

func NewDownloadResponse(stream io.ReadCloser, filename string) *StreamResponse

func NewStreamResponse added in v1.1.10

func NewStreamResponse(stream io.ReadCloser, code int) *StreamResponse

func (*StreamResponse) Stream added in v1.1.10

func (sr *StreamResponse) Stream() io.ReadCloser

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