embed

package
v0.37.1 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2025 License: BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Overview

Package embed provides a way to embed the NetBird client directly into Go programs without requiring a separate NetBird client installation.

Index

Constants

This section is empty.

Variables

View Source
var ErrClientAlreadyStarted = errors.New("client already started")
View Source
var ErrClientNotStarted = errors.New("client not started")

Functions

This section is empty.

Types

type Client

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

Client manages a netbird embedded client instance

func New

func New(opts Options) (*Client, error)

New creates a new netbird embedded client

func (*Client) Dial

func (c *Client) Dial(ctx context.Context, network, address string) (net.Conn, error)

Dial dials a network address in the netbird network. Not applicable if the userspace networking mode is disabled.

func (*Client) ListenTCP

func (c *Client) ListenTCP(address string) (net.Listener, error)

ListenTCP listens on the given address in the netbird network Not applicable if the userspace networking mode is disabled.

func (*Client) ListenUDP

func (c *Client) ListenUDP(address string) (net.PacketConn, error)

ListenUDP listens on the given address in the netbird network Not applicable if the userspace networking mode is disabled.

func (*Client) NewHTTPClient

func (c *Client) NewHTTPClient() *http.Client

NewHTTPClient returns a configured http.Client that uses the netbird network for requests. Not applicable if the userspace networking mode is disabled.

func (*Client) Start

func (c *Client) Start(startCtx context.Context) error

Start begins client operation and blocks until the engine has been started successfully or a startup error occurs. Pass a context with a deadline to limit the time spent waiting for the engine to start.

func (*Client) Stop

func (c *Client) Stop(ctx context.Context) error

Stop gracefully stops the client. Pass a context with a deadline to limit the time spent waiting for the engine to stop.

type Options

type Options struct {
	// DeviceName is this peer's name in the network
	DeviceName string
	// SetupKey is used for authentication
	SetupKey string
	// ManagementURL overrides the default management server URL
	ManagementURL string
	// PreSharedKey is the pre-shared key for the WireGuard interface
	PreSharedKey string
	// LogOutput is the output destination for logs (defaults to os.Stderr if nil)
	LogOutput io.Writer
	// LogLevel sets the logging level (defaults to info if empty)
	LogLevel string
	// NoUserspace disables the userspace networking mode. Needs admin/root privileges
	NoUserspace bool
	// ConfigPath is the path to the netbird config file. If empty, the config will be stored in memory and not persisted.
	ConfigPath string
	// StatePath is the path to the netbird state file
	StatePath string
	// DisableClientRoutes disables the client routes
	DisableClientRoutes bool
}

Options configures a new Client

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