database

package module
v0.0.0-...-9648d7d Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2021 License: GPL-3.0 Imports: 8 Imported by: 6

README

database

Helper package for Packetframe's control plane database

Example
package main

import (
	log "github.com/sirupsen/logrus"

	database "github.com/packetframe/database/pkg/db"
	"github.com/packetframe/database/pkg/queue"
)

func main() {
	db, err := database.New("mongodb://localhost:27017", "packetframe")
	if err != nil {
		log.Fatal(err)
	}

	if err := db.QueueAppend(queue.Message{
		Payload: map[string]string{"foo": "bar"},
	}); err != nil {
		log.Fatal(err)
	}

	if msg, err := db.QueueNext(); err != nil {
		log.Fatal(err)
	} else {
		log.Printf("%+v\n", msg)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Database

type Database struct {
	Db *mongo.Database
}

Database wraps a mongo.Database

func New

func New(bootstrapUri string, databaseName string) (*Database, error)

New constructs a new database object

func (*Database) NewIndex

func (d *Database) NewIndex(collection string, key string, unique bool) error

NewIndex creates a new database index with given collection, key, and uniqueness boolean

func (*Database) QueueAppend

func (d *Database) QueueAppend(m Message) error

QueueAppend appends a message to the queue

func (*Database) QueueDelete

func (d *Database) QueueDelete(m Message) error

QueueDelete deletes a message from the queue

func (*Database) QueueNext

func (d *Database) QueueNext() (*Message, error)

QueueNext retrieves the newest message in queue, may return mongo.ErrNoDocuments if there are no queue messages

type Message

type Message struct {
	ID       primitive.ObjectID `bson:"_id,omitempty"`
	Payload  map[string]string
	Created  int64
	Locked   bool
	LockedAt int64
}

Message stores a single queue entry

Jump to

Keyboard shortcuts

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