listen

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2023 License: Apache-2.0 Imports: 19 Imported by: 6

Documentation

Overview

Package listen can create a Border0 listener with configurable options. The border0 listener is a net.Listener that can be used to accept incoming connections. When the listener is passed to http.Serve, the server will accept HTTP requests sent by Border0 and forward them to an HTTP handler. The handler's response will be sent back to Border0. If no options are provided, some default values will be used.

Example:

listener := listen.New(
	listen.WithSocketName("sdk-socket-http"),              // http socket name the listener will be bound to, socket will be created if not exists
	listen.WithAuthToken(os.Getenv("BORDER0_AUTH_TOKEN")), // optional, if not provided, Border0 SDK will use BORDER0_AUTH_TOKEN env var
)
err := listener.Start()
if err != nil {
	// handle error
}
defer listener.Close()

// create a handler
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
	// do something
})

// start a server using the listener
http.Serve(listener, handler)

See Option for more configurable options.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Listener

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

Listener is a net.Listener that connects to a Border0 tunnel server and forwards connections to the local machine.

func New

func New(options ...Option) *Listener

New creates a new Listener with the given options.

func (*Listener) Accept

func (l *Listener) Accept() (net.Conn, error)

Accept waits for and returns the next connection to the listener.

func (*Listener) Addr

func (l *Listener) Addr() net.Addr

Addr returns the listener's network address.

func (*Listener) Close

func (l *Listener) Close() error

Close closes the listener.

func (*Listener) Start

func (l *Listener) Start() error

Start connects to Border0 tunnel server and starts listening for connections. It will block until the listener is ready to accept connections.

type Option

type Option func(*Listener)

Option is a function that configures a Listener.

func WithAPIClient

func WithAPIClient(api client.Requester) Option

WithAPIClient sets the API client to use for the Listener.

func WithAuthToken

func WithAuthToken(token string) Option

WithAuthToken sets the auth token to use with the API client.

func WithSocketName

func WithSocketName(name string) Option

WithSocketName sets the socket name to use for the HTTP socket that the Listener will create.

func WithTunnelServer

func WithTunnelServer(server string) Option

WithTunnelServer sets the tunnel server address for the Listener.

Jump to

Keyboard shortcuts

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