mongo

package module
v0.0.0-...-ecd6d2d Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2018 License: MIT Imports: 12 Imported by: 0

README

Mongo Go Report Card

Mongo is a reference storage implementation based on the core library and mongodb.

Branch Pipeline Coverage
Master pipeline status coverage report
Develop pipeline status coverage report

Documentation

Overview

Package mongo is a reference storage implementation for the npolar/api(https://gitlab.com/npolar/api) project based on MongoDB. The globalsign/mgo(https://godoc.org/github.com/globalsign/mgo) package is used to communicate with MongoDB. Document storage and internal metadata are stored in collections. File storage uses GridFS.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

type Conn struct {
	Database       string   `json:"database"`
	Collection     string   `json:"collection"`
	SupportedTypes []string `json:"supportedTypes"`
	Servers        []string `json:"servers"`
	User           string   `json:"username"`
	Pass           string   `json:"password"`
	AuthDB         string   `json:"authDB"`

	*mgo.Session
	// contains filtered or unexported fields
}

Conn wraps the MongoDB configuration and implements the core.Conn interface.

func (Conn) Close

func (c Conn) Close() error

Close wraps the mgo.Session.Close() method and returns nil when called.

From the mgo docs: Close terminates the session. It's a runtime error to use
a session after it has been closed.

reference: https://godoc.org/github.com/globalsign/mgo#Session.Close

func (Conn) Create

func (c Conn) Create(info *core.Info, r io.Reader) error

Create inserts a new item into a collection or GridFS prefix based on the storage mode in use. Create verifies which types are configured for storage. If the item being created isn't of a supported type it will get rejected with an unsupported type error.

func (Conn) Delete

func (c Conn) Delete(info *core.Info) error

Delete an item from the collection/GridFS prefix based on the storage mode. Info objects are retained after deletion. This ensure that we don't create any dead references. If data is gone the info should be returned.

func (Conn) Formats

func (c Conn) Formats() []string

Formats returns an string array containing the allowed formats for this connection. Formats should be specified in the media type format as defined in RFC6838: https://tools.ietf.org/html/rfc6838

func (Conn) InfoList

func (c Conn) InfoList(info *core.Info, opts *core.RequestOptions) (io.Reader, error)

InfoList returns a list of info items as an io.Reader. This can be used to render info lists or build operational logic spanning multiple items.

func (Conn) NewWriteCloser

func (c Conn) NewWriteCloser(info *core.Info) (io.WriteCloser, error)

NewWriteCloser returns a new io.WriteCloser based on the info object provided. This is convenient for use cases where you want to control the write actions directly (for example when creating archives on the fly).

  • NewWriteCloser doesn't persist Info to disk so the caller needs to run a Conn.WriteInfo(info) call to write metadata to disk.
  • NewWriteCloser can't be used to update existing content.

func (Conn) Read

func (c Conn) Read(info *core.Info, ctx context.Context) (io.ReadSeeker, error)

Read retrieves an item from document of file storage using the provided Info. If an item is found it returns an io.ReadSeeker containing the result.

func (Conn) ReadInfo

func (c Conn) ReadInfo(info *core.Info) error

ReadInfo will retrieve the metadata object for specified item. If metadata is found the info reference will be updated with the retrieved information. If not an error will be returned.

func (Conn) Update

func (c Conn) Update(info *core.Info, r io.Reader) error

Update writes the readers contents to the item referenced in the info. When updating a previously deleted item the delete time will be reset and content will be re-inserted in the namespace defined by the info object.

func (Conn) WriteInfo

func (c Conn) WriteInfo(info *core.Info) error

WriteInfo will commit the info object to the designated info collection. if for some reason write should fail an error is returned to the caller.

type Driver

type Driver struct{}

Driver is a placeholder struct used to implement the driver logic defined in the npolar/api/core(https://gitlab.com/npolar/api/core) package.

func (Driver) Open

func (m Driver) Open(st core.StorageType, opts json.RawMessage) (core.Conn, error)

Open a new MongoDB connection and do initial configuration based on the StorageType and opts provided.

type IterReader

type IterReader struct {
	*mgo.Iter
	// contains filtered or unexported fields
}

IterReader implements an io.Reader interface for mgo.Iter

func NewIterReader

func NewIterReader(i *mgo.Iter) *IterReader

NewIterReader creates a new *IterReader for the provided mgo.Iter reference.

func (*IterReader) Read

func (ir *IterReader) Read(b []byte) (n int, err error)

Read data from the mgo.Iter into the byte slice provided.

Jump to

Keyboard shortcuts

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