Documentation ¶
Index ¶
- func ExtractLoggingOptions(options ...GatewayOption) []logging.Option
- func FieldsFromContextWithForward(ctx context.Context) logging.Fields
- func HttpInterceptor(l logging.Logger) func(handler http.Handler) http.Handler
- 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 (o *Gateway) ApplyOptions(options ...GatewayOption) *Gateway
- func (gateway *Gateway) BindAddr() string
- 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 WithDefault() []GatewayOption
- func WithDefaultMarsherOption() []GatewayOption
- func WithGateway(v Gateway) GatewayOption
- func WithGatewayGrpcServer(v *grpc.Server) GatewayOption
- func WithGatewayHandler(v http.Handler) GatewayOption
- func WithGatewayHttpMuxToGrpc(v *runtime.ServeMux) GatewayOption
- func WithGatewayOpt(v gatewayOption) GatewayOption
- func WithGrpcDialOption(opts ...grpc.DialOption) GatewayOption
- func WithGrpcReflectionService(autoRegistered bool) GatewayOption
- func WithGrpcServeMuxOption(opts ...runtime.ServeMuxOption) GatewayOption
- func WithGrpcServerOption(opts ...grpc.ServerOption) GatewayOption
- func WithGrpcStreamClientChain(interceptors ...grpc.StreamClientInterceptor) GatewayOption
- func WithGrpcStreamServerChain(interceptors ...grpc.StreamServerInterceptor) GatewayOption
- func WithGrpcUnaryClientChain(interceptors ...grpc.UnaryClientInterceptor) GatewayOption
- func WithGrpcUnaryServerChain(interceptors ...grpc.UnaryServerInterceptor) GatewayOption
- func WithHTTPErrorHandler(fn HTTPErrorHandler) GatewayOption
- func WithHttpAfterCompletion(afterCompletion func(w http.ResponseWriter, r *http.Request, err any)) GatewayOption
- func WithHttpHandlerInterceptor(opts ...http_.HandlerInterceptorChainOption) GatewayOption
- func WithHttpPostHandler(postHandle func(w http.ResponseWriter, r *http.Request)) GatewayOption
- func WithHttpPreHandler(preHandle func(w http.ResponseWriter, r *http.Request) error) GatewayOption
- func WithHttpRewriter(rewriter func(w http.ResponseWriter, r *http.Request) error) GatewayOptiondeprecated
- func WithHttpWrapper(wrapper func(http.Handler) http.Handler) GatewayOption
- func WithLoggingOption(opts ...logging.Option) GatewayOption
- func WithMarshalerOption(mime string, marshaler runtime.Marshaler) GatewayOption
- func WithSlogLogger(logger slog.Handler) []GatewayOption
- func WithSlogLoggerConfig(h slog.Handler, slogOpts []logging.Option) []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 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
FieldsFromContextWithForward fill "X-Forwarded-For" and "X-Forwarded-Host" to record http callers
func HttpInterceptor ¶ added in v1.2.99
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 ¶
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
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
BindAddr returns actual addr bind after a net.Listener on
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 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
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)