net

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2022 License: MIT Imports: 6 Imported by: 1

Documentation

Overview

Package net contains the main logic to send and receive requests

I defines interfaces shared by other packages that accept or send requests Packages that implement these interfaces include:

  • net/cache
  • net/grpc
  • net/http

It also manages the lifecycle of the handlers. All handlers should be registered to this package in order to be gracefuly stopped (drained) when the application shuts down.

Index

Constants

View Source
const (
	// StateDown mode is the default state. The handler is not ready to accept
	// new connections
	StateDown uint32 = iota
	// StateUp mode is when a handler accepts connections
	StateUp
	// StateDrain mode is when a handler stops accepting new connection, but wait
	// for all existing in-flight requests to complete
	StateDrain
)

Variables

View Source
var (
	// ErrEmptyReg is the error returned when there are no servers registered
	ErrEmptyReg = errors.New("there must be at least one registered server")
	// ErrDraining occurs when there is an attempt to access a draining `Server`
	ErrDraining = errors.New("server is draining")
)

Functions

func JoinHostPort

func JoinHostPort(host, port string) string

JoinHostPort combines host and port into a network address of the form "host:port". If host contains a colon, as found in literal IPv6 addresses, then JoinHostPort returns "[host]:port".

See func Dial for a description of the host and port parameters.

Types

type Reg

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

Reg (registry) holds a list of H

func NewReg

func NewReg(log log.Logger) *Reg

NewReg builds a new registry

func (*Reg) Add

func (r *Reg) Add(addr string, h Server)

Add adds the given server to the list of servers

func (*Reg) Drain

func (r *Reg) Drain()

Drain notify all servers to enter in draining mode. It means they are no longer accepting new requests, but they can finish all in-flight requests

func (*Reg) Serve

func (r *Reg) Serve(ctx context.Context) error

Serve starts all registered servers

type Server

type Server interface {
	Serve(ctx context.Context, addr string) error
	Drain()
}

Server is the interface to implement to be a valid server

Directories

Path Synopsis
Package http is an extra layer on to of the standard go net/http package.
Package http is an extra layer on to of the standard go net/http package.
Package naming is a library that converts a target to one or multiple network addresses.
Package naming is a library that converts a target to one or multiple network addresses.
Package stream offers an abstraction layer for stream-processing platforms, such as NATS streaming.
Package stream offers an abstraction layer for stream-processing platforms, such as NATS streaming.

Jump to

Keyboard shortcuts

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