|
|
|
@@ -0,0 +1,68 @@
|
|
|
|
|
package core
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"errors"
|
|
|
|
|
"os"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
|
|
|
|
|
"github.com/google/uuid"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// ExoBasePath is the base path to the exocortex data stores.
|
|
|
|
|
var ExoBasePath = filepath.Join(os.Getenv("HOME"), "exo")
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
// ValueTypeUnspecified is used when the value type hasn't been explicitly
|
|
|
|
|
// set. It should be interpreted as a string in the absence of further
|
|
|
|
|
// information.
|
|
|
|
|
ValueTypeUnspecified = "UNSPECIFIED"
|
|
|
|
|
|
|
|
|
|
// ValueTypeString is used when the value type should be explicitly
|
|
|
|
|
// interpreted as a string.
|
|
|
|
|
ValueTypeString = "String"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// For the sake of storage, values are stored as strings; associate type
|
|
|
|
|
// information so that interested consumers can handle correctly.
|
|
|
|
|
type Value struct {
|
|
|
|
|
Contents string
|
|
|
|
|
Type string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Val creates a new Value with an unspecified type.
|
|
|
|
|
func Val(contents string) Value {
|
|
|
|
|
return Value{
|
|
|
|
|
Contents: contents,
|
|
|
|
|
Type: ValueTypeUnspecified,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Vals creates a new Value with a string type.
|
|
|
|
|
func Vals(contents string) Value {
|
|
|
|
|
return Value{
|
|
|
|
|
Contents: contents,
|
|
|
|
|
Type: ValueTypeString,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Metadata holds additional information that isn't explicitly part of a data
|
|
|
|
|
// definition.
|
|
|
|
|
type Metadata map[string]Value
|
|
|
|
|
|
|
|
|
|
// UUID returns a new UUID or panics.
|
|
|
|
|
func UUID() string {
|
|
|
|
|
return uuid.NewString()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ErrNoID is returned when a lookup is done on a struct that has no
|
|
|
|
|
// identifier attached..
|
|
|
|
|
var ErrNoID = errors.New("missing UUID identifier")
|
|
|
|
|
|
|
|
|
|
func MapFromList(list []string) map[string]bool {
|
|
|
|
|
m := map[string]bool{}
|
|
|
|
|
for _, s := range list {
|
|
|
|
|
m[s] = true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return m
|
|
|
|
|
}
|