Documentation
¶
Index ¶
- func ListenAndServe(addr string, handler http.Handler, opts ...GatewayOption) error
- func ListenAndServeTLS(addr, certFile, keyFile string, handler http.Handler, opts ...GatewayOption) error
- func Serve(l net.Listener, handler http.Handler, opts ...GatewayOption) error
- func ServeTLS(l net.Listener, handler http.Handler, certFile, keyFile string, ...) error
- type EmptyGatewayOption
- type ForwardResponseMessageHandler
- type ForwardResponseMessageHandlerFunc
- type GRPCHandler
- type GRPCHandlerFunc
- type Gateway
- func (gateway *Gateway) ApplyOptions(options ...GatewayOption) *Gateway
- func (gateway *Gateway) ListenAndServe() error
- func (gateway *Gateway) ListenAndServeTLS(certFile, keyFile string) error
- func (gateway *Gateway) RegisterGRPCFunc(handler func(srv *grpc.Server))
- func (gateway *Gateway) RegisterGRPCHandler(handler GRPCHandler)
- func (gateway *Gateway) RegisterHTTPFunc(ctx context.Context, ...) error
- func (gateway *Gateway) RegisterHTTPHandler(ctx context.Context, handler HTTPHandler) error
- func (gateway *Gateway) Serve(l net.Listener) error
- func (gateway *Gateway) ServeTLS(l net.Listener, certFile, keyFile string) error
- type GatewayOption
- func WithDefaultMarsherOption() []GatewayOption
- func WithFastMode(fastMode bool) GatewayOption
- func WithGrpcDialOption(opts ...grpc.DialOption) GatewayOption
- func WithGrpcServeMuxOption(opts ...runtime.ServeMuxOption) GatewayOption
- func WithGrpcServerOption(opts ...grpc.ServerOption) GatewayOption
- func WithGrpcStreamServerChain(interceptors ...grpc.StreamServerInterceptor) GatewayOption
- func WithGrpcUnaryServerChain(interceptors ...grpc.UnaryServerInterceptor) GatewayOption
- func WithHTTPErrorHandler(fn HTTPErrorHandler) GatewayOption
- func WithHttpHandlerInterceptor(opts ...http_.HandlerInterceptorChainOption) GatewayOption
- func WithHttpRewriter(rewriter func(w http.ResponseWriter, r *http.Request) error) GatewayOption
- func WithLogrusLogger(logger *logrus.Logger) GatewayOption
- func WithMarshalerOption(mime string, marshaler runtime.Marshaler) GatewayOption
- func WithStreamErrorHandler(fn runtime.StreamErrorHandlerFunc) GatewayOption
- type GatewayOptionFunc
- type HTTPErrorHandler
- type HTTPErrorHandlerFunc
- type HTTPHandler
- type HTTPHandlerFunc
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 Serve ¶
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 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 GRPCHandlerFunc ¶
func (GRPCHandlerFunc) Register ¶
func (f GRPCHandlerFunc) Register(srv *grpc.Server)
type Gateway ¶
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 (gateway *Gateway) ApplyOptions(options ...GatewayOption) *Gateway
func (*Gateway) ListenAndServe ¶
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 ¶
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 ¶
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) ServeTLS ¶
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 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 ¶ added in v0.0.28
func WithHttpHandlerInterceptor(opts ...http_.HandlerInterceptorChainOption) GatewayOption
func WithHttpRewriter ¶ added in v0.0.28
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
func WithStreamErrorHandler ¶
func WithStreamErrorHandler(fn runtime.StreamErrorHandlerFunc) GatewayOption
type GatewayOptionFunc ¶
type GatewayOptionFunc func(*Gateway)
GatewayOptionFunc wraps a function that modifies Gateway into an implementation of the GatewayOption interface.
type HTTPErrorHandler ¶
type HTTPErrorHandlerFunc ¶
type HTTPErrorHandlerFunc func(ctx context.Context, mux *runtime.ServeMux, marshaler runtime.Marshaler, w http.ResponseWriter, r *http.Request, err error)