xgin

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2020 License: Apache-2.0 Imports: 30 Imported by: 9

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

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
	Mode          string
	DisableMetric bool
	DisableTrace  bool

	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 TODO(gorexlv): implements government protocol with juno

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

Jump to

Keyboard shortcuts

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