grpc

package
v1.2.115 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ListenAndServe

func ListenAndServe(addr string, handler http.Handler, opts ...GatewayOption) error

ListenAndServe listens on the TCP network address addr and then calls Serve with handler to handle requests on incoming connections. Accepted connections are configured to enable TCP keep-alives.

The handler is typically nil, in which case the DefaultServeMux is used.

ListenAndServe always returns a non-nil error.

func ListenAndServeTLS

func ListenAndServeTLS(addr, certFile, keyFile string, handler http.Handler, opts ...GatewayOption) error

ListenAndServeTLS acts identically to ListenAndServe, except that it expects HTTPS connections. Additionally, files containing a certificate and matching private key for the server must be provided. If the certificate is signed by a certificate authority, the certFile should be the concatenation of the server's certificate, any intermediates, and the CA's certificate.

func MessageProducerWithForward

func MessageProducerWithForward(ctx context.Context, format string, level logrus.Level, code codes.Code, err error, fields logrus.Fields)

MessageProducerWithForward fill "X-Forwarded-For" and "X-Forwarded-Host" to record http callers

func Serve

func Serve(l net.Listener, handler http.Handler, opts ...GatewayOption) error

Serve accepts incoming HTTP connections on the listener l, creating a new service goroutine for each. The service goroutines read requests and then call handler to reply to them.

The handler is typically nil, in which case the DefaultServeMux is used.

HTTP/2 support is only enabled if the Listener returns *tls.Conn connections and they were configured with "h2" in the TLS Config.NextProtos.

Serve always returns a non-nil error.

func ServeTLS

func ServeTLS(l net.Listener, handler http.Handler, certFile, keyFile string, opts ...GatewayOption) error

ServeTLS accepts incoming HTTPS connections on the listener l, creating a new service goroutine for each. The service goroutines read requests and then call handler to reply to them.

The handler is typically nil, in which case the DefaultServeMux is used.

Additionally, files containing a certificate and matching private key for the server must be provided. If the certificate is signed by a certificate authority, the certFile should be the concatenation of the server's certificate, any intermediates, and the CA's certificate.

ServeTLS always returns a non-nil error.

Types

type EmptyGatewayOption

type EmptyGatewayOption struct{}

EmptyGatewayOption does not alter the configuration. It can be embedded in another structure to build custom options.

This API is EXPERIMENTAL.

type ForwardResponseMessageHandler

type ForwardResponseMessageHandler interface {
	ForwardResponseMessage(ctx context.Context, mux *runtime.ServeMux, marshaler runtime.Marshaler, w http.ResponseWriter, req *http.Request, resp proto.Message, opts ...func(context.Context, http.ResponseWriter, proto.Message) error)
}

type ForwardResponseMessageHandlerFunc

type ForwardResponseMessageHandlerFunc func(ctx context.Context, mux *runtime.ServeMux, marshaler runtime.Marshaler, w http.ResponseWriter, req *http.Request, resp proto.Message, opts ...func(context.Context, http.ResponseWriter, proto.Message) error)

func (ForwardResponseMessageHandlerFunc) ForwardResponseMessage

type GRPCHandler

type GRPCHandler interface {
	Register(srv *grpc.Server)
}

type GRPCHandlerFunc

type GRPCHandlerFunc func(srv *grpc.Server)

func (GRPCHandlerFunc) Register

func (f GRPCHandlerFunc) Register(srv *grpc.Server)

type Gateway

type Gateway struct {
	http.Server

	Handler http.Handler
	// contains filtered or unexported fields
}

func NewGateway

func NewGateway(addr string, opts ...GatewayOption) *Gateway

func NewGatewayTLS

func NewGatewayTLS(addr string, tlsConfig *tls.Config, opts ...GatewayOption) *Gateway

TLSConfig optionally provides a TLS configuration for use by ServeTLS and ListenAndServeTLS. Note that this value is cloned by ServeTLS and ListenAndServeTLS, so it's not possible to modify the configuration with methods like tls.Config.SetSessionTicketKeys. To use SetSessionTicketKeys, use Server.Serve with a TLS Listener instead.

func (*Gateway) ApplyOptions

func (o *Gateway) ApplyOptions(options ...GatewayOption) *Gateway

ApplyOptions call apply() for all options one by one

func (*Gateway) ListenAndServe

func (gateway *Gateway) ListenAndServe() error

ListenAndServe listens on the TCP network address srv.Addr and then calls Serve to handle requests on incoming connections. Accepted connections are configured to enable TCP keep-alives.

If srv.Addr is blank, ":http" is used.

ListenAndServe always returns a non-nil error. After Shutdown or Close, the returned error is ErrServerClosed.

func (*Gateway) ListenAndServeTLS

func (gateway *Gateway) ListenAndServeTLS(certFile, keyFile string) error

ListenAndServeTLS listens on the TCP network address srv.Addr and then calls ServeTLS to handle requests on incoming TLS connections. Accepted connections are configured to enable TCP keep-alives.

Filenames containing a certificate and matching private key for the server must be provided if neither the Server's TLSConfig.Certificates nor TLSConfig.GetCertificate are populated. If the certificate is signed by a certificate authority, the certFile should be the concatenation of the server's certificate, any intermediates, and the CA's certificate.

If srv.Addr is blank, ":https" is used.

ListenAndServeTLS always returns a non-nil error. After Shutdown or Close, the returned error is ErrServerClosed.

func (*Gateway) RegisterGRPCFunc

