rpcserver

package
v0.2.41 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ProtocolToSystem added in v0.0.90

func ProtocolToSystem(protocol string) string

ProtocolToSystem converts the request protocol to the format used by the OpenTelemetry semantic convention for RPC systems.

func SplitProcedure added in v0.0.90

func SplitProcedure(procedure string) (service, method string)

SplitProcedure splits the RPC procedure into RPC service and RPC method components.

Types

type Config

type Config struct {
	Host        string `koanf:"host" default:"localhost"`
	Port        uint16 `koanf:"port" default:"5000"`
	EnablePprof bool   `koanf:"enablepprof"`
}

Config contains the configuration for creating a Server instance.

type Handler

type Handler interface {
	Register(*http.ServeMux, []connect.HandlerOption)
}

Handler implementations can register themselves to be hosted by the server.

type Recoverer

type Recoverer struct {
	// contains filtered or unexported fields
}

Recoverer handles the recovery from panics and should be used with connect.WithRecover.

When a panic occurs, the following are performed:

  • A log record is produced containing the panic value and stacktrace.
  • If available, the current span's status is set to error and the panic value is recorded as an event.
  • The "rpc.server.panics" counter metric is incremented. This metric includes the "rpc.service" and "rpc.method" attributes.

func NewRecoverer

func NewRecoverer(options ...RecovererOption) (*Recoverer, error)

NewRecoverer creates a Recoverer.

func (*Recoverer) Handle

func (r *Recoverer) Handle(ctx context.Context, spec connect.Spec, _ http.Header, recovered any) error

Handle records a panic via logging, tracing and metrics and returns a generic internal error response to be passed to the client.

type RecovererOption added in v0.0.123

type RecovererOption interface {
	// contains filtered or unexported methods
}

...

func WithMeterProvider added in v0.0.123

func WithMeterProvider(provider metric.MeterProvider) RecovererOption

...

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server provides a HTTP/2 server for one or more HTTP handlers.

func New

func New(
	host string,
	port uint16,
	enablePprof bool,
	handlers []Handler,
	opts []connect.HandlerOption,
) *Server

New creates a new Server instance.

func NewFromConfig

func NewFromConfig(config Config, handlers []Handler, opts []connect.HandlerOption) *Server

New creates a new Server instance from the given configuration.

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

Shutdown gracefully stops the server.

func (*Server) Start

func (s *Server) Start(ctx context.Context) error

Start starts the server and blocks until the server stops.

Directories

Path Synopsis
interceptors
validatex
...
...

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL