mongodbrelation

package
v0.0.0-...-c60bc85 Latest Latest
Warning

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

Go to latest
Published: May 19, 2017 License: LGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

The mongodbrelation package implements a Juju mongodb relation.

Importing this package also registers the type *mgo.Session with the httpservice package, so that it can be used as a relation field with httpservice.Service.Register.

For example, to register a web service that requires a MongoDB connection, you might do something like this:

type relations struct {
	Session *mgo.Session	`httpservice:"mongodb"`
}
func RegisterHooks(r *hook.Registry) {
	var svc httpservice.Service
	svc.Register(r, "somename", "http", func(_ struct{}, rel *relations) (httpservice.Handler, error) {
		// rel.Session contains the actual MongoDB connection.
		return newHandler(rel)
	})
}

This would create a Juju requirer relation named "mongodb" and dial the related MongoDB instance before creating the HTTP handler.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Requirer

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

Requirer represents the requirer side of an mongodb relation.

func (*Requirer) Addresses

func (req *Requirer) Addresses() []string

Addresses returns the addresses of the current mongodb servers.

func (*Requirer) Register

func (req *Requirer) Register(r *hook.Registry, relationName string)

Register registers an mongodb requirer relation with the given relation name with the given hook registry.

To find out when the host addresses change, register a wildcard ("*") hook.

func (*Requirer) URL

func (req *Requirer) URL() string

URL returns a URL suitable for passing to mgo.Dial. If there are no current addresses, it returns the empty string. TODO does this work with IPv6?

Jump to

Keyboard shortcuts

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