dsi

package
v0.0.0-...-cbce884 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2020 License: GPL-3.0 Imports: 4 Imported by: 0

README

Data Source Interfaces

This package contains the golang interface that exposes the required functions for Machinable. The purpose of this package is to abstract the database solution used to store the Machinable data. Currently, Machinable only supports a MongoDB a driver, but any database solution could be supported with the correct dsi driver.

Refer to the Datastore interface if you would like to write a new Machinable DSI driver.

Errors

Datastore errors are returned as the custom DatastoreError type. This type implements the Error function so it can be used as typical golang errors. However, DatastoreError also exposts a Code function which attempts to translate the "type" of error to a HTTP status code. The purpose of this is to reduce the work the handlers have to do to return an appropriate status code to the user if an error occurs.

Documentation

Index

Constants

View Source
const (
	// JSONIDKey is the key of the id returned in the JSON response
	JSONIDKey = "id"
	// DocumentIDKey is the key of ids in mongodb
	DocumentIDKey = "_id"
	// LimitKey is used for paginating HTTP requests
	LimitKey = "_limit"
	// OffsetKey is used for paginating HTTP requests
	OffsetKey = "_offset"
	// SortKey is used for sorting the query by a field
	SortKey = "_sort"
	// RelationKey is used for relations
	RelationKey = "_relation"
	// MetadataKey is the key used to store internal metadata for an object
	MetadataKey         = "_metadata"
	MetadataCreated     = "_metadata.created"
	MetadataCreator     = "_metadata.creator"
	MetadataCreatorType = "_metadata.creator_type"

	// MaxRecursion is the maximum amount of levels allowed in a JSON object (array and objects)
	MaxRecursion = 8
)

Variables

View Source
var MaxLengthOfCollectionInfo = 12

MaxLengthOfCollectionInfo is the maximum character length of collection/resource names and paths

View Source
var ValidPathFormat = regexp.MustCompile(`^[a-zA-Z0-9_-]*$`)

ValidPathFormat is the regular expression used to validate resource path names, collection names, and project slugs

Functions

func CastInterfaceToType

func CastInterfaceToType(typ string, value string) (interface{}, error)

CastInterfaceToType returns the interface with a proper type

func ContainsReservedField

func ContainsReservedField(doc map[string]interface{}) error

ContainsReservedField checks for reserved fields in a map[string]whatever

func ReservedField

func ReservedField(a string) bool

ReservedField returns true if the string is a reserved field key

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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