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(context.Background()) 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.
type Option ¶
type Option func(*Listener)
Option is a function that configures a Listener.
func WithAPIClient ¶
WithAPIClient sets the API client to use for the Listener.
func WithAuthToken ¶
WithAuthToken sets the auth token to use with the API client.
func WithPolicies ¶ added in v1.3.0
WithPolicies sets the policy names to use for the Listener's underlaying HTTP socket. Policies with the given names will be attached to the socket. If the policy names list is empty, then no policies will be attached. If there are any changes made to the policy names list between listener startups, they will get properly handled. The listener will check the socket's already attached policies, and compare them with the given policy names. Removed policies will be detached from the socket, and new policies will be checked and made sure they exist, and then they will be attached to the listener's socket.
func WithSocketName ¶
WithSocketName sets the socket name to use for the HTTP socket that the Listener will create.
func WithTunnelServer ¶
WithTunnelServer sets the tunnel server address for the Listener.