Documentation
¶
Index ¶
- Constants
- Variables
- func PortsSpecification() (string, bool)
- type ListenConfig
- type ListenSpec
- type ListenSpecs
- func (ll ListenSpecs) Listen(ctx context.Context, network, address string) (net.Listener, error)
- func (ll ListenSpecs) ListenAll(ctx context.Context) ([]net.Listener, error)
- func (ll ListenSpecs) ListenPacket(ctx context.Context, network, address string) (net.PacketConn, error)
- func (ll ListenSpecs) ListenPacketAll(ctx context.Context) ([]net.PacketConn, error)
- func (ll ListenSpecs) String() string
Constants ¶
const PortEnvName = "SERVER_STARTER_PORT"
PortEnvName is the environment name for server_starter configures. copied from the starter package.
Variables ¶
var ErrNoListeningTarget = errors.New("listener: no listening target")
ErrNoListeningTarget is returned by ListenAll calls when the process is not started using server_starter.
Functions ¶
func PortsSpecification ¶
PortsSpecification returns the value of SERVER_STARTER_PORT environment variable. If the process starts from the start_server command, returns the port specification and the boolean is true. Otherwise the returned value will be empty and the boolean will be false.
Types ¶
type ListenConfig ¶
type ListenConfig interface {
Listen(ctx context.Context, network, address string) (net.Listener, error)
ListenPacket(ctx context.Context, network, address string) (net.PacketConn, error)
}
ListenConfig is a generator of net.Listener.
func PortsFallback ¶
func PortsFallback() (ListenConfig, error)
PortsFallback returns the same result as Ports, if SERVER_STARTER_PORT is defined. Otherwise returns net.ListenConfig instead of ListenSpecs. Regardless of whether the process starts from the start_server command or not, you can call Listen method.
lc, err := listener.PortsFallback() l, err := lc.Listen(ctx, "tcp", ":8080")
type ListenSpec ¶
type ListenSpec interface {
// Fd returns the underlying file descriptor
Fd() uintptr
// Listen creates a new Listener
Listen() (net.Listener, error)
// ListenPacket creates new PacketConn
ListenPacket() (net.PacketConn, error)
// Addr returns the address.
Addr() string
// return a string compatible with SERVER_STARTER_PORT
String() string
}
ListenSpec is the interface for things that listen on file descriptors specified by Start::Server / server_starter
type ListenSpecs ¶
type ListenSpecs []ListenSpec
ListenSpecs holds a list of ListenConfig. This is here just for convenience so that you can do
list.String()
to get a string compatible with SERVER_STARTER_PORT
func Ports ¶
func Ports() (ListenSpecs, error)
Ports parses the environment variable SERVER_STARTER_PORT, and return ListenSpecs. If SERVER_STARTER_PORT is not defined, return ErrNoListeningTarget.
func (ListenSpecs) Listen ¶
Listen announces on the local network address. The network must be "tcp", "tcp4", "tcp6", "unix".
func (ListenSpecs) ListenPacket ¶
func (ll ListenSpecs) ListenPacket(ctx context.Context, network, address string) (net.PacketConn, error)
ListenPacket announces on the local network address. The network must be "udp", "udp4", "udp6".
func (ListenSpecs) ListenPacketAll ¶
func (ll ListenSpecs) ListenPacketAll(ctx context.Context) ([]net.PacketConn, error)
ListenPacketAll announces on the local network address.
func (ListenSpecs) String ¶
func (ll ListenSpecs) String() string