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 (*FerretDB) MongoDBURI ¶
MongoDBURI returns MongoDB URI for this FerretDB instance.
TCP's connection string is returned if both TCP and Unix listeners are enabled.
Click to show internal directories.
Click to hide internal directories.