Documentation ¶
Index ¶
- Constants
- Variables
- func BuildUpdateOpSet() map[string]struct{}
- func CheckObjectNonEmpty(obj interface{}) bool
- func Mapify(d bson.D) bson.M
- func MapifyWithOp(d bson.D, m bson.M) bson.M
- func SetContain(m map[string]struct{}, op string) bool
- func SetValue(m bson.M, key []string, v interface{}) error
- func ToBsonD(m bson.M) bson.D
- func Validate(ctx context.Context, obj bson.D, fields map[string]CollectionField, ...) error
- func WalkCollectionFields(fields map[string]CollectionField, fn WalkCollectionFieldsFunc) error
- type BSONType
- type ClusterSchema
- type Collection
- type CollectionField
- type Database
- type SchemaLoader
- type SchemaPlugin
- type SchemaPluginConfig
- type SchemaQuerier
- type SchemaValidator
- type WalkCollectionFieldsFunc
Constants ¶
const (
Name = "schema"
)
Variables ¶
var OpMap = BuildUpdateOpSet()
Functions ¶
func BuildUpdateOpSet ¶ added in v0.0.2
func BuildUpdateOpSet() map[string]struct{}
func CheckObjectNonEmpty ¶ added in v0.0.2
func CheckObjectNonEmpty(obj interface{}) bool
func MapifyWithOp ¶ added in v0.0.2
Map creates a map from the elements of the D with operator It makes additional process for arrays
func SetContain ¶ added in v0.0.2
func Validate ¶
func Validate(ctx context.Context, obj bson.D, fields map[string]CollectionField, denyUnknownFields, isUpdate bool) error
Validate checks datatype aganst CollectionField It validates either Insert or Update TODO: remove the .Map()?
func WalkCollectionFields ¶
func WalkCollectionFields(fields map[string]CollectionField, fn WalkCollectionFieldsFunc) error
Types ¶
type BSONType ¶
type BSONType string
const ( // BSON types, not all of them supported yet. INT BSONType = "int" INT_ARRAY BSONType = "[]int" LONG BSONType = "long" LONG_ARRAY BSONType = "[]long" DOUBLE BSONType = "double" DOUBLE_ARRAY BSONType = "[]double" STRING BSONType = "string" STRING_ARRAY BSONType = "[]string" OBJECT BSONType = "object" OBJECT_ARRAY BSONType = "[]object" BIN_DATA BSONType = "binData" BIN_DATA_ARRAY BSONType = "[]binData" OBJECT_ID BSONType = "objectID" OBJECT_ID_ARRAY BSONType = "[]objectID" BOOL BSONType = "bool" BOOL_ARRAY BSONType = "[]bool" DATE BSONType = "date" DATE_ARRAY BSONType = "[]date" NULL BSONType = "null" REGEX BSONType = "regex" DECIMAL128 BSONType = "decimal" SKIP_SCHEMA_ANNOTATION = "skipSchema" )
type ClusterSchema ¶
type ClusterSchema struct { MongosEndpoint string `json:"mongosEndpoint"` Annotations map[string]string `json:"annotations,omitempty"` Databases map[string]Database `json:"dbs"` DenyUnknownDatabases bool `json:"denyUnknownDatabases,omitempty"` }
func (*ClusterSchema) UnmarshalJSON ¶
func (s *ClusterSchema) UnmarshalJSON(data []byte) error
func (*ClusterSchema) ValidateInsert ¶
func (s *ClusterSchema) ValidateInsert(ctx context.Context, database, collection string, obj bson.D) error
ValidateInsert will validate the schema of the passed in object.
func (*ClusterSchema) ValidateUpdate ¶
func (s *ClusterSchema) ValidateUpdate(ctx context.Context, database, collection string, obj bson.D, upsert bool) error
ValidateUpdate will validate the schema of the passed in object.
type Collection ¶
type Collection struct { Annotations map[string]string `json:"annotations,omitempty"` // All the columns in this table Fields map[string]CollectionField `json:"fields"` // Whether we should strictly enforce fields or allow others DenyUnknownFields bool `json:"denyUnknownFields,omitempty"` // Whether we should enforce schema check for this collection EnforceSchema bool `json:"enforceSchema,omitempty"` }
func (*Collection) GetField ¶
func (c *Collection) GetField(names ...string) *CollectionField
func (*Collection) ValidateInsert ¶
ValidateInsert will validate the schema of the passed in object.
func (*Collection) ValidateUpdate ¶
ValidateUpdate will validate the schema of the passed in object.
type CollectionField ¶
type CollectionField struct { Name string `json:"alias,omitempty"` Type BSONType `json:"type"` Annotations map[string]string `json:"annotations,omitempty"` // Various configuration options Required bool `json:"required,omitempty"` // Field is a array type IsArray bool // Optional subfields SubFields map[string]CollectionField `json:"subfields,omitempty"` // contains filtered or unexported fields }
func (*CollectionField) Validate ¶
func (c *CollectionField) Validate(ctx context.Context, v interface{}, denyUnknownFields, isUpdate bool) error
ValidateInsert will validate the schema of the passed in object.
func (*CollectionField) ValidateElement ¶
func (c *CollectionField) ValidateElement(ctx context.Context, d interface{}, validateType BSONType) error
Validate elements type inside an array
type Database ¶
type Database struct { Annotations map[string]string `json:"annotations,omitempty"` Collections map[string]Collection `json:"collections"` DenyUnknownCollections bool `json:"denyUnknownCollections,omitempty"` }
func (*Database) ValidateInsert ¶
ValidateInsert will validate the schema of the passed in object.
type SchemaLoader ¶
type SchemaLoader interface { // Load returns a bool (whether something was loaded) + error Load(ctx context.Context, glob string) error // Querier returns a querier of the current loaded config. The // returned querier must provide a consistent view over the data // (this way we get consistent schema enforcement throughout // all calls in a single request) Querier() SchemaQuerier }
type SchemaPlugin ¶
type SchemaPlugin struct {
// contains filtered or unexported fields
}
This is a plugin that handles sending the request to the acutual downstream mongo
func (*SchemaPlugin) Configure ¶
func (p *SchemaPlugin) Configure(d bson.D) error
Configure configures this plugin with the given configuration object. Returns an error if the configuration is invalid for the plugin.
func (*SchemaPlugin) GetSchema ¶
func (p *SchemaPlugin) GetSchema() *ClusterSchema
func (*SchemaPlugin) LoadSchema ¶
func (p *SchemaPlugin) LoadSchema() (err error)
func (*SchemaPlugin) Name ¶
func (p *SchemaPlugin) Name() string
type SchemaPluginConfig ¶
type SchemaQuerier ¶
type SchemaQuerier interface { SchemaValidator }
type SchemaValidator ¶
type SchemaValidator interface { // ValidateInsert will validate the schema of the passed in object. ValidateInsert(ctx context.Context, database, collection string, obj bson.D) error // ValidateUpdate will validate the schema of the passed in object. ValidateUpdate(ctx context.Context, database, collection string, obj bson.D) error }
type WalkCollectionFieldsFunc ¶
type WalkCollectionFieldsFunc func(string, *CollectionField) error