ferretdb

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2022 License: Apache-2.0 Imports: 10 Imported by: 7

Documentation

Overview

Package ferretdb provides embeddable FerretDB implementation.

Example (Tcp)
f, err := New(&Config{
	ListenAddr:    "127.0.0.1:17027",
	Handler:       "pg",
	PostgreSQLURL: "postgres://postgres@127.0.0.1:5432/ferretdb",
})
if err != nil {
	log.Fatal(err)
}

ctx, cancel := context.WithCancel(context.Background())

done := make(chan struct{})

go func() {
	log.Print(f.Run(ctx))
	close(done)
}()

uri := f.MongoDBURI()
fmt.Println(uri)

// Use MongoDB URI as usual. For example:
//
// import "go.mongodb.org/mongo-driver/mongo"
//
// [...]
//
// mongo.Connect(ctx, options.Client().ApplyURI(uri)

cancel()
<-done
Output:
mongodb://127.0.0.1:17027/
Example (Unix)
f, err := New(&Config{
	ListenUnix:    "/tmp/ferretdb-27017.sock",
	Handler:       "pg",
	PostgreSQLURL: "postgres://postgres@127.0.0.1:5432/ferretdb",
})
if err != nil {
	log.Fatal(err)
}

ctx, cancel := context.WithCancel(context.Background())

done := make(chan struct{})

go func() {
	log.Print(f.Run(ctx))
	close(done)
}()

uri := f.MongoDBURI()
fmt.Println(uri)

// Use MongoDB URI as usual.

cancel()
<-done
Output:
mongodb://%2Ftmp%2Fferretdb-27017.sock

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Listen address.
	// If empty, TCP listener is disabled.
	ListenAddr string

	// Listen Unix domain socket path.
	// If empty, Unix listener is disabled.
	ListenUnix string

	// Handler to use; one of `pg` or `tigris` (if enabled at compile-time).
	Handler string

	// PostgreSQL connection string for `pg` handler.
	PostgreSQLURL string // For example: `postgres://username:password@hostname:5432/ferretdb`.

	// Tigris parameters for `tigris` handler.
	// See https://docs.tigrisdata.com/overview/authentication
	// and https://docs.tigrisdata.com/golang/getting-started.
	TigrisClientID     string
	TigrisClientSecret string
	TigrisToken        string
	TigrisURL          string
}

Config represents FerretDB configuration.

type FerretDB

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

FerretDB represents an instance of embeddable FerretDB implementation.

func New

func New(config *Config) (*FerretDB, error)

New creates a new instance of embeddable FerretDB implementation.

func (*FerretDB) MongoDBURI

func (f *FerretDB) MongoDBURI() string

MongoDBURI returns MongoDB URI for this FerretDB instance.

TCP's connection string is returned if both TCP and Unix listeners are enabled.

func (*FerretDB) Run

func (f *FerretDB) Run(ctx context.Context) error

Run runs FerretDB until ctx is done.

When this method returns, listener and all connections are closed.

Jump to

Keyboard shortcuts

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