ctx

package
v0.0.0-...-cf0249b Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2024 License: MIT Imports: 16 Imported by: 4

Documentation

Index

Constants

View Source
const (
	HTTPType = "http"
	WSType   = "ws"
	RPCType  = "rpc"
	GQLType  = "gql"
)
View Source
const (
	REQUEST_FINISHED = "REQUEST_FINISHED"
	CATCH_EXCEPTION  = "CATCH_EXCEPTION"
)
View Source
const (
	REQUEST_ID = "X-Request-Id"
)

header keys

View Source
const (
	TagBind = "bind"
)

Variables

This section is empty.

Functions

func BindFile

func BindFile(f File, s any) (map[string][]*DataFile, any)

func GetTagParamIndex

func GetTagParamIndex(v string) (int, string)

func GetTagParams

func GetTagParams(v string) []string

func NewEvent

func NewEvent() *event

func ResolveWSEventname

func ResolveWSEventname(e string) (string, string)

Types

type Body

type Body map[string]any

func (Body) Bind

func (b Body) Bind(s any) (any, []FieldLevel)

func (Body) Del

func (b Body) Del(k string)

func (Body) Get

func (b Body) Get(k string) any

func (Body) Has

func (b Body) Has(k string) bool

func (Body) Set

func (b Body) Set(k string, v any)

type Context

type Context struct {
	*http.Request
	http.ResponseWriter

	ParamKeys   map[string][]int
	ParamValues []string

	ID   string
	Type string

	Next      Next
	Event     *event
	Code      int
	Timestamp time.Time

	// Extend context
	// WebSocket
	WS *WS
	// contains filtered or unexported fields
}

func NewContext

func NewContext() *Context

func (*Context) Body

func (c *Context) Body() Body

func (*Context) File

func (c *Context) File() File

func (*Context) Form

func (c *Context) Form() Form

func (*Context) GetID

func (c *Context) GetID() string

func (*Context) GetRoute

func (c *Context) GetRoute() string

func (*Context) GetType

func (c *Context) GetType() string

func (*Context) Header

func (c *Context) Header() Header

func (*Context) JSON

func (c *Context) JSON(data ...any)

func (*Context) JSONP

func (c *Context) JSONP(data ...any)

func (*Context) Param

func (c *Context) Param() Param

func (*Context) Query

func (c *Context) Query() Query

func (*Context) Redirect

func (c *Context) Redirect(url string)

func (*Context) Reset

func (c *Context) Reset()

func (*Context) SetID

func (c *Context) SetID(id string) *Context

func (*Context) SetRoute

func (c *Context) SetRoute(route string) *Context

func (*Context) SetType

func (c *Context) SetType(t string) *Context

func (*Context) Status

func (c *Context) Status(code int) *Context

func (*Context) Text

func (c *Context) Text(data string, args ...any)

type DataFile

type DataFile struct {
	*multipart.FileHeader
	Index    int
	Size     int64
	Total    int
	Key      string
	Filename string
	Type     string
	Dest     string
}

type DataWriter

type DataWriter interface {
	WriteData(int)
}

type ErrFn

type ErrFn func(error)

type FieldLevel

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

func BindStrArr

func BindStrArr(d map[string][]string, fls *[]FieldLevel, s any) (any, []FieldLevel)

func BindStruct

func BindStruct(d map[string]any, fls *[]FieldLevel, s any, parentNS string, parentTag string) (any, []FieldLevel)

func (*FieldLevel) Field

func (fl *FieldLevel) Field() string

func (*FieldLevel) Index

func (fl *FieldLevel) Index() int

func (*FieldLevel) IsValue

func (fl *FieldLevel) IsValue() bool

func (*FieldLevel) Kind

func (fl *FieldLevel) Kind() reflect.Kind

func (*FieldLevel) Namespace

func (fl *FieldLevel) Namespace() string

func (*FieldLevel) NestedTag

func (fl *FieldLevel) NestedTag() string

func (*FieldLevel) Tag

func (fl *FieldLevel) Tag() string

func (*FieldLevel) Type

func (fl *FieldLevel) Type() reflect.Type

func (*FieldLevel) Value

func (fl *FieldLevel) Value() any

type File

type File map[string][]*multipart.FileHeader

func (File) Bind

func (files File) Bind(s any) any

type Form

type Form map[string][]string

func (Form) Add

func (f Form) Add(k, v string)

func (Form) Bind

func (f Form) Bind(s any) (any, []FieldLevel)

func (Form) Del

func (f Form) Del(k string)

func (Form) Get

func (f Form) Get(k string) string

func (Form) Has

func (f Form) Has(k string) bool

func (Form) Set

func (f Form) Set(k, v string)

type Handler

type Handler = func(*Context)
type Header map[string][]string

func (Header) Add

func (h Header) Add(k, v string)

func (Header) Bind

func (h Header) Bind(s any) (any, []FieldLevel)

func (Header) Del

func (h Header) Del(k string)

func (Header) Get

func (h Header) Get(k string) string

func (Header) Has

func (h Header) Has(k string) bool

func (Header) Set

func (h Header) Set(k, v string)

type JSON

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

func (*JSON) WriteData

func (json *JSON) WriteData(statusCode int)

type JSONP

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

func (*JSONP) WriteData

func (jsonp *JSONP) WriteData(statusCode int)

type Map

type Map map[string]any

type Next

type Next = func()

type Param

type Param map[string][]string

func (Param) Add

func (p Param) Add(k, v string)

func (Param) Bind

func (p Param) Bind(s any) (any, []FieldLevel)

func (Param) Del

func (p Param) Del(k string)

func (Param) Get

func (p Param) Get(k string) string

func (Param) Has

func (p Param) Has(k string) bool

func (Param) Set

func (p Param) Set(k, v string)

type Query

type Query map[string][]string

func (Query) Add

func (q Query) Add(k, v string)

func (Query) Bind

func (q Query) Bind(s any) (any, []FieldLevel)

func (Query) Del

func (q Query) Del(k string)

func (Query) Get

func (q Query) Get(k string) string

func (Query) Has

func (q Query) Has(k string) bool

func (Query) Set

func (q Query) Set(k, v string)

type Redirect

type Redirect = func(string)

type Text

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

func (*Text) WriteData

func (text *Text) WriteData(statusCode int)

type WS

type WS struct {
	Connection *websocket.Conn
	Message    WSMessage
	// contains filtered or unexported fields
}

func NewWS

func NewWS(wsConn *websocket.Conn) *WS

func (*WS) CanEstablish

func (ws *WS) CanEstablish(insertedEvents map[string]string) bool

func (*WS) GetConnID

func (ws *WS) GetConnID() string

func (*WS) GetSubprotocol

func (ws *WS) GetSubprotocol() string

func (*WS) GetSubscribedEvents

func (ws *WS) GetSubscribedEvents() []string

func (*WS) SendSelf

func (ws *WS) SendSelf(c *Context, message any) error

Use for return error response to itself connection

func (*WS) SendToConn

func (ws *WS) SendToConn(c *Context, wsConn *websocket.Conn, message string) error

type WSMessage

type WSMessage struct {
	Event   string    `json:"event"`
	Payload WSPayload `json:"payload"`
}

type WSPayload

type WSPayload map[string]any

func (WSPayload) Bind

func (p WSPayload) Bind(s any) (any, []FieldLevel)

Jump to

Keyboard shortcuts

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