httprxr

package
v0.0.0-...-11273d6 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2021 License: MIT Imports: 16 Imported by: 4

Documentation

Index

Constants

View Source
const (
	//STANDBY = iota
	OPENED = iota + 1
	CLOSED
)
View Source
const InvalidParamErrorCode = "invalid_param"

Variables

View Source
var JSONResponse = &RespSetting{
	contentType: "application/json;charset=UTF-8",
	cacheEnable: false,
}
View Source
var RespMessageType = responseMsgType{
	Error:   messageType("error"),
	Info:    messageType("info"),
	Warning: messageType("warning"),
}

Functions

func BearerAuth

func BearerAuth(r *http.Request) (accessToken string, ok bool)

func ContextGet

func ContextGet(r *http.Request, key interface{}) interface{}

func ContextSet

func ContextSet(r *http.Request, paris ...interface{}) *http.Request

func GetJSONRequestData

func GetJSONRequestData(r *http.Request, data interface{}) error

export

func GetJSONRequestMap

func GetJSONRequestMap(r *http.Request) map[string]interface{}

export

func GetRequestVars

func GetRequestVars(r *http.Request, keys ...string) map[string]string

export

func Response

func Response(w http.ResponseWriter, setting ResponseSetting, filler ResponseFiller, statusCode ...int)

export

func ResponseJSON

func ResponseJSON(w http.ResponseWriter, statusCode int, data interface{}, settings ...RespSetting)

export

func SetupWebsocket

func SetupWebsocket(wsc *WsConnect, w http.ResponseWriter, r *http.Request, headers ...map[string]string) (err error)

export

Types

type JSONFiller

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

func NewJSONFiller

func NewJSONFiller(data interface{}) *JSONFiller

func (*JSONFiller) FillResponse

func (jf *JSONFiller) FillResponse(w *RespWriter) (err error)

type RequestVar

type RequestVar map[string][]string

func ParseRequestVars

func ParseRequestVars(r *http.Request, keys ...string) RequestVar

func (RequestVar) Exist

func (rv RequestVar) Exist(key string) bool

func (RequestVar) Get

func (rv RequestVar) Get(key string) []string

func (RequestVar) GetBool

func (rv RequestVar) GetBool(key string) (bool, error)

func (RequestVar) GetBools

func (rv RequestVar) GetBools(key string) ([]bool, error)

func (RequestVar) GetFloat

func (rv RequestVar) GetFloat(key string) (float64, error)

func (RequestVar) GetFloats

func (rv RequestVar) GetFloats(key string) ([]float64, error)

func (RequestVar) GetInt

func (rv RequestVar) GetInt(key string) (int64, error)

func (RequestVar) GetInts

func (rv RequestVar) GetInts(key string) ([]int64, error)

func (RequestVar) GetString

func (rv RequestVar) GetString(key string) string

func (RequestVar) GetTime

func (rv RequestVar) GetTime(key string, format string, loc ...*time.Location) (time.Time, error)

func (RequestVar) GetTimes

func (rv RequestVar) GetTimes(key string, format string, loc ...*time.Location) ([]time.Time, error)

func (RequestVar) GetUint

func (rv RequestVar) GetUint(key string) (uint64, error)

func (RequestVar) GetUints

func (rv RequestVar) GetUints(key string) ([]uint64, error)

type RespSetting

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

func NewRespSetting

func NewRespSetting(contentType string, cacheEnable bool, header http.Header) *RespSetting

export

func (RespSetting) GetContentType

func (rs RespSetting) GetContentType() string

func (RespSetting) GetHeader

func (rs RespSetting) GetHeader() http.Header

func (RespSetting) IsCacheEnable

func (rs RespSetting) IsCacheEnable() bool

func (RespSetting) New

func (rs RespSetting) New(cacheEnable bool, header http.Header) *RespSetting

func (*RespSetting) SetCacheEnable

func (rs *RespSetting) SetCacheEnable(cache bool)

func (*RespSetting) SetHeader

func (rs *RespSetting) SetHeader(header http.Header)

type RespWriter

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

func (*RespWriter) Write

func (rw *RespWriter) Write(p []byte) (n int, err error)

type ResponseData

type ResponseData map[string]interface{}

type ResponseFiller

type ResponseFiller interface {
	FillResponse(w *RespWriter) error
}

type ResponseMessage

type ResponseMessage struct {
	Code    string                 `json:"error_code"`
	Message string                 `json:"error_message"`
	Data    map[string]interface{} `json:"data"`
	Type    messageType            `json:"type"`
}

func ErrorMessage

func ErrorMessage(err errorx.Error, data ...map[string]interface{}) ResponseMessage

export

func ExceptionMessage

func ExceptionMessage(err error, codes ...string) ResponseMessage

export

func InvalidParamError

func InvalidParamError(param string, value ...interface{}) ResponseMessage

export

func MakeErrorMessage

func MakeErrorMessage(code string, err error, data ...map[string]interface{}) ResponseMessage

export

func NewErrorMessage

func NewErrorMessage(code, message string, data ...map[string]interface{}) ResponseMessage

export

func NewResponseMessage

func NewResponseMessage(msgType messageType, code, message string, data ...map[string]interface{}) ResponseMessage

export

type ResponseSetting

type ResponseSetting interface {
	GetContentType() string
	IsCacheEnable() bool
	GetHeader() http.Header
}

type StatusResponse

type StatusResponse struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

func MakeStatusResponse

func MakeStatusResponse(writer http.ResponseWriter) *StatusResponse

func (*StatusResponse) GetStatusCode

func (sr *StatusResponse) GetStatusCode() int

func (*StatusResponse) Hijack

func (sr *StatusResponse) Hijack() (net.Conn, *bufio.ReadWriter, error)

func (*StatusResponse) WriteHeader

func (sr *StatusResponse) WriteHeader(statusCode int)

type WsCloseHandler

type WsCloseHandler func(int, string) error

type WsConnect

type WsConnect struct {
	Code     string
	Decoder  WsDecoder
	Encoder  WsEncoder
	Status   uint
	Conn     *gws.Conn
	Duration time.Duration
	// contains filtered or unexported fields
}

func (*WsConnect) AddCloseHandler

func (wsc *WsConnect) AddCloseHandler(handler WsCloseHandler)

func (*WsConnect) AddReceiver

func (wsc *WsConnect) AddReceiver(receiver WsReceiver)

func (*WsConnect) GetStatus

func (wsc *WsConnect) GetStatus() uint

func (*WsConnect) IsOpen

func (wsc *WsConnect) IsOpen() bool

func (*WsConnect) ListenAndServe

func (wsc *WsConnect) ListenAndServe()

func (*WsConnect) SendMessage

func (wsc *WsConnect) SendMessage(message interface{})

func (*WsConnect) SetupConnection

func (wsc *WsConnect) SetupConnection(ws *gws.Conn)

type WsDecoder

type WsDecoder func([]byte) (interface{}, error)

type WsEncoder

type WsEncoder func(interface{}) (int, []byte, error)

type WsProgressHandler

type WsProgressHandler WsConnect

func (*WsProgressHandler) SendData

func (wph *WsProgressHandler) SendData(msg interface{}) error

type WsReceiver

type WsReceiver func(interface{})

type WsWriter

type WsWriter interface {
	EncodeWsMessage() (int, []byte, error)
}

Jump to

Keyboard shortcuts

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