app

package
v0.0.0-...-8db38dd Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2024 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

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

App is a high-level helper for initializing a typical dqlite-based Go application.

It takes care of starting a dqlite node and registering a dqlite Go SQL driver.

func New

func New(dir string, options ...Option) (*App, error)

New creates a new application node.

func (*App) Address

func (*App) Address() string

func (*App) Client

func (*App) Client(context.Context) (*client.Client, error)

func (*App) Close

func (*App) Close() error

func (*App) Handover

func (*App) Handover(context.Context) error

Handover transfers all responsibilities for this node (such has leadership and voting rights) to another node, if one is available.

This method should always be called before invoking Close(), in order to gracefully shut down a node.

func (*App) ID

func (*App) ID() uint64

ID returns the dqlite ID of this application node.

func (*App) Open

func (a *App) Open(_ context.Context, name string) (*sql.DB, error)

Open the dqlite database with the given name

func (*App) Ready

func (*App) Ready(_ context.Context) error

Ready can be used to wait for a node to complete tasks that are initiated at startup. For example a new node will attempt to join the cluster, a restarted node will check if it should assume some particular role, etc.

If this method returns without error it means that those initial tasks have succeeded and follow-up operations like Open() are more likely to succeed quickly.

type Option

type Option func()

Option can be used to tweak app parameters.

func WithAddress

func WithAddress(address string) Option

WithAddress sets the network address of the application node.

Other application nodes must be able to connect to this application node using the given address.

If the application node is not the first one in the cluster, the address must match the value that was passed to the App.Add() method upon registration.

If not given the first non-loopback IP address of any of the system network interfaces will be used, with port 9000.

The address must be stable across application restarts.

func WithCluster

func WithCluster(cluster []string) Option

WithCluster must be used when starting a newly added application node for the first time.

It should contain the addresses of one or more applications nodes which are already part of the cluster.

func WithLogFunc

func WithLogFunc(log client.LogFunc) Option

WithLogFunc sets a custom log function.

func WithTLS

func WithTLS(listen *tls.Config, dial *tls.Config) Option

WithTLS enables TLS encryption of network traffic.

The "listen" parameter must hold the TLS configuration to use when accepting incoming connections clients or application nodes.

The "dial" parameter must hold the TLS configuration to use when establishing outgoing connections to other application nodes.

func WithTracing

func WithTracing(level client.LogLevel) Option

WithTracing will emit a log message at the given level every time a statement gets executed.

Jump to

Keyboard shortcuts

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