Documentation
¶
Overview ¶
Package minato provides an opinionated, fast, and feature-rich HTTP server framework built on top of standard library net/http and chi.
Index ¶
- type GRPCServiceFunc
- type GatewayRegisterFunc
- type Logger
- type Option
- func WithAddr(addr string) Option
- func WithCloser(name string, fn func() error) Option
- func WithGRPCAddr(addr string) Option
- func WithGRPCReflection() Option
- func WithGRPCStreamInterceptor(interceptors ...grpc.StreamServerInterceptor) Option
- func WithGRPCUnaryInterceptor(interceptors ...grpc.UnaryServerInterceptor) Option
- func WithGatewayMuxOptions(opts ...runtime.ServeMuxOption) Option
- func WithHealthCheck() Option
- func WithIdleTimeout(d time.Duration) Option
- func WithLogger(l Logger) Option
- func WithMetrics() Option
- func WithReadHeaderTimeout(d time.Duration) Option
- func WithReadinessCheck(name string, fn func(ctx context.Context) error) Option
- func WithShutdownTimeout(d time.Duration) Option
- type Plugin
- type Router
- func (r *Router) Delete(pattern string, h http.HandlerFunc)
- func (r *Router) Get(pattern string, h http.HandlerFunc)
- func (r *Router) Group(pattern string, fn func(r *Router))
- func (r *Router) Mount(pattern string, h http.Handler)
- func (r *Router) Patch(pattern string, h http.HandlerFunc)
- func (r *Router) Post(pattern string, h http.HandlerFunc)
- func (r *Router) Put(pattern string, h http.HandlerFunc)
- func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (r *Router) Use(middlewares ...func(http.Handler) http.Handler)
- type Server
- func (s *Server) RegisterGRPC(fn GRPCServiceFunc)
- func (s *Server) RegisterGateway(fn GatewayRegisterFunc)
- func (s *Server) Router() *Router
- func (s *Server) Run() error
- func (s *Server) Use(middlewares ...func(http.Handler) http.Handler)
- func (s *Server) UseGRPC(interceptors ...grpc.UnaryServerInterceptor)
- func (s *Server) UsePlugin(plugins ...Plugin)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GRPCServiceFunc ¶ added in v0.2.0
type GRPCServiceFunc func(s grpc.ServiceRegistrar)
GRPCServiceFunc is a callback that registers a gRPC service implementation against the server's grpc.ServiceRegistrar.
type GatewayRegisterFunc ¶ added in v0.2.0
type GatewayRegisterFunc func( ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption, ) error
GatewayRegisterFunc is a callback that registers a gRPC gateway handler produced by protoc-gen-grpc-gateway.
type Logger ¶ added in v0.1.1
Logger interface defines the methods required for custom loggin within Minato framework.
type Option ¶
type Option func(*config)
Option defines a functional configuration option for the Minato Server.
func WithCloser ¶
WithCloser registers a teardown function that will be called during graceful shutdown.
func WithGRPCAddr ¶ added in v0.2.0
WithGRPCAddr sets the TCP address for the gRPC server and enables gRPC mode.
func WithGRPCReflection ¶ added in v0.2.0
func WithGRPCReflection() Option
WithGRPCReflection enables gRPC server reflection. Keep disabled by default and enable only when needed.
func WithGRPCStreamInterceptor ¶ added in v0.2.0
func WithGRPCStreamInterceptor(interceptors ...grpc.StreamServerInterceptor) Option
WithGRPCStreamInterceptor appends one or more stream interceptors to the gRPC server.
func WithGRPCUnaryInterceptor ¶ added in v0.2.0
func WithGRPCUnaryInterceptor(interceptors ...grpc.UnaryServerInterceptor) Option
WithGRPCUnaryInterceptor appends one or more unary interceptors to the gRPC server.
func WithGatewayMuxOptions ¶ added in v0.2.0
func WithGatewayMuxOptions(opts ...runtime.ServeMuxOption) Option
WithGatewayMuxOptions forwards options directly to runtime.NewServeMux.
func WithHealthCheck ¶
func WithHealthCheck() Option
WithHealthCheck enables automatic registration of /healthz and /readyz endpoints.
func WithIdleTimeout ¶
WithIdleTimeout sets the maximum amount of time to wait for the next request when keep-alives are enabled. Defaults to 60 seconds.
func WithLogger ¶ added in v0.1.1
WithLogger allows injecting a custom Logger implementation for the server. If not provided, it defaults to standard log/slog.
func WithMetrics ¶
func WithMetrics() Option
WithMetrics enables automatic registration of the Prometheus /metrics endpoint.
func WithReadHeaderTimeout ¶
WithReadHeaderTimeout sets the amount of time allowed to read request headers. Defaults to 5 seconds.
func WithReadinessCheck ¶
WithReadinessCheck registers a named dependency check for the /readyz endpoint.
func WithShutdownTimeout ¶
WithShutdownTimeout sets the deadline for graceful shutdown. Defaults to 30 seconds.
type Plugin ¶ added in v0.2.0
Plugin bundles the HTTP middleware form and the gRPC unary interceptor form of the same cross-cutting concern into a single registerable unit.
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router is a wrapper around chi.Mux to prevent exposing third-party router dependencies directly to library consumers.
func (*Router) Delete ¶
func (r *Router) Delete(pattern string, h http.HandlerFunc)
Delete adds the route `pattern` that matches a DELETE HTTP method to route handler `h`
func (*Router) Get ¶
func (r *Router) Get(pattern string, h http.HandlerFunc)
Get adds the route `pattern` that matches a GET HTTP method to route handler `h`
func (*Router) Mount ¶ added in v0.2.0
Mount attaches an http.Handler at the given pattern prefix. Used internally by gRPC mode to mount the grpc-gateway ServeMux
func (*Router) Patch ¶
func (r *Router) Patch(pattern string, h http.HandlerFunc)
Patch adds the route `pattern` that matches a PATCH HTTP method to route handler `h`
func (*Router) Post ¶
func (r *Router) Post(pattern string, h http.HandlerFunc)
Post adds the route `pattern` that matches a POST HTTP method to route handler `h`
func (*Router) Put ¶
func (r *Router) Put(pattern string, h http.HandlerFunc)
Put adds the route `pattern` that matches a PUT HTTP method to route handler `h`
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server represents the Minato HTTP server instance, wrapping an internal http.Server and Router
func (*Server) RegisterGRPC ¶ added in v0.2.0
func (s *Server) RegisterGRPC(fn GRPCServiceFunc)
RegisterGRPC registers a gRPC service implementation.
func (*Server) RegisterGateway ¶ added in v0.2.0
func (s *Server) RegisterGateway(fn GatewayRegisterFunc)
RegisterGateway registers a generated grpc-gateway handler for HTTP<->gRPC translation.
func (*Server) Run ¶
Run starts the server. If a gRPC address is configured, it starts in gRPC mode with both gRPC and HTTP/REST endpoints. Otherwise, it starts in standard HTTP mode.
func (*Server) UseGRPC ¶ added in v0.2.0
func (s *Server) UseGRPC(interceptors ...grpc.UnaryServerInterceptor)
UseGRPC appends gRPC unary interceptors directly (without an HTTP counterpart)