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 ¶
- type Conn
- func (c Conn) Close() error
- func (c Conn) Create(info *core.Info, r io.Reader) error
- func (c Conn) Delete(info *core.Info) error
- func (c Conn) Formats() []string
- func (c Conn) InfoList(info *core.Info, opts *core.RequestOptions) (io.Reader, error)
- func (c Conn) NewWriteCloser(info *core.Info) (io.WriteCloser, error)
- func (c Conn) Read(info *core.Info, ctx context.Context) (io.ReadSeeker, error)
- func (c Conn) ReadInfo(info *core.Info) error
- func (c Conn) Update(info *core.Info, r io.Reader) error
- func (c Conn) WriteInfo(info *core.Info) error
- type Driver
- type IterReader
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.
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 ¶
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.