Namespace Go
Namespace Go
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
package command
import (
"errors"
"strings"
)
return Namespace{
DB: name[:index],
Collection: name[index+1:],
}
}
// FullName returns the full namespace string, which is the result of joining the
database
// name and the collection name with a "." character.
func (ns *Namespace) FullName() string {
return strings.Join([]string{ns.DB, ns.Collection}, ".")
}
return ns.validateCollection()
}
// validateDB ensures the database name is not an empty string, contain a ".",
// or contain a " ".
func (ns *Namespace) validateDB() error {
if ns.DB == "" {
return errors.New("database name cannot be empty")
}
if strings.Contains(ns.DB, " ") {
return errors.New("database name cannot contain ' '")
}
if strings.Contains(ns.DB, ".") {
return errors.New("database name cannot contain '.'")
}
return nil
}
return nil
}