grpc

package
v1.2.117 Latest Latest
Warning

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

Go to latest
Published: May 13, 2024 License: MIT Imports: 24 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractLoggingOptions added in v1.2.99

func ExtractLoggingOptions(options ...GatewayOption) []logging.Option

ExtractLoggingOptions extract all logging.Option from the given options.

func FieldsFromContextWithForward added in v1.2.89

func FieldsFromContextWithForward(ctx context.Context) logging.Fields

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

func HttpInterceptor added in v1.2.99

func HttpInterceptor(l logging.Logger) func(handler http.Handler) http.Handler

HttpInterceptor returns a new unary http interceptors that optionally logs endpoint handling. Logger will read existing and write new logging.Fields available in current context. See `ExtractFields` and `InjectFields` for details.

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

NewGatewayTLS 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) BindAddr added in v1.2.109

func (gateway *Gateway) BindAddr() string

BindAddr returns actual addr bind after a net.Listener on

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 WithDefault

func WithDefault() []GatewayOption

func WithDefaultMarsherOption

func WithDefaultMarsherOption() []GatewayOption

func WithGateway added in v1.2.89

func WithGateway(v Gateway) GatewayOption

WithGateway sets Gateway.

func WithGatewayGrpcServer added in v1.2.89

func WithGatewayGrpcServer(v *grpc.Server) GatewayOption

WithGatewayGrpcServer sets grpcServer in Gateway. runtime

func WithGatewayHandler added in v1.2.89

func WithGatewayHandler(v http.Handler) GatewayOption

WithGatewayHandler sets Handler in Gateway.

func WithGatewayHttpMuxToGrpc added in v1.2.89

func WithGatewayHttpMuxToGrpc(v *runtime.ServeMux) GatewayOption

WithGatewayHttpMuxToGrpc sets httpMuxToGrpc in Gateway.

func WithGatewayOpt added in v1.2.89

func WithGatewayOpt(v gatewayOption) GatewayOption

WithGatewayOpt sets opt in Gateway. options

func WithGrpcDialOption

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

func WithGrpcReflectionService

func WithGrpcReflectionService(autoRegistered bool) GatewayOption

func WithGrpcServeMuxOption

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

func WithGrpcServerOption

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

func WithGrpcStreamClientChain

func WithGrpcStreamClientChain(interceptors ...grpc.StreamClientInterceptor) GatewayOption

func WithGrpcStreamServerChain

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

func WithGrpcUnaryClientChain

func WithGrpcUnaryClientChain(interceptors ...grpc.UnaryClientInterceptor) 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 WithHttpAfterCompletion

func WithHttpAfterCompletion(
	afterCompletion func(w http.ResponseWriter, r *http.Request, err any)) GatewayOption

func WithHttpHandlerInterceptor

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

func WithHttpPostHandler

func WithHttpPostHandler(
	postHandle func(w http.ResponseWriter, r *http.Request)) GatewayOption

func WithHttpPreHandler

func WithHttpPreHandler(preHandle func(w http.ResponseWriter, r *http.Request) error) GatewayOption

func WithHttpRewriter deprecated

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

Deprecated: Use WithHttpPreHandler instead.

func WithHttpWrapper

func WithHttpWrapper(wrapper func(http.Handler) http.Handler) GatewayOption

WithHttpWrapper is a decorator or middleware of http.Handler

func WithLoggingOption added in v1.2.99

func WithLoggingOption(opts ...logging.Option) GatewayOption

func WithMarshalerOption

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

func WithSlogLogger added in v1.2.89

func WithSlogLogger(logger slog.Handler) []GatewayOption

func WithSlogLoggerConfig added in v1.2.89

func WithSlogLoggerConfig(h slog.Handler, slogOpts []logging.Option) []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