Documentation
¶
Index ¶
- Constants
- Variables
- func StatusText(code int) string
- type Config
- func (config *Config) Address() string
- func (config *Config) Build() *Server
- func (config *Config) WithDeployment(deployment string) *Config
- func (config *Config) WithEnableMetric(disableMetric bool) *Config
- func (config *Config) WithEnableSlowQuery(disableSlowQuery bool) *Config
- func (config *Config) WithEnableTrace(disableTrace bool) *Config
- func (config *Config) WithHost(host string) *Config
- func (config *Config) WithMode(mode string) *Config
- func (config *Config) WithPort(port int) *Config
- func (config *Config) WithServiceAddress(serviceAddress string) *Config
- func (config *Config) WithSlowQueryThresholdInMilli(milli int64) *Config
- type EmptyMessage
- type GRPCProxyMessage
- type HTTPError
- type Server
- type WebSocket
- type WebSocketConn
- type WebSocketFunc
- type WebSocketOption
Constants ¶
const ( // StatusContinue ... StatusContinue = 100 // StatusSwitchingProtocols ... StatusSwitchingProtocols = 101 // StatusOK ... StatusOK = 200 // StatusCreated ... StatusCreated = 201 // StatusAccepted ... StatusAccepted = 202 // StatusNonAuthoritativeInfo ... StatusNonAuthoritativeInfo = 203 // StatusNoContent ... StatusNoContent = 204 // StatusResetContent ... StatusResetContent = 205 // StatusPartialContent ... StatusPartialContent = 206 // StatusMultipleChoices ... StatusMultipleChoices = 300 // StatusMovedPermanently ... StatusMovedPermanently = 301 // StatusFound ... StatusFound = 302 // StatusSeeOther ... StatusSeeOther = 303 // StatusNotModified ... StatusNotModified = 304 // StatusUseProxy ... StatusUseProxy = 305 // StatusTemporaryRedirect ... StatusTemporaryRedirect = 307 // StatusBadRequest ... StatusBadRequest = 400 StatusUnauthorized = 401 // StatusPaymentRequired ... StatusPaymentRequired = 402 // StatusForbidden ... StatusForbidden = 403 // StatusNotFound ... StatusNotFound = 404 // StatusMethodNotAllowed ... StatusMethodNotAllowed = 405 // StatusNotAcceptable ... StatusNotAcceptable = 406 // StatusProxyAuthRequired ... StatusProxyAuthRequired = 407 // StatusRequestTimeout ... StatusRequestTimeout = 408 // StatusConflict ... StatusConflict = 409 // StatusGone ... StatusGone = 410 // StatusLengthRequired ... StatusLengthRequired = 411 // StatusPreconditionFailed ... StatusPreconditionFailed = 412 // StatusRequestEntityTooLarge ... StatusRequestEntityTooLarge = 413 // StatusRequestURITooLong ... StatusRequestURITooLong = 414 // StatusUnsupportedMediaType ... StatusUnsupportedMediaType = 415 // StatusRequestedRangeNotSatisfiable ... StatusRequestedRangeNotSatisfiable = 416 // StatusExpectationFailed ... StatusExpectationFailed = 417 // StatusTeapot ... StatusTeapot = 418 // StatusPreconditionRequired ... StatusPreconditionRequired = 428 // StatusTooManyRequests ... StatusTooManyRequests = 429 // StatusRequestHeaderFieldsTooLarge ... StatusRequestHeaderFieldsTooLarge = 431 StatusUnavailableForLegalReasons = 451 // StatusInternalServerError ... StatusInternalServerError = 500 // StatusNotImplemented ... StatusNotImplemented = 501 // StatusBadGateway ... StatusBadGateway = 502 StatusServiceUnavailable = 503 // StatusGatewayTimeout ... StatusGatewayTimeout = 504 // StatusHTTPVersionNotSupported ... StatusHTTPVersionNotSupported = 505 // StatusNetworkAuthenticationRequired ... StatusNetworkAuthenticationRequired = 511 // StatusErrorCodeReturned 针对微服务定制的错误返回status StatusErrorCodeReturned = 800 )
StatusContinue ...
const ( // HeaderAcceptEncoding ... HeaderAcceptEncoding = "Accept-Encoding" // HeaderContentType ... HeaderContentType = "Content-Type" // HRPC Errord HeaderHRPCErr = "HRPC-Errord" )
HeaderAcceptEncoding Headers
const ( // MIMEApplicationJSON ... MIMEApplicationJSON = "application/json" // MIMEApplicationJSONCharsetUTF8 ... MIMEApplicationJSONCharsetUTF8 = MIMEApplicationJSON + "; " + charsetUTF8 // MIMEApplicationProtobuf ... MIMEApplicationProtobuf = "application/protobuf" )
MIMEApplicationJSON MIME types
const ModName = "server.gin"
ModName ..
Variables ¶
var ( // ErrGRPCResponseValid ... ErrGRPCResponseValid = status.Errorf(codes.Internal, "response valid") // ErrGRPCInvokeLen ... ErrGRPCInvokeLen = status.Errorf(codes.Internal, "invoke request without len 2 res") )
ErrGRPCResponseValid ...
var ErrNotFound = HTTPError{ Code: StatusNotFound, Message: "not found", }
ErrNotFound defines StatusNotFound error.
Functions ¶
func StatusText ¶
StatusText returns a text for the HTTP status code. It returns the empty string if the code is unknown.
Types ¶
type Config ¶
type Config struct {
Host string
Port int
Deployment string
Mode string
EnableMetric bool
EnableTrace bool
EnableSlowQuery bool
ServiceAddress string // ServiceAddress service address in registry info, default to 'Host:Port'
SlowQueryThresholdInMill int64
}
Config HTTP config
func (*Config) WithDeployment ¶
WithDeployment ...
func (*Config) WithEnableMetric ¶ added in v3.8.21
WithEnableMetric ...
func (*Config) WithEnableSlowQuery ¶ added in v3.8.21
WithEnableSlowQuery ...
func (*Config) WithEnableTrace ¶ added in v3.8.21
WithEnableTrace ...
func (*Config) WithServiceAddress ¶
WithServiceAddress ...
func (*Config) WithSlowQueryThresholdInMilli ¶
WithSlowQueryThresholdInMilli WithPort ...
type GRPCProxyMessage ¶
type GRPCProxyMessage struct {
Error int `protobuf:"varint,1,opt,name=error" json:"error"`
Message string `protobuf:"bytes,2,opt,name=msg" json:"msg"`
Data proto.Message `protobuf:"bytes,3,opt,name=data" json:"data"`
}
GRPCProxyMessage ...
func (*GRPCProxyMessage) MarshalJSONPB ¶
func (m *GRPCProxyMessage) MarshalJSONPB(jsb *jsonpb.MarshalOptions) ([]byte, error)
MarshalJSONPB ...
type HTTPError ¶
HTTPError wraps handler error.
func NewHTTPError ¶
NewHTTPError constructs a new HTTPError instance.
type Server ¶
Server ...
func (*Server) GracefulStop ¶
GracefulStop implements server.Server interface it will stop gin server gracefully
func (*Server) Info ¶
func (s *Server) Info() *server.ServiceInfo
Info returns server info, used by governor and consumer balancer
type WebSocket ¶
type WebSocket struct {
Pattern string
Handler WebSocketFunc
*websocket.Upgrader
Header http.Header
}
WebSocket ..
func WebSocketOptions ¶
func WebSocketOptions(pattern string, handler WebSocketFunc, opts ...WebSocketOption) *WebSocket
WebSocketOptions ..
type WebSocketConn ¶
type WebSocketConn interface {
Subprotocol() string
Close() error
LocalAddr() net.Addr
RemoteAddr() net.Addr
WriteControl(messageType int, data []byte, deadline time.Time) error
NextWriter(messageType int) (io.WriteCloser, error)
WritePreparedMessage(pm *websocket.PreparedMessage) error
WriteMessage(messageType int, data []byte) error
SetWriteDeadline(t time.Time) error
NextReader() (messageType int, r io.Reader, err error)
ReadMessage() (messageType int, p []byte, err error)
SetReadDeadline(t time.Time) error
SetReadLimit(limit int64)
CloseHandler() func(code int, text string) error
SetCloseHandler(h func(code int, text string) error)
PingHandler() func(appData string) error
SetPingHandler(h func(appData string) error)
PongHandler() func(appData string) error
SetPongHandler(h func(appData string) error)
UnderlyingConn() net.Conn
EnableWriteCompression(enable bool)
SetCompressionLevel(level int) error
}
WebSocketConn websocket conn, see websocket.Conn