handler

package
v0.0.0-...-25d1615 Latest Latest
Warning

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

Go to latest
Published: May 18, 2023 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const SENTRY_CHANNEL_TIMEOUT = 50

Variables

This section is empty.

Functions

func CaptureErrorToSentry

func CaptureErrorToSentry(ctx *Context, err string)

CapturePanicToSentry will collect error info then send to sentry

func CheckArgs

func CheckArgs(r RestResourceInterface, ctx *Context)

CheckArgs: check whether param is right

func HandleStaticFile

func HandleStaticFile(path string, response *Response) bool

func RecoverFromCronTaskPanic

func RecoverFromCronTaskPanic(ctx context.Context)

RecoverFromCronTaskPanic crontask的recover

func RecoverPanic

func RecoverPanic(ctx *Context)

Types

type Context

type Context struct {
	Request  *Request
	Response *Response
	Data     map[string]interface{}
	Events   []map[string]interface{}
}

func NewContext

func NewContext() *Context

NewContext return the Context with Input and Output

func (*Context) AddEvent

func (ctx *Context) AddEvent(eventData map[string]interface{})

func (*Context) EmitAll

func (ctx *Context) EmitAll()

func (*Context) Get

func (ctx *Context) Get(key string) interface{}

func (*Context) GetBusinessContext

func (ctx *Context) GetBusinessContext() context.Context

func (*Context) Reset

func (ctx *Context) Reset(rw http.ResponseWriter, r *http.Request)

Reset init Context

func (*Context) Set

func (ctx *Context) Set(key string, value interface{})

func (*Context) SetBusinessContext

func (ctx *Context) SetBusinessContext(value interface{})

func (*Context) SetJSON

func (ctx *Context) SetJSON(key string, value map[string]interface{})

func (*Context) SetJSONArray

func (ctx *Context) SetJSONArray(key string, value []interface{})

type FillOption

type FillOption = map[string]bool

type Map

type Map = map[string]interface{}

type Middleware

type Middleware struct {
}

func (*Middleware) ProcessRequest

func (m *Middleware) ProcessRequest(ctx *Context)

func (*Middleware) ProcessResponse

func (m *Middleware) ProcessResponse(ctx *Context)

type MiddlewareInterface

type MiddlewareInterface interface {
	ProcessRequest(ctx *Context)
	ProcessResponse(ctx *Context)
}

type Request

type Request struct {
	HttpRequest    *http.Request
	Name2JSON      map[string]map[string]interface{}
	Name2JSONArray map[string][]interface{}
	Filters        map[string]interface{}
}

Request

func (*Request) GetBool

func (r *Request) GetBool(key string, def ...bool) (bool, error)

GetBool returns input value as bool or the default value while it's present and input is blank.

func (*Request) GetBoolOptions

func (r *Request) GetBoolOptions(key string) map[string]bool

func (*Request) GetFile

func (r *Request) GetFile(key string) (multipart.File, *multipart.FileHeader, error)

func (*Request) GetFillOptions

func (r *Request) GetFillOptions(key string) FillOption

func (*Request) GetFilters

func (r *Request) GetFilters() map[string]interface{}

func (*Request) GetFloat

func (r *Request) GetFloat(key string, def ...float64) (float64, error)

GetFloat returns input value as float64 or the default value while it's present and input is blank.

func (*Request) GetInt

func (r *Request) GetInt(key string, def ...int) (int, error)

GetInt returns input as an int or the default value while it's present and input is blank

func (*Request) GetInt16

func (r *Request) GetInt16(key string, def ...int16) (int16, error)

GetInt16 returns input as an int16 or the default value while it's present and input is blank

func (*Request) GetInt32

func (r *Request) GetInt32(key string, def ...int32) (int32, error)

GetInt32 returns input as an int32 or the default value while it's present and input is blank

func (*Request) GetInt64

func (r *Request) GetInt64(key string, def ...int64) (int64, error)

GetInt64 returns input value as int64 or the default value while it's present and input is blank.

func (*Request) GetInt8

func (r *Request) GetInt8(key string, def ...int8) (int8, error)

GetInt8 return input as an int8 or the default value while it's present and input is blank

func (*Request) GetIntArray

func (r *Request) GetIntArray(key string) []int

func (*Request) GetJSON

func (r *Request) GetJSON(key string) map[string]interface{}

GetJSONArray 与key对应的返回json map数据

func (*Request) GetJSONArray

func (r *Request) GetJSONArray(key string) []interface{}

GetJSONArray 与key对应的返回json array数据

func (*Request) GetOrmFilters

func (r *Request) GetOrmFilters() map[string]interface{}

func (*Request) GetPageInfo

func (r *Request) GetPageInfo() *paginate.PageInfo

func (*Request) GetString

func (r *Request) GetString(key string, def ...string) string

func (*Request) GetStringArray

func (r *Request) GetStringArray(key string) []string

func (*Request) GetUint16

func (r *Request) GetUint16(key string, def ...uint16) (uint16, error)

GetUint16 returns input as an uint16 or the default value while it's present and input is blank

func (*Request) GetUint32

func (r *Request) GetUint32(key string, def ...uint32) (uint32, error)

GetUint32 returns input as an uint32 or the default value while it's present and input is blank

func (*Request) GetUint64

func (r *Request) GetUint64(key string, def ...uint64) (uint64, error)

GetUint64 returns input value as uint64 or the default value while it's present and input is blank.

func (*Request) GetUint8

func (r *Request) GetUint8(key string, def ...uint8) (uint8, error)

GetUint8 return input as an uint8 or the default value while it's present and input is blank

func (*Request) Header

func (r *Request) Header(key string) string

func (*Request) Input

func (r *Request) Input() url.Values

func (*Request) Method

func (r *Request) Method() string

func (*Request) Query

func (r *Request) Query(key string) string

Query returns input data item string by a given string.

func (*Request) RawMethod

func (r *Request) RawMethod() string

func (*Request) Reset

func (r *Request) Reset(request *http.Request)

func (*Request) SetFilter

func (r *Request) SetFilter(key string, value interface{})

func (*Request) SetFilters

func (r *Request) SetFilters(filters map[string]interface{})

func (*Request) SetJSON

func (r *Request) SetJSON(key string, value map[string]interface{})

func (*Request) SetJSONArray

func (r *Request) SetJSONArray(key string, value []interface{})

func (*Request) URL

func (r *Request) URL() string

URL returns request url path (without query string, fragment).

type Response

type Response struct {
	ResponseWriter http.ResponseWriter
	Started        bool
	Status         int
	ContentLength  int
	ErrCode        string
	ErrMsg         string
}

Response is a wrapper for the http.ResponseWriter started set to true if response was written to then don't execute other handler

func (*Response) Body

func (r *Response) Body(content []byte) error

func (*Response) CloseNotify

func (r *Response) CloseNotify() <-chan bool

CloseNotify http.CloseNotifier

func (*Response) Content

func (r *Response) Content(content []byte, contentType string) error

func (*Response) Error

func (r *Response) Error(errCode string, errMsg string)

func (*Response) ErrorWithCode

func (r *Response) ErrorWithCode(code int, errCode string, errMsg string, innerErrMsg string)

func (*Response) Flush

func (r *Response) Flush()

Flush http.Flusher

func (*Response) Header

func (r *Response) Header(key string, value string)

func (*Response) Hijack

func (r *Response) Hijack() (net.Conn, *bufio.ReadWriter, error)

Hijack hijacker for http

func (*Response) JSON

func (r *Response) JSON(data interface{})

func (*Response) JSONWithOption

func (r *Response) JSONWithOption(data interface{}, hasIndent bool, coding bool) error

func (*Response) Reset

func (r *Response) Reset(rw http.ResponseWriter)

func (*Response) Write

func (r *Response) Write(p []byte) (int, error)

Write writes the data to the connection as part of an HTTP reply, and sets `started` to true. started means the response has sent out.

func (*Response) WriteHeader

func (r *Response) WriteHeader(code int)

WriteHeader sends an HTTP response header with status code, and sets `started` to true.

type RestResource

type RestResource struct {
	Ctx *context.Context
}

RestResource 扩展eel.Controller, 作为rest中各个资源的基类

func (*RestResource) Delete

func (r *RestResource) Delete(ctx *Context)

Delete adds a request function to handle DELETE request.

func (*RestResource) EnableHTMLResource

func (r *RestResource) EnableHTMLResource() bool

EnableHTMLResource 是否开启html资源

func (*RestResource) Get

func (r *RestResource) Get(ctx *Context)

Get adds a request function to handle GET request.

func (*RestResource) GetParameters

func (r *RestResource) GetParameters() map[string][]string

Parameters 获取需要检查的参数

func (*RestResource) Head

func (r *RestResource) Head(ctx *Context)

Head adds a request function to handle HEAD request.

func (*RestResource) Options

func (r *RestResource) Options(ctx *Context)

Options adds a request function to handle OPTIONS request.

func (*RestResource) Patch

func (r *RestResource) Patch(ctx *Context)

Patch adds a request function to handle PATCH request.

func (*RestResource) Post

func (r *RestResource) Post(ctx *Context)

Post adds a request function to handle POST request.

func (*RestResource) Prepare

func (r *RestResource) Prepare(ctx *Context)

prepare for request handling

func (*RestResource) Put

func (r *RestResource) Put(ctx *Context)

Put adds a request function to handle PUT request.

func (*RestResource) Resource

func (r *RestResource) Resource() string

func (*RestResource) SkipAuthCheck

func (r *RestResource) SkipAuthCheck() bool

type RestResourceInterface

type RestResourceInterface interface {
	//Init(ct *handler.Context, controllerName, actionName string, app interface{})
	Prepare(ctx *Context)
	Get(ctx *Context)
	Post(ctx *Context)
	Delete(ctx *Context)
	Put(ctx *Context)
	//Finish(ctx *Context)
	Resource() string
	//EnableHTMLResource() bool
	GetParameters() map[string][]string
	SkipAuthCheck() bool
}

type RestResponse

type RestResponse struct {
	Code        int32       `json:"code"`
	Data        interface{} `json:"data"`
	ErrCode     string      `json:"errCode"`
	ErrMsg      string      `json:"errMsg"`
	InnerErrMsg string      `json:"innerErrMsg"`
}

func MakeErrorResponse

func MakeErrorResponse(code int32, errCode string, errMsg string, innerErrMsgs ...string) *RestResponse

func MakeResponse

func MakeResponse(data interface{}) *RestResponse

Directories

Path Synopsis
rest
op

Jump to

Keyboard shortcuts

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