Documentation
¶
Overview ¶
go/grpc/server.go
Index ¶
- Constants
- func CodeFromHTTPStatus(status int) codes.Code
- func ForwardCustomHeaders(ctx context.Context) context.Context
- func GetHTTPMethod(ctx context.Context) string
- func IsStandardHeader(key string) bool
- func SetHTTPHeader(ctx context.Context, key, value string) error
- func WithDNSBalancer() grpc.DialOption
- func WithRawCodec() grpc.CallOption
- type Connection
- func (c *Connection) Close() error
- func (c *Connection) Connect(ctx context.Context) error
- func (c *Connection) Get() *grpc.ClientConn
- func (c *Connection) HealthCheckFn(service string) health.Check
- func (c *Connection) WithLogger(logger *slog.Logger) *Connection
- func (c *Connection) WithMetadata(key, value string) *Connection
- func (c *Connection) WithOptions(options ...grpc.DialOption) *Connection
- func (c *Connection) WithStreamInterceptors(interceptors ...grpc.StreamClientInterceptor) *Connection
- func (c *Connection) WithUnaryInterceptors(interceptors ...grpc.UnaryClientInterceptor) *Connection
- type Gateway
- func (g *Gateway) GracefulStop() error
- func (g *Gateway) Serve(ctx context.Context) error
- func (g *Gateway) Stop() error
- func (g *Gateway) WithClientStreamInterceptors(interceptors ...grpc.StreamClientInterceptor) *Gateway
- func (g *Gateway) WithClientUnaryInterceptors(interceptors ...grpc.UnaryClientInterceptor) *Gateway
- func (g *Gateway) WithDialOptions(options ...grpc.DialOption) *Gateway
- func (g *Gateway) WithLogger(logger *slog.Logger) *Gateway
- func (g *Gateway) WithOptions(options ...runtime.ServeMuxOption) *Gateway
- type GatewayCookie
- type GatewayOpts
- type Opts
- type RegisterHandler
- type Server
- func (s *Server) GetHealthServer() *health.GRPCServer
- func (s *Server) GracefulStop() error
- func (s *Server) Serve(ctx context.Context) error
- func (s *Server) Stop() error
- func (s *Server) WithFileDescriptorSet(bytes []byte) *Server
- func (s *Server) WithLogger(logger *slog.Logger) *Server
- func (s *Server) WithOptions(options ...grpc.ServerOption) *Server
- func (s *Server) WithStreamInterceptors(interceptors ...grpc.StreamServerInterceptor) *Server
- func (s *Server) WithUnaryInterceptors(interceptors ...grpc.UnaryServerInterceptor) *Server
- type ServerOptions
- type WebCookie
Constants ¶
const ( HeaderXForwardedProto = "X-Forwarded-Proto" HeaderXForwardedHost = "X-Forwarded-Host" HeaderXOriginalURL = "X-Original-Url" HeaderXRequestBody = "X-Request-Body-Bin" HeaderXHTTPMethod = "X-Http-Method" )
const ( HTTPHeaderLocation = "Location" HTTPHeaderCacheControl = "Cache-Control" )
///////////// FORWARD RESPONSE OPTIONS //////////////
const (
// maximum message size for the server (20 MB)
MaximumMessageSize = 20 * 1024 * 1024
)
Variables ¶
This section is empty.
Functions ¶
func CodeFromHTTPStatus ¶
CodeFromHTTPStatus converts an HTTP status code to the corresponding gRPC code. This follows the inverse mapping of HTTPStatusFromCode as defined in the gRPC spec. If the HTTP status code doesn't have a direct mapping, it returns codes.Unknown.
See: https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto
func GetHTTPMethod ¶
func IsStandardHeader ¶
IsStandardHeader returns true if the given key is a standard gRPC/HTTP2 header:
- ":" HTTP/2 pseudo-headers (:authority, :method, :path, :scheme).
- "grpc-" gRPC reserved headers (grpc-timeout, grpc-encoding, grpc-status, etc.).
- "content-type" required by gRPC, always "application/grpc".
- "user-agent" set automatically by gRPC clients.
- "te" HTTP/2 transfer encoding, always "trailers".
- "authorization" standard HTTP authentication header.
func WithDNSBalancer ¶
func WithDNSBalancer() grpc.DialOption
withDNSBalancer returns gRPC DialOption that does client-side load balancing based on DNS.
func WithRawCodec ¶
func WithRawCodec() grpc.CallOption
Types ¶
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
Connection is a gRPC client.
func NewConnection ¶
func NewConnection(opts *Opts, certsOpts *certs.Opts, prometheusOpts *prometheus.Opts) (*Connection, error)
NewConnection creates and returns a new gRPC client.
func (*Connection) Close ¶
func (c *Connection) Close() error
func (*Connection) Connect ¶
func (c *Connection) Connect(ctx context.Context) error
Connect dials the gRPC connection and returns it, as well as a health.ProbeFN, to encourage any client to use the probe fn as a health check.
func (*Connection) Get ¶
func (c *Connection) Get() *grpc.ClientConn
func (*Connection) HealthCheckFn ¶
func (c *Connection) HealthCheckFn(service string) health.Check
HealthCheck calls the `Check` method of the grpc server, specifying the service.
func (*Connection) WithLogger ¶
func (c *Connection) WithLogger(logger *slog.Logger) *Connection
func (*Connection) WithMetadata ¶
func (c *Connection) WithMetadata(key, value string) *Connection
WithMetadata adds a static metadata key-value pair to every unary and stream call.
func (*Connection) WithOptions ¶
func (c *Connection) WithOptions(options ...grpc.DialOption) *Connection
WithOptions adds options to this gRPC client.
func (*Connection) WithStreamInterceptors ¶
func (c *Connection) WithStreamInterceptors(interceptors ...grpc.StreamClientInterceptor) *Connection
WithStreamInterceptors adds interceptors to this gRPC client.
func (*Connection) WithUnaryInterceptors ¶
func (c *Connection) WithUnaryInterceptors(interceptors ...grpc.UnaryClientInterceptor) *Connection
WithUnaryInterceptors adds interceptors to this gRPC client.
type Gateway ¶
type Gateway struct {
// contains filtered or unexported fields
}
Gateway is a gRPC gateway.
func NewGateway ¶
func NewGateway(opts *GatewayOpts, grpcOpts *Opts, certsOpts *certs.Opts, prometheusOpts *prometheus.Opts, registerHandlers []RegisterHandler) *Gateway
NewGateway creates and returns a new Gateway.
func (*Gateway) GracefulStop ¶
GracefulStop gracefully stops the gateway server.
func (*Gateway) WithClientStreamInterceptors ¶
func (g *Gateway) WithClientStreamInterceptors(interceptors ...grpc.StreamClientInterceptor) *Gateway
WithClientStreamInterceptors adds interceptors to this gateway's gRPC client..
func (*Gateway) WithClientUnaryInterceptors ¶
func (g *Gateway) WithClientUnaryInterceptors(interceptors ...grpc.UnaryClientInterceptor) *Gateway
WithClientUnaryInterceptors adds interceptors to this gateway's gRPC client..
func (*Gateway) WithDialOptions ¶
func (g *Gateway) WithDialOptions(options ...grpc.DialOption) *Gateway
WithDialOptions adds dial options to this gRPC gateway.
func (*Gateway) WithOptions ¶
func (g *Gateway) WithOptions(options ...runtime.ServeMuxOption) *Gateway
WithOptions adds options to this gRPC gateway.
type GatewayCookie ¶
type GatewayCookie struct {
// contains filtered or unexported fields
}
GatewayCookie namespaces methods for grpc-gateway cookies.
func (*GatewayCookie) GetHTTPCookie ¶
func (gc *GatewayCookie) GetHTTPCookie(ctx context.Context, name string) (*grpcpb.HttpCookie, error)
GetHTTPCookie retrieves the http cookie with the given name from the context.
func (*GatewayCookie) GetHTTPCookies ¶
func (*GatewayCookie) GetHTTPCookies(ctx context.Context) ([]*grpcpb.HttpCookie, error)
GetHTTPCookies retrieves any http cookies from a context.
func (*GatewayCookie) SetHTTPCookies ¶
func (*GatewayCookie) SetHTTPCookies(ctx context.Context, httpCookies ...*grpcpb.HttpCookie) error
SetHTTPCookies is used by a server to send cookies through grpc headers, to the grpc gateway during an RPC call.
type GatewayOpts ¶
type GatewayOpts struct {
Port int `long:"port" env:"PORT" description:"Port to serve the GRPC gateway on." default:"8080"`
Host string `long:"host" env:"HOST" description:"Host for a client to connect to."`
GracefulStopTimeout int `` /* 127-byte string literal not displayed */
AllowedIncomingHeaders []string `` /* 143-byte string literal not displayed */
AllowedOutgoingHeaders []string `` /* 146-byte string literal not displayed */
}
GatewayOpts holds a gRPC gateway server opts.
type Opts ¶
type Opts struct {
Health *health.GRPCOpts `group:"Health" namespace:"health" env-namespace:"HEALTH"`
Port int `long:"port" env:"PORT" description:"Port to serve gRPC on." default:"9090"`
Host string `long:"host" env:"HOST" description:"Host for a client to connect to."`
DisableTLS bool `long:"disable-tls" env:"DISABLE_TLS" description:"Set to true in order to disable TLS for this service."`
GracefulStopTimeout int `` /* 127-byte string literal not displayed */
SocketPath string `long:"socket-path" env:"SOCKET_PATH" description:"Unix socket path to use instead of TCP port"`
EnableReflection bool `long:"enable-reflection" env:"ENABLE_REFLECTION" description:"enable the reflection api"`
}
Opts holds a gRPC server opts.
type RegisterHandler ¶
type RegisterHandler = func(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error)
RegisterHandler is syntactice sugar for a gRPC gateway handler.
type Server ¶
Server is a gRPC server.
func NewServer ¶
func NewServer(opts *Opts, certsOpts *certs.Opts, prometheusOpts *prometheus.Opts, name string, register func(*Server)) *Server
NewServer creates and returns a new Server.
func (*Server) GetHealthServer ¶
func (s *Server) GetHealthServer() *health.GRPCServer
func (*Server) GracefulStop ¶
func (*Server) WithFileDescriptorSet ¶
func (*Server) WithOptions ¶
func (s *Server) WithOptions(options ...grpc.ServerOption) *Server
WithOptions adds options to this gRPC server.
func (*Server) WithStreamInterceptors ¶
func (s *Server) WithStreamInterceptors(interceptors ...grpc.StreamServerInterceptor) *Server
WithStreamInterceptors adds interceptors to this gRPC server. These interceptors are added *AFTER* the default pre interceptors and *BEFORE* the default post interceptors.
func (*Server) WithUnaryInterceptors ¶
func (s *Server) WithUnaryInterceptors(interceptors ...grpc.UnaryServerInterceptor) *Server
WithUnaryInterceptors adds interceptors to this gRPC server. These interceptors are added *AFTER* the default pre interceptors and *BEFORE* the default post interceptors.
type ServerOptions ¶
type ServerOptions struct {
UnaryInterceptors []grpc.UnaryServerInterceptor
StreamInterceptors []grpc.StreamServerInterceptor
GRPCOptions []grpc.ServerOption
}
ServerOptions holds config for a server.
type WebCookie ¶
type WebCookie struct{}
WebCookie namespaces methods for grpc-web cookies.
func (WebCookie) GetHTTPCookie ¶
GetHTTPCookie retrieves the http cookie with the given name from the context.
func (WebCookie) GetHTTPCookies ¶
func (WebCookie) GetHTTPCookies(ctx context.Context) []*grpcpb.HttpCookie
GetHTTPCookies retrieves any http cookies from a context.
func (WebCookie) SetHTTPCookies ¶
SetHTTPCookies adds cookies to a grpc header with the `set-cookie`key. This is used to send cookies back to grpc-web clients.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package grpcinproc provides utilities for working with gRPC streaming RPCs.
|
Package grpcinproc provides utilities for working with gRPC streaming RPCs. |
|
go/grpc/middleware/errors.go
|
go/grpc/middleware/errors.go |
|
Package mockserver provides a gRPC server that stands in for a third party in tests.
|
Package mockserver provides a gRPC server that stands in for a third party in tests. |