nethttp

package
v0.5.5 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package nethttp provides a production-ready net/http adapter for go-trpc with configurable timeouts and graceful shutdown support.

Usage:

r := router.NewRouter()
srv := nethttp.NewServer(r, nethttp.Config{Addr: ":8080"})
go srv.Start()
// ...
srv.Shutdown(context.Background())

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Addr         string        // listen address, default ":8080"
	BasePath     string        // tRPC base path, default "/trpc"
	ReadTimeout  time.Duration // default 30s
	WriteTimeout time.Duration // default 30s
	IdleTimeout  time.Duration // default 120s
}

Config configures the HTTP server.

type Server

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

Server wraps a go-trpc Router in a production-ready *http.Server.

func NewServer

func NewServer(r *router.Router, cfg Config) *Server

NewServer creates a new Server that serves the given router.

func (*Server) Addr

func (s *Server) Addr() string

Addr returns the configured listen address.

func (*Server) Shutdown

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

Shutdown gracefully shuts down the server, waiting for in-flight requests to complete before returning.

func (*Server) Start

func (s *Server) Start() error

Start begins listening and serving HTTP requests. This blocks until the server is shut down. Returns http.ErrServerClosed on graceful shutdown.

func (*Server) StartTLS

func (s *Server) StartTLS(certFile, keyFile string) error

StartTLS begins listening and serving HTTPS requests.

Jump to

Keyboard shortcuts

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