Documentation
¶
Index ¶
- Constants
- type BaseEndpoint
- func (endpoint *BaseEndpoint) After(http.ResponseWriter, *http.Request) *HttpError
- func (endpoint *BaseEndpoint) Before(http.ResponseWriter, *http.Request) *HttpError
- func (endpoint *BaseEndpoint) ExplicitMiddlewares() []string
- func (endpoint *BaseEndpoint) GetRoute() string
- func (endpoint *BaseEndpoint) Handler(http.ResponseWriter, *http.Request) *HttpError
- func (endpoint *BaseEndpoint) Methods() []string
- func (endpoint *BaseEndpoint) OnError(err *HttpError, w http.ResponseWriter, r *http.Request)
- type BaseWebsocket
- func (socket *BaseWebsocket) CheckOrigin(r *http.Request) bool
- func (socket *BaseWebsocket) ClientConnect(client WebsocketClient) fail.CustomError
- func (socket *BaseWebsocket) EnableCompression() bool
- func (socket *BaseWebsocket) GetRoute() string
- func (socket *BaseWebsocket) Handle(data []byte, client WebsocketClient) fail.CustomError
- func (socket *BaseWebsocket) Handshake(w http.ResponseWriter, r *http.Request) *HttpError
- func (socket *BaseWebsocket) ReadBufferSize() int
- func (socket *BaseWebsocket) WriteBufferSize() int
- type ClientPool
- type Config
- type CorsConfig
- type Endpoint
- type HttpError
- type Middleware
- type RequestUtils
- type ResponseUtils
- type Runner
- type Websocket
- type WebsocketClient
Constants ¶
View Source
const ExecuteNoMiddleware = "###NoMiddleware###"
View Source
const TraceIDKey contextKey = "trace_id"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseEndpoint ¶
type BaseEndpoint struct {
RequestUtils RequestUtils
ResponseUtils ResponseUtils
// contains filtered or unexported fields
}
func NewBaseEndpoint ¶
func NewBaseEndpoint() *BaseEndpoint
func (*BaseEndpoint) After ¶
func (endpoint *BaseEndpoint) After(http.ResponseWriter, *http.Request) *HttpError
func (*BaseEndpoint) Before ¶
func (endpoint *BaseEndpoint) Before(http.ResponseWriter, *http.Request) *HttpError
func (*BaseEndpoint) ExplicitMiddlewares ¶
func (endpoint *BaseEndpoint) ExplicitMiddlewares() []string
func (*BaseEndpoint) GetRoute ¶
func (endpoint *BaseEndpoint) GetRoute() string
func (*BaseEndpoint) Handler ¶
func (endpoint *BaseEndpoint) Handler(http.ResponseWriter, *http.Request) *HttpError
func (*BaseEndpoint) Methods ¶
func (endpoint *BaseEndpoint) Methods() []string
func (*BaseEndpoint) OnError ¶
func (endpoint *BaseEndpoint) OnError(err *HttpError, w http.ResponseWriter, r *http.Request)
type BaseWebsocket ¶
type BaseWebsocket struct {
Pool ClientPool
}
func NewBaseWebsocket ¶
func NewBaseWebsocket() *BaseWebsocket
func (*BaseWebsocket) CheckOrigin ¶
func (socket *BaseWebsocket) CheckOrigin(r *http.Request) bool
func (*BaseWebsocket) ClientConnect ¶
func (socket *BaseWebsocket) ClientConnect(client WebsocketClient) fail.CustomError
func (*BaseWebsocket) EnableCompression ¶
func (socket *BaseWebsocket) EnableCompression() bool
func (*BaseWebsocket) GetRoute ¶
func (socket *BaseWebsocket) GetRoute() string
func (*BaseWebsocket) Handle ¶
func (socket *BaseWebsocket) Handle(data []byte, client WebsocketClient) fail.CustomError
func (*BaseWebsocket) Handshake ¶
func (socket *BaseWebsocket) Handshake(w http.ResponseWriter, r *http.Request) *HttpError
func (*BaseWebsocket) ReadBufferSize ¶
func (socket *BaseWebsocket) ReadBufferSize() int
func (*BaseWebsocket) WriteBufferSize ¶
func (socket *BaseWebsocket) WriteBufferSize() int
type ClientPool ¶
type ClientPool interface {
Register(client WebsocketClient)
Get(filter func(client WebsocketClient) bool) []WebsocketClient
}
type Config ¶
type Config struct {
ListenAddress string
Middlewares []Middleware
Endpoints map[string][]Endpoint
StaticFiles http.FileSystem
CrossOriginRequests CorsConfig
Websockets []Websocket
}
type CorsConfig ¶
type Endpoint ¶
type Endpoint interface {
Methods() []string
GetRoute() string
ExplicitMiddlewares() []string
Handler(http.ResponseWriter, *http.Request) *HttpError
Before(http.ResponseWriter, *http.Request) *HttpError
After(http.ResponseWriter, *http.Request) *HttpError
OnError(err *HttpError, w http.ResponseWriter, r *http.Request)
}
type HttpError ¶
func NewHttpError ¶
func NewHttpError(err fail.CustomError, status int) *HttpError
type Middleware ¶
type RequestUtils ¶
type RequestUtils interface {
GetBearerToken(r *http.Request) string
GetClientIP(r *http.Request) string
GetPreferredLanguage(r *http.Request, supportedLanguages []string) string
GetTraceID(r *http.Request) string
GetHeaderValue(r *http.Request, name string) string
GetUrlParam(r *http.Request, name string) string
GetUrlParamInt(r *http.Request, name string, defaultValue int) int
GetUrlParamBool(r *http.Request, name string, defaultValue bool) bool
GetUrlParamFloat32(r *http.Request, name string, defaultValue float32) float32
GetUrlParamFloat64(r *http.Request, name string, defaultValue float64) float64
GetFormData(r *http.Request, name string) (string, fail.CustomError)
GetRawBody(r *http.Request) ([]byte, fail.CustomError)
GetJsonBody(r *http.Request, target any) fail.CustomError
}
type ResponseUtils ¶
type ResponseUtils interface {
WritePlainText(status int, data string, w http.ResponseWriter) *HttpError
WriteBytes(status int, data []byte, w http.ResponseWriter) *HttpError
WriteJson(status int, data any, w http.ResponseWriter) *HttpError
WriteEmpty(status int, w http.ResponseWriter) *HttpError
WriteError(err *HttpError, w http.ResponseWriter)
}
type Runner ¶
type Runner interface {
Start(config Config) fail.CustomError
}
type Websocket ¶
type Websocket interface {
GetRoute() string
Handshake(w http.ResponseWriter, r *http.Request) *HttpError
ClientConnect(client WebsocketClient) fail.CustomError
CheckOrigin(r *http.Request) bool
ReadBufferSize() int
WriteBufferSize() int
EnableCompression() bool
Handle(data []byte, client WebsocketClient) fail.CustomError
}
type WebsocketClient ¶
type WebsocketClient interface {
GetId() string
Send(data []byte) fail.CustomError
SendJson(data any) fail.CustomError
Close() fail.CustomError
Closed() *fail.ErrorList
OnClose(toDo func() fail.CustomError)
}
Click to show internal directories.
Click to hide internal directories.