com

package
v0.0.15 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2021 License: MIT Imports: 26 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	HideServerErr = defaultHideServerErr
)

Functions

func AddGlbRespMidwares

func AddGlbRespMidwares(mws ...interface{})

func IntsRegExp

func IntsRegExp(ies []interface{}) string

func ReqResp

func ReqResp(ictx iris.Context, as ...interface{}) (*Req, *RespStruct, context.Context)

func StringsRegExp

func StringsRegExp(elems []string) string

func UintsRegExp

func UintsRegExp(set ...interface{}) string

Types

type Req

type Req struct {
	ID     string
	Method string
	// contains filtered or unexported fields
}

func NewReq

func NewReq(p interface{}) *Req

func (*Req) AddCookie

func (r *Req) AddCookie(c *http.Cookie)

func (*Req) Body

func (r *Req) Body(param string, patterns ...interface{}) (*ReqProp, *ae.Error)

func (*Req) ContentType

func (r *Req) ContentType() string

func (*Req) Cookie

func (r *Req) Cookie(name string) (*http.Cookie, error)

func (*Req) Cookies

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

func (*Req) FastXheader

func (r *Req) FastXheader(name string, patterns ...interface{}) *ReqProp

func (*Req) FastXparam

func (r *Req) FastXparam(name string) *ReqProp

func (*Req) Header

func (r *Req) Header(param string, patterns ...interface{}) (*ReqProp, *ae.Error)

func (*Req) Headers

func (r *Req) Headers() map[string]interface{}

func (*Req) Qparam

func (r *Req) Qparam(name string, patterns ...interface{}) (v *ReqProp, e *ae.Error)

func (*Req) Queries

func (r *Req) Queries() map[string]interface{}

func (*Req) Query

func (r *Req) Query(param string, patterns ...interface{}) (*ReqProp, *ae.Error)

func (*Req) Uri

func (r *Req) Uri() string

func (*Req) XHeader

func (r *Req) XHeader(name string, patterns ...interface{}) (v *ReqProp, e *ae.Error)

跟踪客户端数据,优先级:url --> header `X-***` --> cookie 标准:Referer, User-Agent, 自定义:X-Csrf-Token, X-Request-Id, X-From, X-Inviter @warn 尽量不要通过自定义header传参,因为可能某个web server会基于安全禁止某些无法识别的header

func (*Req) Xhost

func (r *Req) Xhost() string

func (*Req) Xparam

func (r *Req) Xparam(name string, patterns ...interface{}) (v *ReqProp, e *ae.Error)

in url params -> in header? -> in cookie? e.g. csrf_token: in url params? -> Csrf-Token: in header? X-Csrf-Token: in header-> csrf_token: in cookie

type ReqProp

type ReqProp struct {
	dtype.Dtype
	// contains filtered or unexported fields
}

func NewReqProp

func NewReqProp(param string, data interface{}) *ReqProp

func (*ReqProp) Default

func (p *ReqProp) Default(v interface{})

func (*ReqProp) Filter

func (p *ReqProp) Filter(patterns ...interface{}) *ae.Error

@param pattern e.g. `[[:word:]]+` `\w+` Filter(pattern string, required bool) Filter(required bool) Filter(pattern string) Filter(default dtype.Dtype)

type RespContentDTO

type RespContentDTO struct {
	Code    int         `json:"code"`
	Msg     string      `json:"msg"`
	Payload interface{} `json:"data"`
}

type RespStruct

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

func Resp

func Resp(ictx iris.Context, req *Req, as ...interface{}) *RespStruct

func (*RespStruct) AddMidwares

func (resp *RespStruct) AddMidwares(mws ...interface{})

func (*RespStruct) CatchErrors

func (resp *RespStruct) CatchErrors(es ...*ae.Error) error

func (*RespStruct) DelHeader

func (resp *RespStruct) DelHeader(head string)

func (*RespStruct) Header

func (resp *RespStruct) Header(head string) string

func (*RespStruct) LoadOrSetHeader

func (resp *RespStruct) LoadOrSetHeader(k, v string)

func (*RespStruct) ServeFile

func (resp *RespStruct) ServeFile(f string, hps ...map[string]string) error

1. set Last-Modified 2. check preconditions

  • check If-Match
  • check If-Unmodified-Since
  • check If-None-Match
  • check If-Modified-Since
  • check If-Range

func (*RespStruct) SetHeader

func (resp *RespStruct) SetHeader(k, v string)

func (*RespStruct) SetHeaders

func (resp *RespStruct) SetHeaders(heads map[string]string)

func (*RespStruct) Write

func (resp *RespStruct) Write(a interface{}, d ...interface{}) error

Write(404) Write(404, "Not Found") Write(ae.Error{}) Write(ae.Error{}, data) Write(ae.Error{}, data) Write(data)

func (*RespStruct) WriteAliasId

func (resp *RespStruct) WriteAliasId(alias string, id string) error

func (*RespStruct) WriteCode

func (resp *RespStruct) WriteCode(code int) error

func (*RespStruct) WriteE

func (resp *RespStruct) WriteE(e *ae.Error) error

func (*RespStruct) WriteErr

func (resp *RespStruct) WriteErr(code int, msg string) error

func (*RespStruct) WriteErrMsg

func (resp *RespStruct) WriteErrMsg(msg string) error

func (*RespStruct) WriteError

func (resp *RespStruct) WriteError(err error) error

func (*RespStruct) WriteHeader

func (resp *RespStruct) WriteHeader(code interface{})

func (*RespStruct) WriteId

func (resp *RespStruct) WriteId(id string) error

返回插入数据的ID,ID 可能是联合主键,或者字段不为id,那么就会以对象形式返回 如: {"id":12314} {"id":"ADREDD"} {"id":{"k":"i_am_prinary_key"}} {"id": {"k":"", "uid":""}}

func (*RespStruct) WriteJSONP

func (resp *RespStruct) WriteJSONP(varname string, d map[string]interface{}) error

func (*RespStruct) WriteJointId

func (resp *RespStruct) WriteJointId(args ...interface{}) error

k1,v1, k2, v2, k3,v3

func (*RespStruct) WriteOK

func (resp *RespStruct) WriteOK() error

func (*RespStruct) WriteRaw

func (resp *RespStruct) WriteRaw(ps ...interface{}) (int, error)

func (*RespStruct) WriteSafeE

func (resp *RespStruct) WriteSafeE(e ae.Error) error

func (*RespStruct) WriteUint64AliasId

func (resp *RespStruct) WriteUint64AliasId(alias string, id uint64) error

func (*RespStruct) WriteUint64Id

func (resp *RespStruct) WriteUint64Id(id uint64) error

func (*RespStruct) WriteUintAliasId

func (resp *RespStruct) WriteUintAliasId(alias string, id uint) error

func (*RespStruct) WriteUintId

func (resp *RespStruct) WriteUintId(id uint) error

Jump to

Keyboard shortcuts

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