func (gateway *Gateway) RegisterGRPCFunc(handler func(srv *grpc.Server))

RegisterGRPCFunc registers grpc handler of the gateway

func (*Gateway) RegisterGRPCHandler

func (gateway *Gateway) RegisterGRPCHandler(handler GRPCHandler)

RegisterGRPCHandler registers grpc handler of the gateway

func (*Gateway) RegisterHTTPFunc

func (gateway *Gateway) RegisterHTTPFunc(ctx context.Context, handler func(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) error) error

RegisterHTTPFunc registers http handler of the gateway

func (*Gateway) RegisterHTTPHandler

func (gateway *Gateway) RegisterHTTPHandler(ctx context.Context, handler HTTPHandler) error

RegisterHTTPHandler registers http handler of the gateway

func (*Gateway) Serve

func (gateway *Gateway) Serve(l net.Listener) error

func (*Gateway) ServeTLS

func (gateway *Gateway) ServeTLS(l net.Listener, certFile, keyFile string) error

ServeTLS accepts incoming connections on the Listener l, creating a new service goroutine for each. The service goroutines perform TLS setup and then read requests, calling srv.Handler to reply to them.

Files containing a certificate and matching private key for the server must be provided if neither the Server's TLSConfig.Certificates nor TLSConfig.GetCertificate are populated. If the certificate is signed by a certificate authority, the certFile should be the concatenation of the server's certificate, any intermediates, and the CA's certificate.

ServeTLS always returns a non-nil error. After Shutdown or Close, the returned error is ErrServerClosed.

type GatewayOption

type GatewayOption interface {
	// contains filtered or unexported methods
}

A GatewayOption sets options.

func WithDefaultMarsherOption

func WithDefaultMarsherOption() []GatewayOption

func WithFastMode

func WithFastMode(fastMode bool) GatewayOption

func WithGateway added in v1.2.100

func WithGateway(v Gateway) GatewayOption

WithGateway sets Gateway.

func WithGatewayGrpcServer added in v1.2.100

func WithGatewayGrpcServer(v *grpc.Server) GatewayOption

WithGatewayGrpcServer sets grpcServer in Gateway. runtime

func WithGatewayHandler added in v1.2.100

func WithGatewayHandler(v http.Handler) GatewayOption

WithGatewayHandler sets Handler in Gateway.

func WithGatewayHttpMuxToGrpc added in v1.2.100

func WithGatewayHttpMuxToGrpc(v *runtime.ServeMux) GatewayOption

WithGatewayHttpMuxToGrpc sets httpMuxToGrpc in Gateway.

func WithGatewayOnce added in v1.2.100

func WithGatewayOnce(v sync.Once) GatewayOption

WithGatewayOnce sets once in Gateway.

func WithGatewayOpt added in v1.2.100

func WithGatewayOpt(v gatewayOption) GatewayOption

WithGatewayOpt sets opt in Gateway. options

func WithGrpcDialOption

func WithGrpcDialOption(opts ...grpc.DialOption) GatewayOption

func WithGrpcServeMuxOption

func WithGrpcServeMuxOption(opts ...runtime.ServeMuxOption) GatewayOption

func WithGrpcServerOption

func WithGrpcServerOption(opts ...grpc.ServerOption) GatewayOption

func WithGrpcStreamServerChain

func WithGrpcStreamServerChain(interceptors ...grpc.StreamServerInterceptor) GatewayOption

func WithGrpcUnaryServerChain

func WithGrpcUnaryServerChain(interceptors ...grpc.UnaryServerInterceptor) GatewayOption

func WithHTTPErrorHandler

func WithHTTPErrorHandler(fn HTTPErrorHandler) GatewayOption

WithHTTPErrorHandler replies to the request with the error. You can set a custom function to this variable to customize error format.

func WithHttpHandlerInterceptor

func WithHttpHandlerInterceptor(opts ...http_.HandlerInterceptorChainOption) GatewayOption

func WithHttpRewriter

func WithHttpRewriter(rewriter func(w http.ResponseWriter, r *http.Request) error) GatewayOption

func WithLogrusLogger

func WithLogrusLogger(logger *logrus.Logger) GatewayOption

func WithMarshalerOption

func WithMarshalerOption(mime string, marshaler runtime.Marshaler) GatewayOption

type GatewayOptionFunc

type GatewayOptionFunc func(*Gateway)

GatewayOptionFunc wraps a function that modifies Gateway into an implementation of the GatewayOption interface.

type HTTPErrorHandler

type HTTPErrorHandler interface {
	HandleHTTPError(ctx context.Context, mux *runtime.ServeMux, marshaler runtime.Marshaler, w http.ResponseWriter, r *http.Request, err error)
}

type HTTPErrorHandlerFunc

type HTTPErrorHandlerFunc func(ctx context.Context, mux *runtime.ServeMux, marshaler runtime.Marshaler, w http.ResponseWriter, r *http.Request, err error)

func (HTTPErrorHandlerFunc) HandleHTTPError

func (f HTTPErrorHandlerFunc) HandleHTTPError(ctx context.Context, mux *runtime.ServeMux, marshaler runtime.Marshaler, w http.ResponseWriter, r *http.Request, err error)

type HTTPHandler

type HTTPHandler interface {
	Register(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) error
}

type HTTPHandlerFunc

type HTTPHandlerFunc func(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) error

func (HTTPHandlerFunc) Register

func (f HTTPHandlerFunc) Register(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) error

Jump to

Keyboard shortcuts

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