xgin

package
v0.0.0-...-b937326 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2020 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
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 ...
	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 ...
	StatusUnavailableForLegalReasons = 451
	// StatusInternalServerError ...
	StatusInternalServerError = 500
	// StatusNotImplemented ...
	StatusNotImplemented = 501
	// StatusBadGateway ...
	StatusBadGateway = 502
	// StatusServiceUnavailable ...
	StatusServiceUnavailable = 503
	// StatusGatewayTimeout ...
	StatusGatewayTimeout = 504
	// StatusHTTPVersionNotSupported ...
	StatusHTTPVersionNotSupported = 505
	// StatusNetworkAuthenticationRequired ...
	StatusNetworkAuthenticationRequired = 511

	// StatusErrorCodeReturned 针对微服务定制的错误返回status
	StatusErrorCodeReturned = 800
)
View Source
const (
	// HeaderAcceptEncoding ...
	HeaderAcceptEncoding = "Accept-Encoding"
	// HeaderContentType ...
	HeaderContentType = "Content-Type"
	// HRPC Errord
	HeaderHRPCErr = "HRPC-Errord"
)

Headers

View Source
const (
	// MIMEApplicationJSON ...
	MIMEApplicationJSON = "application/json"
	// MIMEApplicationJSONCharsetUTF8 ...
	MIMEApplicationJSONCharsetUTF8 = MIMEApplicationJSON + "; " + charsetUTF8
	// MIMEApplicationProtobuf ...
	MIMEApplicationProtobuf = "application/protobuf"
)

MIME types

View Source
const ModName = "server.gin"

ModName ..

Variables

View Source
var (
	// ErrGRPCResponseValid ...
	ErrGRPCResponseValid = grpc.Errorf(codes.Internal, "response valid")
	// ErrGRPCInvokeLen ...
	ErrGRPCInvokeLen = grpc.Errorf(codes.Internal, "invoke request without len 2 res")
)
View Source
var ErrNotFound = HTTPError{
	Code:    StatusNotFound,
	Message: "not found",
}

ErrNotFound defines StatusNotFound error.

Functions

func StatusText

func StatusText(code int) string

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
	DisableMetric bool
	DisableTrace  bool
	// ServiceAddress service address in registry info, default to 'Host:Port'
	ServiceAddress string

	SlowQueryThresholdInMilli int64
	// contains filtered or unexported fields
}

Config HTTP config

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig ...

func RawConfig

func RawConfig(key string) *Config

RawConfig ...

func StdConfig

func StdConfig(name string) *Config

StdConfig Jupiter Standard HTTP Server config

func (*Config) Address

func (config *Config) Address() string

Address ...

func (*Config) Build

func (config *Config) Build() *Server

Build create server instance, then initialize it with necessary interceptor

func (*Config) WithHost

func (config *Config) WithHost(host string) *Config

WithHost ...

func (*Config) WithLogger

func (config *Config) WithLogger(logger *xlog.Logger) *Config

WithLogger ...

func (*Config) WithPort

func (config *Config) WithPort(port int) *Config

WithPort ...

type EmptyMessage

type EmptyMessage struct{}

EmptyMessage ...

func (*EmptyMessage) ProtoMessage

func (*EmptyMessage) ProtoMessage()

ProtoMessage ...

func (*EmptyMessage) Reset

func (m *EmptyMessage) Reset()

Reset ...

func (*EmptyMessage) String

func (m *EmptyMessage) String() string

String ...

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.Marshaler) ([]byte, error)

MarshalJSONPB ...

func (*GRPCProxyMessage) ProtoMessage

func (*GRPCProxyMessage) ProtoMessage()

ProtoMessage ...

func (*GRPCProxyMessage) Reset

func (m *GRPCProxyMessage) Reset()

Reset ...

func (*GRPCProxyMessage) String

func (m *GRPCProxyMessage) String() string

String ...

type HTTPError

type HTTPError struct {
	Code    int
	Message string
}

HTTPError wraps handler error.

func NewHTTPError

func NewHTTPError(code int, msg ...string) *HTTPError

NewHTTPError constructs a new HTTPError instance.

func (HTTPError) Error

func (e HTTPError) Error() string

Errord return error message.

type Server

type Server struct {
	*gin.Engine
	Server *http.Server
	// contains filtered or unexported fields
}

Server ...

func (*Server) GracefulStop

func (s *Server) GracefulStop(ctx context.Context) error

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

func (*Server) Serve

func (s *Server) Serve() error

Serve implements server.Server interface.

func (*Server) Stop

func (s *Server) Stop() error

Stop implements server.Server interface it will terminate gin server immediately

func (*Server) Upgrade

func (s *Server) Upgrade(ws *WebSocket) gin.IRoutes

Upgrade protocol to WebSocket

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 ..

func (*WebSocket) Upgrade

func (ws *WebSocket) Upgrade(w http.ResponseWriter, r *http.Request)

Upgrade get upgrage request

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

type WebSocketFunc

type WebSocketFunc func(WebSocketConn, error)

WebSocketFunc ..

type WebSocketOption

type WebSocketOption func(*WebSocket)

WebSocketOption ..

Jump to

Keyboard shortcuts

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