Help us shape the future of Go! Take the 2026 Go Developer Survey

server

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseSize

func ParseSize(s string) (int64, error)

ParseSize converts human-readable size strings like "10MB" to bytes.

func RequestIDFromContext

func RequestIDFromContext(ctx context.Context) string

RequestIDFromContext extracts the request ID from context, if present.

Types

type Config

type Config struct {
	Server    ServerConfig     `mapstructure:"server"`
	Log       LogConfig        `mapstructure:"log"`
	Endpoints []EndpointConfig `mapstructure:"endpoints"`
}

func LoadConfig

func LoadConfig(path string) (*Config, error)

type EndpointConfig

type EndpointConfig struct {
	ID          string        `mapstructure:"id"`
	PathPrefix  string        `mapstructure:"path_prefix"`
	Token       string        `mapstructure:"token"`
	Mode        string        `mapstructure:"mode"`
	SyncTimeout time.Duration `mapstructure:"sync_timeout"`
	MaxBodySize string        `mapstructure:"max_body_size"`
}

type GRPCConfig

type GRPCConfig struct {
	Addr             string        `mapstructure:"addr"`
	MaxRecvMsgSize   string        `mapstructure:"max_recv_msg_size"`
	KeepaliveTime    time.Duration `mapstructure:"keepalive_time"`
	KeepaliveTimeout time.Duration `mapstructure:"keepalive_timeout"`
}

type HTTPConfig

type HTTPConfig struct {
	Addr         string        `mapstructure:"addr"`
	ReadTimeout  time.Duration `mapstructure:"read_timeout"`
	WriteTimeout time.Duration `mapstructure:"write_timeout"`
	IdleTimeout  time.Duration `mapstructure:"idle_timeout"`
	MaxBodySize  string        `mapstructure:"max_body_size"`
}

type HTTPServer

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

func NewHTTPServer

func NewHTTPServer(hub *Hub, endpoints []EndpointConfig, maxBodySize string, logger *slog.Logger) (*HTTPServer, error)

func (*HTTPServer) Handler

func (s *HTTPServer) Handler() http.Handler

type Hub

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

Hub manages active tunnel connections and routes incoming webhooks to the correct CLI agent.

func NewHub

func NewHub(logger *slog.Logger) *Hub

func (*Hub) IsConnected

func (h *Hub) IsConnected(endpointID string) bool

IsConnected returns true if a tunnel client is connected for the endpoint.

func (*Hub) Register

func (h *Hub) Register(endpointID string, sender TunnelSender, ep *EndpointConfig) error

Register associates a tunnel stream with an endpoint. Returns an error if another connection already holds the endpoint.

func (*Hub) Resolve

func (h *Hub) Resolve(requestID string, resp *hookerv1.WebhookResponse) bool

Resolve delivers a webhook response from the CLI back to the waiting HTTP handler. Returns false if no handler is waiting for this request ID.

func (*Hub) RouteAsync

func (h *Hub) RouteAsync(req *hookerv1.WebhookRequest) error

RouteAsync sends a webhook to the tunnel client without waiting for a response. Returns an error if no client is connected.

func (*Hub) RouteSync

RouteSync sends a webhook and blocks until the CLI responds or the context deadline is reached.

func (*Hub) Unregister

func (h *Hub) Unregister(endpointID string)

Unregister removes the tunnel connection for an endpoint.

type LogConfig

type LogConfig struct {
	Level  string `mapstructure:"level"`
	Format string `mapstructure:"format"`
}

type Server

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

Server orchestrates the HTTP and gRPC listeners.

func New

func New(cfg *Config, logger *slog.Logger) (*Server, error)

func (*Server) Run

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

Run starts both listeners and blocks until ctx is cancelled.

type ServerConfig

type ServerConfig struct {
	HTTP HTTPConfig `mapstructure:"http"`
	GRPC GRPCConfig `mapstructure:"grpc"`
	TLS  TLSConfig  `mapstructure:"tls"`
}

type TLSConfig

type TLSConfig struct {
	Enabled  bool   `mapstructure:"enabled"`
	CertFile string `mapstructure:"cert_file"`
	KeyFile  string `mapstructure:"key_file"`
}

type TunnelSender

type TunnelSender interface {
	Send(*hookerv1.ServerMessage) error
}

TunnelSender abstracts the ability to send a webhook down a gRPC stream.

type TunnelService

type TunnelService struct {
	hookerv1.UnimplementedTunnelServiceServer
	// contains filtered or unexported fields
}

TunnelService implements the gRPC TunnelService defined in tunnel.proto.

func NewTunnelService

func NewTunnelService(hub *Hub, endpoints []EndpointConfig, logger *slog.Logger) *TunnelService

func (*TunnelService) Connect

Jump to

Keyboard shortcuts

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