Documentation ¶
Index ¶
- Constants
- Variables
- func AbstractToModels(reg *Registry, abs string) (*GroupModel, *ResourceModel)
- func AnyToUInt(val any) (int, error)
- func ConvertString(val string, toType string) (any, bool)
- func CreateDB(name string) error
- func DBExists(name string) bool
- func DeleteDB(name string) error
- func Do(tx *Tx, cmd string, args ...interface{}) error
- func DoCount(tx *Tx, num int, cmd string, args ...interface{}) error
- func DoOne(tx *Tx, cmd string, args ...interface{}) error
- func DoOneTwo(tx *Tx, cmd string, args ...interface{}) error
- func DoZeroOne(tx *Tx, cmd string, args ...interface{}) error
- func DoZeroTwo(tx *Tx, cmd string, args ...interface{}) error
- func DumpTXs()
- func EnsureAttrOK(userAttr *Attribute, specAttr *Attribute) error
- func GenerateQuery(reg *Registry, what string, paths []string, filters [][]*FilterExpr) (string, []interface{}, error)
- func GetGroupModelInlines(gm *GroupModel) []string
- func GetJSONPointer(data any, path string) (any, error)
- func GetModelInlines(m *Model) []string
- func GetRegistryNames() []string
- func GetResourceModelInlines(rm *ResourceModel) []string
- func GetStack() []string
- func GetVersionModelInlines(rm *ResourceModel) []string
- func GoToOurType(val any) string
- func HTMLify(r *http.Request, buf []byte) []byte
- func HTTPDelete(info *RequestInfo) error
- func HTTPDeleteGroups(info *RequestInfo) error
- func HTTPDeleteResources(info *RequestInfo) error
- func HTTPDeleteVersions(info *RequestInfo) error
- func HTTPGETContent(info *RequestInfo) error
- func HTTPGETModel(info *RequestInfo) error
- func HTTPGet(info *RequestInfo) error
- func HTTPPUTModel(info *RequestInfo) error
- func HTTPPutPost(info *RequestInfo) error
- func HTTPSetDefaultVersionID(info *RequestInfo) error
- func ImportTraverse(importArgs ImportArgs, data map[string]any) error
- func IncomingObj2Map(incomingObj Object) (map[string]Object, error)
- func IsNil(a any) bool
- func IsOfType(val any, attrType string) bool
- func IsScalar(daType string) bool
- func IsString(daType string) bool
- func IsValidAttributeName(name string) bool
- func IsValidMapKey(key string) bool
- func JSONEscape(obj interface{}) string
- func Keys(m interface{}) []string
- func KindIsScalar(k reflect.Kind) bool
- func LineNum(buf []byte, pos int) int
- func Match(pattern string, str string) bool
- func MaterializeProp(current any, pp *PropPath, val any, prev *PropPath) (any, error)
- func Model2xRegistryJson(m *Model, format string) ([]byte, error)
- func Must(err error)
- func NestedGetProp(obj any, pp *PropPath, prev *PropPath) (any, bool, error)
- func NewUUID() string
- func NotNilBoolDef(val *any, def bool) bool
- func NotNilInt(val *any) int
- func NotNilIntDef(val *any, def int) int
- func NotNilString(val *any) string
- func ObjectGetProp(obj any, pp *PropPath) (any, bool, error)
- func ObjectSetProp(obj map[string]any, pp *PropPath, val any) error
- func OneLine(buf []byte) []byte
- func OpenDB(name string) error
- func PanicIf(b bool, msg string, args ...any)
- func Panicf(msg string, args ...any)
- func Path2Abstract(path string) string
- func PrepUpdateEntity(e *Entity) error
- func ProcessImports(file string, buf []byte, localFiles bool) ([]byte, error)
- func ProcessSetDefaultVersionIDFlag(info *RequestInfo, resource *Resource, version *Version) error
- func PtrBool(b bool) *bool
- func PtrBoolDef(val *any, def bool) *bool
- func PtrIntDef(val *any, def int) *int
- func RegHTMLify(r *http.Request, buf []byte) []byte
- func RegisterModelSerializer(name string, sm ModelSerializer)
- func RemoveComments(buf []byte) []byte
- func RemoveProps(buf []byte) []byte
- func ResetMap[M ~map[K]V, K comparable, V any](m M, key K, oldVal V)
- func ResolvePath(baseFile string, next string) string
- func SerializeQuery(info *RequestInfo, paths []string, what string, filters [][]*FilterExpr) error
- func ShowStack()
- func SortedKeys(m interface{}) []string
- func SplitFragement(str string) (string, string)
- func SubQuery(query string, args []interface{}) string
- func ToJSON(obj interface{}) string
- func ToJSONOneLine(obj interface{}) string
- func Unmarshal(buf []byte, v any) error
- type AddType
- type AttrInternals
- type Attribute
- func (a *Attribute) AddAttr(name, daType string) (*Attribute, error)
- func (a *Attribute) AddAttrArray(name string, item *Item) (*Attribute, error)
- func (a *Attribute) AddAttrMap(name string, item *Item) (*Attribute, error)
- func (a *Attribute) AddAttrObj(name string) (*Attribute, error)
- func (a *Attribute) AddAttribute(attr *Attribute) (*Attribute, error)
- func (a *Attribute) GetStrict() bool
- func (a *Attribute) InLevel(level int) bool
- func (a *Attribute) IsScalar() bool
- func (a *Attribute) SetRegistry(reg *Registry)
- type Attributes
- func (attrs Attributes) AddIfValuesAttributes(obj map[string]any)
- func (attrs Attributes) ConvertStrings(obj Object)
- func (attrs Attributes) MarshalJSON() ([]byte, error)
- func (attrs Attributes) SetRegistry(reg *Registry)
- func (attrs Attributes) SetSpecPropsFields()
- func (attrs Attributes) Verify(ld *LevelData) error
- type BufferedWriter
- type DefaultWriter
- type DiscardWriter
- type Entity
- func (e *Entity) AddCalcProps(info *RequestInfo) map[string]any
- func (e *Entity) Get(path string) any
- func (e *Entity) GetAsInt(path string) int
- func (e *Entity) GetAsString(path string) string
- func (e *Entity) GetAttributes(obj Object) Attributes
- func (e *Entity) GetBaseAttributes() Attributes
- func (e *Entity) GetCollections() [][2]string
- func (e *Entity) GetModels() (*GroupModel, *ResourceModel)
- func (e *Entity) GetPP(pp *PropPath) any
- func (e *Entity) JustSet(pp *PropPath, val any) error
- func (e *Entity) Refresh() error
- func (e *Entity) RemoveCollections(obj Object)
- func (e *Entity) Save() error
- func (e *Entity) SerializeProps(info *RequestInfo, ...) error
- func (e *Entity) SetCommit(path string, val any) error
- func (e *Entity) SetDBProperty(pp *PropPath, val any) error
- func (e *Entity) SetFromDBName(name string, val *string, propType string) error
- func (e *Entity) SetPP(pp *PropPath, val any) error
- func (e *Entity) SetSave(path string, val any) error
- func (e *Entity) Validate() error
- func (e *Entity) ValidateAndSave() error
- func (e *Entity) ValidateArray(val any, item *Item, path *PropPath) error
- func (e *Entity) ValidateAttribute(val any, attr *Attribute, path *PropPath) error
- func (e *Entity) ValidateMap(val any, item *Item, path *PropPath) error
- func (e *Entity) ValidateObject(val any, origAttrs Attributes, path *PropPath) error
- func (e *Entity) ValidateScalar(val any, attr *Attribute, path *PropPath) error
- type EntitySetter
- type FilterExpr
- type FilterPProf
- type Group
- func (g *Group) AddResource(rType string, id string, vID string) (*Resource, error)
- func (g *Group) AddResourceWithObject(rType string, id string, vID string, obj Object, doChildren bool, ...) (*Resource, error)
- func (g *Group) Delete() error
- func (g *Group) FindResource(rType string, id string, anyCase bool) (*Resource, error)
- func (g *Group) Get(name string) any
- func (g *Group) JustSet(name string, val any) error
- func (g *Group) SetCommit(name string, val any) error
- func (g *Group) SetSave(name string, val any) error
- func (g *Group) UpsertResource(rType string, id string, vID string) (*Resource, bool, error)
- func (g *Group) UpsertResourceWithObject(rType string, id string, vID string, obj Object, addType AddType, ...) (*Resource, bool, error)
- type GroupModel
- func (gm *GroupModel) AddAttr(name, daType string) (*Attribute, error)
- func (gm *GroupModel) AddAttrArray(name string, item *Item) (*Attribute, error)
- func (gm *GroupModel) AddAttrMap(name string, item *Item) (*Attribute, error)
- func (gm *GroupModel) AddAttrObj(name string) (*Attribute, error)
- func (gm *GroupModel) AddAttribute(attr *Attribute) (*Attribute, error)
- func (gm *GroupModel) AddResourceModel(plural string, singular string, maxVersions int, setVerId bool, ...) (*ResourceModel, error)
- func (gm *GroupModel) AddResourceModelFull(rm *ResourceModel) (*ResourceModel, error)
- func (gm *GroupModel) AddResourceModelSimple(plural, singular string) (*ResourceModel, error)
- func (gm *GroupModel) DelAttribute(name string) error
- func (gm *GroupModel) Delete() error
- func (gm *GroupModel) GetBaseAttributes() Attributes
- func (gm *GroupModel) Save() error
- func (gm *GroupModel) SetRegistry(reg *Registry)
- func (gm *GroupModel) Verify(gmName string) error
- type HTTPWriter
- type IDArray
- type IDEntry
- type IfValue
- type IfValues
- type ImportArgs
- type Item
- func (i *Item) AddAttr(name, daType string) (*Attribute, error)
- func (i *Item) AddAttrArray(name string, item *Item) (*Attribute, error)
- func (i *Item) AddAttrMap(name string, item *Item) (*Attribute, error)
- func (i *Item) AddAttrObj(name string) (*Attribute, error)
- func (i *Item) AddAttribute(attr *Attribute) (*Attribute, error)
- func (i *Item) DelAttribute(name string) error
- func (i *Item) SetItem(item *Item) error
- func (i *Item) SetRegistry(reg *Registry)
- func (item *Item) Verify(path *PropPath) error
- type JsonWriter
- func (jw *JsonWriter) Indent()
- func (jw *JsonWriter) LoadCollections(level int)
- func (jw *JsonWriter) NextEntity() (*Entity, error)
- func (jw *JsonWriter) OptPrintf(format string, args ...any)
- func (jw *JsonWriter) Outdent()
- func (jw *JsonWriter) Print(str string)
- func (jw *JsonWriter) Printf(format string, args ...any)
- func (jw *JsonWriter) WriteCollection() (int, error)
- func (jw *JsonWriter) WriteCollectionHeader(extra string) (string, error)
- func (jw *JsonWriter) WriteEntity() error
- func (jw *JsonWriter) WritePostCollections(extra string, level int) string
- func (jw *JsonWriter) WritePreCollections(extra string, plural string, level int) string
- type LevelData
- type Model
- func (m *Model) AddAttr(name, daType string) (*Attribute, error)
- func (m *Model) AddAttrArray(name string, item *Item) (*Attribute, error)
- func (m *Model) AddAttrMap(name string, item *Item) (*Attribute, error)
- func (m *Model) AddAttrObj(name string) (*Attribute, error)
- func (m *Model) AddAttribute(attr *Attribute) (*Attribute, error)
- func (m *Model) AddGroupModel(plural string, singular string) (*GroupModel, error)
- func (m *Model) AddSchema(schema string) error
- func (m *Model) ApplyNewModel(newM *Model) error
- func (m *Model) DelAttribute(name string) error
- func (m *Model) DelSchema(schema string) error
- func (m *Model) FindGroupModel(gTypePlural string) *GroupModel
- func (m *Model) GetBaseAttributes() Attributes
- func (m *Model) Save() error
- func (m *Model) SetPointers()
- func (m *Model) SetSchemas(schemas []string) error
- func (m *Model) Verify() error
- func (m *Model) VerifyAndSave() error
- type ModelSerializer
- type Object
- type PageWriter
- type PropPart
- type PropPath
- func MustPropPathFromDB(str string) *PropPath
- func MustPropPathFromPath(str string) *PropPath
- func MustPropPathFromUI(str string) *PropPath
- func NewPP() *PropPath
- func NewPPP(prop string) *PropPath
- func PropPathFromDB(str string) (*PropPath, error)
- func PropPathFromPath(str string) (*PropPath, error)
- func PropPathFromUI(str string) (*PropPath, error)
- func (pp *PropPath) Abstract() string
- func (pp *PropPath) Append(addPP *PropPath) *PropPath
- func (pp *PropPath) Clone() *PropPath
- func (pp *PropPath) DB() string
- func (pp *PropPath) Equals(other *PropPath) bool
- func (pp *PropPath) First() *PropPath
- func (pp *PropPath) HasPrefix(other *PropPath) bool
- func (pp *PropPath) I(i int) *PropPath
- func (pp *PropPath) Index(i int) *PropPath
- func (pp *PropPath) IsIndexed() int
- func (pp *PropPath) Len() int
- func (pp *PropPath) Next() *PropPath
- func (pp *PropPath) P(prop string) *PropPath
- func (pp *PropPath) Path() string
- func (pp *PropPath) Prop(prop string) *PropPath
- func (pp *PropPath) Top() string
- func (pp *PropPath) UI() string
- type RegOpt
- type Registry
- func (reg *Registry) AddGroup(gType string, id string) (*Group, error)
- func (reg *Registry) AddGroupWithObject(gType string, id string, obj Object, doChildren bool) (*Group, error)
- func (r *Registry) Commit() error
- func (reg *Registry) Delete() error
- func (reg *Registry) FindGroup(gType string, id string, anyCase bool) (*Group, error)
- func (reg *Registry) Get(name string) any
- func (reg *Registry) JustSet(name string, val any) error
- func (reg *Registry) LoadModel() *Model
- func (reg *Registry) LoadModelFromFile(file string) error
- func (r *Registry) Rollback() error
- func (reg *Registry) SetCommit(name string, val any) error
- func (reg *Registry) SetSave(name string, val any) error
- func (reg *Registry) Update(obj Object, addType AddType, doChildren bool) error
- func (reg *Registry) UpsertGroup(gType string, id string) (*Group, bool, error)
- func (reg *Registry) UpsertGroupWithObject(gType string, id string, obj Object, addType AddType, doChildren bool) (*Group, bool, error)
- type RequestInfo
- func (ri *RequestInfo) AddHeader(name, value string)
- func (info *RequestInfo) AddInline(path string) error
- func (info *RequestInfo) IsInlineSet(entityPath string) bool
- func (info *RequestInfo) ParseFilters() error
- func (info *RequestInfo) ParseRequestURL() error
- func (info *RequestInfo) ShouldInline(entityPath string) bool
- func (ri *RequestInfo) Write(b []byte) (int, error)
- type Resource
- func (r *Resource) AddVersion(id string) (*Version, error)
- func (r *Resource) AddVersionWithObject(id string, obj Object) (*Version, error)
- func (r *Resource) Delete() error
- func (r *Resource) EnsureMaxVersions() error
- func (r *Resource) FindVersion(id string, anyCase bool) (*Version, error)
- func (r *Resource) Get(name string) any
- func (r *Resource) GetDefault() (*Version, error)
- func (r *Resource) GetVersionIDs() ([]string, error)
- func (r *Resource) GetVersions() ([]*Version, error)
- func (r *Resource) JustSet(name string, val any) error
- func (r *Resource) SetCommit(name string, val any) error
- func (r *Resource) SetDefault(newDefault *Version) error
- func (r *Resource) SetSave(name string, val any) error
- func (r *Resource) UpsertVersion(id string) (*Version, bool, error)
- func (r *Resource) UpsertVersionWithObject(id string, obj Object, addType AddType) (*Version, bool, error)
- type ResourceModel
- func (rm *ResourceModel) AddAttr(name, daType string) (*Attribute, error)
- func (rm *ResourceModel) AddAttrArray(name string, item *Item) (*Attribute, error)
- func (rm *ResourceModel) AddAttrMap(name string, item *Item) (*Attribute, error)
- func (rm *ResourceModel) AddAttrObj(name string) (*Attribute, error)
- func (rm *ResourceModel) AddAttribute(attr *Attribute) (*Attribute, error)
- func (rm *ResourceModel) AddTypeMap(ct string, format string) error
- func (rm *ResourceModel) DelAttribute(name string) error
- func (rm *ResourceModel) Delete() error
- func (rm *ResourceModel) GetBaseAttributes() Attributes
- func (rm *ResourceModel) GetHasDocument() bool
- func (rm *ResourceModel) GetSetStickyDefault() bool
- func (rm *ResourceModel) GetSetVersionId() bool
- func (rm *ResourceModel) MapContentType(ct string) string
- func (rm *ResourceModel) RemoveTypeMap(ct string) error
- func (rm *ResourceModel) Save() error
- func (rm *ResourceModel) SetMaxVersions(maxV int) error
- func (rm *ResourceModel) SetRegistry(reg *Registry)
- func (rm *ResourceModel) SetSetStickyDefault(val bool) error
- func (r *ResourceModel) UnmarshalJSON(data []byte) error
- func (rm *ResourceModel) Verify(rmName string) error
- func (rm *ResourceModel) VerifyAndSave() error
- func (rm *ResourceModel) VerifyData() error
- type Result
- type Server
- type Tx
- func (tx *Tx) AddVersion(v *Version)
- func (tx *Tx) Commit() error
- func (tx *Tx) Conditional(err error) error
- func (tx *Tx) GetVersion(r *Resource, vID string) *Version
- func (tx *Tx) NewTx() error
- func (tx *Tx) Prepare(query string) (*sql.Stmt, error)
- func (tx *Tx) Rollback() error
- func (tx *Tx) String() string
- type Version
Constants ¶
const ANY = "any"
Attribute types
const ARRAY = "array"
const BOOLEAN = "boolean"
const DB_IN = ','
If DB_IN changes then DefaultProps in init.sql needs to change too
const DB_INDEX = '#'
const DECIMAL = "decimal"
const HASDOCUMENT = true
const INTEGER = "integer"
const IN_CHAR = '.'
const IN_STR = string(IN_CHAR)
const MAP = "map"
const MAXVERSIONS = 0
const OBJECT = "object"
const READONLY = false
const SETSTICKYDEFAULT = true
const SETVERSIONID = true
const SPECVERSION = "0.5"
const STRICT = true
Model attribute default values
const STRING = "string"
const TIMESTAMP = "timestamp"
const UINTEGER = "uinteger"
const URI = "uri"
const URI_REFERENCE = "urireference"
const URI_TEMPLATE = "uritemplate"
const URL = "url"
const UX_IN = '.'
const XREGSCHEMA = "xRegistry-json"
Variables ¶
var DB *sql.DB
var DBHOST = "localhost"
var DBPASSWORD = "password"
var DBPORT = "3306"
var DBUSER = "root"
var DB_InitFunc func()
var DB_Name = ""
var DefaultDiscardWriter = &DiscardWriter{}
var DefaultRegDbSID string
var DefinedTypes = map[string]bool{ ANY: true, BOOLEAN: true, DECIMAL: true, INTEGER: true, UINTEGER: true, ARRAY: true, MAP: true, OBJECT: true, STRING: true, TIMESTAMP: true, URI: true, URI_REFERENCE: true, URI_TEMPLATE: true, URL: true}
var JPtrEsc0 = regexp.MustCompile(`~0`)
var JPtrEsc1 = regexp.MustCompile(`~1`)
var ModelSerializers = map[string]ModelSerializer{}
var OrderedSpecProps = []*Attribute{ { Name: "specversion", Type: STRING, ReadOnly: true, Immutable: true, ServerRequired: true, // contains filtered or unexported fields }, { Name: "id", Type: STRING, Immutable: true, ServerRequired: true, // contains filtered or unexported fields }, { Name: "name", Type: STRING, // contains filtered or unexported fields }, { Name: "epoch", Type: UINTEGER, ServerRequired: true, // contains filtered or unexported fields }, { Name: "self", Type: URL, ReadOnly: true, ServerRequired: true, // contains filtered or unexported fields }, { Name: "isdefault", Type: BOOLEAN, ReadOnly: true, // contains filtered or unexported fields }, { Name: "stickydefaultversion", Type: BOOLEAN, ReadOnly: true, // contains filtered or unexported fields }, { Name: "defaultversionid", Type: STRING, ReadOnly: true, // contains filtered or unexported fields }, { Name: "defaultversionurl", Type: URL, ReadOnly: true, // contains filtered or unexported fields }, { Name: "description", Type: STRING, // contains filtered or unexported fields }, { Name: "documentation", Type: URL, // contains filtered or unexported fields }, { Name: "labels", Type: MAP, Item: &Item{ Type: STRING, }, // contains filtered or unexported fields }, { Name: "origin", Type: URI, // contains filtered or unexported fields }, { Name: "createdat", Type: TIMESTAMP, // contains filtered or unexported fields }, { Name: "modifiedat", Type: TIMESTAMP, // contains filtered or unexported fields }, { Name: "contenttype", Type: STRING, // contains filtered or unexported fields }, { Name: "model", Type: OBJECT, ReadOnly: true, Attributes: Attributes{ "*": &Attribute{ Name: "*", Type: ANY, }, }, // contains filtered or unexported fields }, }
This allows for us to choose the order and define custom logic per prop
var PProfFilter = &FilterPProf{}
var RegexpMapKey = regexp.MustCompile("^[a-z0-9][a-z0-9_.\\-]{0,62}$")
var RegexpPropName = regexp.MustCompile("^[a-z_][a-z0-9_./]{0,62}$")
var SpecProps = map[string]*Attribute{}
var TESTING = (os.Getenv("TESTING") != "")
var TXs = map[string]*Tx{}
Active transaction - mainly for debugging and testing
Functions ¶
func AbstractToModels ¶
func AbstractToModels(reg *Registry, abs string) (*GroupModel, *ResourceModel)
func EnsureAttrOK ¶
Make sure that the attribute doesn't deviate too much from the spec defined version of it. There's only so much that we allow the user to customize
func GenerateQuery ¶
func GetGroupModelInlines ¶
func GetGroupModelInlines(gm *GroupModel) []string
func GetModelInlines ¶
func GetRegistryNames ¶
func GetRegistryNames() []string
func GetResourceModelInlines ¶
func GetResourceModelInlines(rm *ResourceModel) []string
func GetVersionModelInlines ¶
func GetVersionModelInlines(rm *ResourceModel) []string
func GoToOurType ¶
func HTTPDelete ¶
func HTTPDelete(info *RequestInfo) error
func HTTPDeleteGroups ¶
func HTTPDeleteGroups(info *RequestInfo) error
func HTTPDeleteResources ¶
func HTTPDeleteResources(info *RequestInfo) error
func HTTPDeleteVersions ¶
func HTTPDeleteVersions(info *RequestInfo) error
func HTTPGETContent ¶
func HTTPGETContent(info *RequestInfo) error
func HTTPGETModel ¶
func HTTPGETModel(info *RequestInfo) error
func HTTPGet ¶
func HTTPGet(info *RequestInfo) error
func HTTPPUTModel ¶
func HTTPPUTModel(info *RequestInfo) error
func HTTPPutPost ¶
func HTTPPutPost(info *RequestInfo) error
func HTTPSetDefaultVersionID ¶
func HTTPSetDefaultVersionID(info *RequestInfo) error
func ImportTraverse ¶
func ImportTraverse(importArgs ImportArgs, data map[string]any) error
data is the current map to check for $import statements
func IsValidAttributeName ¶
func IsValidMapKey ¶
func JSONEscape ¶
func JSONEscape(obj interface{}) string
func KindIsScalar ¶
func MaterializeProp ¶
func Model2xRegistryJson ¶
The model serializer we use for the "xRegistry" schema format
func NestedGetProp ¶
Value, Found, Error
func NotNilBoolDef ¶
func NotNilIntDef ¶
func NotNilString ¶
func ObjectGetProp ¶
Value, Found, Error
func ObjectSetProp ¶
Given a PropPath and a value this will add the necessary golang data structures to 'obj' to materialize PropPath and set the appropriate fields to 'val'
func Path2Abstract ¶
func PrepUpdateEntity ¶
func ProcessSetDefaultVersionIDFlag ¶
func ProcessSetDefaultVersionIDFlag(info *RequestInfo, resource *Resource, version *Version) error
Process the ?setdefaultversionid query parameter "resource" is the resource we're processing "version" is the version that was processed
func PtrBoolDef ¶
func RegisterModelSerializer ¶
func RegisterModelSerializer(name string, sm ModelSerializer)
func RemoveComments ¶
func RemoveProps ¶
func ResetMap ¶
func ResetMap[M ~map[K]V, K comparable, V any](m M, key K, oldVal V)
Either delete or change the value of a map based on "oldVal" being nil or not
func ResolvePath ¶
func SerializeQuery ¶
func SerializeQuery(info *RequestInfo, paths []string, what string, filters [][]*FilterExpr) error
func SortedKeys ¶
func SortedKeys(m interface{}) []string
func SplitFragement ¶
func ToJSONOneLine ¶
func ToJSONOneLine(obj interface{}) string
Types ¶
type AttrInternals ¶
type AttrInternals struct {
// contains filtered or unexported fields
}
Defined a separate struct instead of just inlining these attributes so that we can just copy them over in one statement in SetSpecPropsFields() and so that if we add more we don't need to remember to update that func
type Attribute ¶
type Attribute struct { Registry *Registry `json:"-"` Name string `json:"name,omitempty"` Type string `json:"type,omitempty"` Description string `json:"description,omitempty"` Enum []any `json:"enum,omitempty"` // just scalars though Strict *bool `json:"strict,omitempty"` ReadOnly bool `json:"readonly,omitempty"` Immutable bool `json:"immutable,omitempty"` ClientRequired bool `json:"clientrequired,omitempty"` ServerRequired bool `json:"serverrequired,omitempty"` Default any `json:"default,omitempty"` Attributes Attributes `json:"attributes,omitempty"` // for Objs Item *Item `json:"item,omitempty"` // for maps & arrays IfValues IfValues `json:"ifValues,omitempty"` // Value // contains filtered or unexported fields }
Do not include "omitempty" on any attribute that has a default value that doesn't match golang's default value for that type. E.g. bool defaults to 'false', but Strict needs to default to 'true'. See the custome Unmarshal funcs in model.go for how we set those
func (*Attribute) AddAttrArray ¶
func (*Attribute) AddAttrMap ¶
func (*Attribute) AddAttribute ¶
func (*Attribute) SetRegistry ¶
type Attributes ¶
func (Attributes) AddIfValuesAttributes ¶
func (attrs Attributes) AddIfValuesAttributes(obj map[string]any)
This just does the top-level attributes with the assumption that we'll do the lower-level ones later on in Entity.ValidateObject
func (Attributes) ConvertStrings ¶
func (attrs Attributes) ConvertStrings(obj Object)
func (Attributes) MarshalJSON ¶
func (attrs Attributes) MarshalJSON() ([]byte, error)
To be picky, let's Marshal the list of attributes with Spec defined ones first, and then the extensions in alphabetical order
func (Attributes) SetRegistry ¶
func (attrs Attributes) SetRegistry(reg *Registry)
func (Attributes) SetSpecPropsFields ¶
func (attrs Attributes) SetSpecPropsFields()
Copy the internal data for spec defined properties so we can access that info directly from these Attributes instead of having to go back to the SpecProps stuff
func (Attributes) Verify ¶
func (attrs Attributes) Verify(ld *LevelData) error
type BufferedWriter ¶
type BufferedWriter struct { Info *RequestInfo OldWriter HTTPWriter Headers *map[string]string Buffer *bytes.Buffer }
func NewBufferedWriter ¶
func NewBufferedWriter(info *RequestInfo) *BufferedWriter
func (*BufferedWriter) AddHeader ¶
func (bw *BufferedWriter) AddHeader(name, value string)
func (*BufferedWriter) Done ¶
func (bw *BufferedWriter) Done()
type DefaultWriter ¶
type DefaultWriter struct {
Info *RequestInfo
}
func (*DefaultWriter) AddHeader ¶
func (dw *DefaultWriter) AddHeader(name, value string)
func (*DefaultWriter) Done ¶
func (dw *DefaultWriter) Done()
type DiscardWriter ¶
type DiscardWriter struct{}
func (*DiscardWriter) AddHeader ¶
func (dw *DiscardWriter) AddHeader(name, value string)
func (*DiscardWriter) Done ¶
func (dw *DiscardWriter) Done()
type Entity ¶
type Entity struct { Registry *Registry `json:"-"` DbSID string // Entity's SID Plural string UID string // Entity's UID Object map[string]any `json:"-"` NewObject map[string]any `json:"-"` // updated version, save() will store // These were added just for convenience and so we can use the same // struct for traversing the SQL results Level int // 0=registry, 1=group, 2=resource, 3=version Path string Abstract string EpochSet bool `json:"-"` // Has epoch been updated this transaction? // contains filtered or unexported fields }
func RawEntitiesFromQuery ¶
func RawEntityFromPath ¶
func (*Entity) AddCalcProps ¶
func (e *Entity) AddCalcProps(info *RequestInfo) map[string]any
This will add in the calculated properties into the entity. This will normally be called after a query using FullTree view and before we serialize the entity we need to add the non-DB-stored properties (meaning, the calculated ones. Note that we make a copy and don't touch the entity itself. Serializing an entity shouldn't have side-effects.
func (*Entity) GetAsString ¶
func (*Entity) GetAttributes ¶
func (e *Entity) GetAttributes(obj Object) Attributes
func (*Entity) GetBaseAttributes ¶
func (e *Entity) GetBaseAttributes() Attributes
Returns the initial set of attributes defined for the entity.
func (*Entity) GetCollections ¶
Array of plural/singular pairs
func (*Entity) GetModels ¶
func (e *Entity) GetModels() (*GroupModel, *ResourceModel)
func (*Entity) Refresh ¶
Update the entity's Object - not the other props in Entity. Similar to RawEntityFromPath
func (*Entity) RemoveCollections ¶
This will remove all Collection related attributes from the entity. While this is an Entity.Func, we allow callers to pass in the Object data to use instead of the e.Object/NewObject so that we'll use this Entity's Level (which tells us which collections it has), on the 'obj'. This is handy for cases where we need to remove the Resource's collections from a Version's Object - like on a PUT to /GROUPs/gID/RESOURECEs/rID where we're passing in what looks like a Resource entity, but we're really using it to create a Version
func (*Entity) SerializeProps ¶
func (e *Entity) SerializeProps(info *RequestInfo, fn func(*Entity, *RequestInfo, string, any, *Attribute) error) error
This is used to serialize an Entity regardless of the format. This will:
- Use AddCalcProps() to fill in any missing props (eg Entity's getFn())
- Call that passed-in 'fn' to serialize each prop but in the right order as defined by OrderedSpecProps
func (*Entity) SetCommit ¶
All in one: Set, Validate, Save to DB and Commit (or Rollback on error) Should never be used because the act of committing should be done by the caller once all of the changes are done. This is a holdover from before we had transaction support - once we're sure, delete it
func (*Entity) SetDBProperty ¶
This will save a single property/value in the DB. This assumes the caller is traversing the Object and splitting it into individual props
func (*Entity) SetFromDBName ¶
This is used to take a DB entry and update the current Entity's Object
func (*Entity) SetPP ¶
This is really just an internal Setter used for testing. It'sll set a property and then validate and save the entity in the DB
func (*Entity) Validate ¶
Doesn't fully validate in the sense that it'll assume read-only fields are not worth checking since the server generated them. This is mainly used for validating input from a client. NOTE!!! This isn't a read-only operation. Normally it would be, but to avoid traversing the entity more than once, we will tweak things if needed. For example, if a missing attribute has a Default value then we'll add it.
func (*Entity) ValidateAndSave ¶
func (*Entity) ValidateArray ¶
func (*Entity) ValidateAttribute ¶
func (*Entity) ValidateMap ¶
func (*Entity) ValidateObject ¶
func (e *Entity) ValidateObject(val any, origAttrs Attributes, path *PropPath) error
This should be called after all level-specific calculated properties have been removed - such as collections
type EntitySetter ¶
type FilterExpr ¶
type FilterPProf ¶
type FilterPProf struct {
// contains filtered or unexported fields
}
type Group ¶
func (*Group) AddResource ¶
func (*Group) AddResourceWithObject ¶
func (*Group) FindResource ¶
func (*Group) UpsertResource ¶
type GroupModel ¶
type GroupModel struct { SID string `json:"-"` Registry *Registry `json:"-"` Plural string `json:"plural"` Singular string `json:"singular"` Attributes Attributes `json:"attributes,omitempty"` Resources map[string]*ResourceModel `json:"resources,omitempty"` // Plural }
func (*GroupModel) AddAttrArray ¶
func (gm *GroupModel) AddAttrArray(name string, item *Item) (*Attribute, error)
func (*GroupModel) AddAttrMap ¶
func (gm *GroupModel) AddAttrMap(name string, item *Item) (*Attribute, error)
func (*GroupModel) AddAttrObj ¶
func (gm *GroupModel) AddAttrObj(name string) (*Attribute, error)
func (*GroupModel) AddAttribute ¶
func (gm *GroupModel) AddAttribute(attr *Attribute) (*Attribute, error)
func (*GroupModel) AddResourceModel ¶
func (gm *GroupModel) AddResourceModel(plural string, singular string, maxVersions int, setVerId bool, setStickyDefault bool, hasDocument bool) (*ResourceModel, error)
func (*GroupModel) AddResourceModelFull ¶
func (gm *GroupModel) AddResourceModelFull(rm *ResourceModel) (*ResourceModel, error)
func (*GroupModel) AddResourceModelSimple ¶
func (gm *GroupModel) AddResourceModelSimple(plural, singular string) (*ResourceModel, error)
func (*GroupModel) DelAttribute ¶
func (gm *GroupModel) DelAttribute(name string) error
func (*GroupModel) Delete ¶
func (gm *GroupModel) Delete() error
func (*GroupModel) GetBaseAttributes ¶
func (gm *GroupModel) GetBaseAttributes() Attributes
func (*GroupModel) Save ¶
func (gm *GroupModel) Save() error
func (*GroupModel) SetRegistry ¶
func (gm *GroupModel) SetRegistry(reg *Registry)
func (*GroupModel) Verify ¶
func (gm *GroupModel) Verify(gmName string) error
type HTTPWriter ¶
func DefaultHTTPWriter ¶
func DefaultHTTPWriter(info *RequestInfo) HTTPWriter
type IDArray ¶
type IDArray []IDEntry
func LoadIDList ¶
func LoadIDList(info *RequestInfo) (IDArray, error)
type IfValue ¶
type IfValue struct {
SiblingAttributes Attributes `json:"siblingAttributes,omitempty"`
}
type IfValues ¶
func (IfValues) SetRegistry ¶
type ImportArgs ¶
type Item ¶
type Item struct { Registry *Registry `json:"-"` Type string `json:"type,omitempty"` Attributes Attributes `json:"attributes,omitempty"` // when 'type'=obj Item *Item `json:"item,omitempty"` // when 'type'=map,array }
func NewItemArray ¶
func NewItemMap ¶
func NewItemObject ¶
func NewItemObject() *Item
func NewItemType ¶
func (*Item) AddAttrArray ¶
func (*Item) DelAttribute ¶
func (*Item) SetRegistry ¶
type JsonWriter ¶
type JsonWriter struct { Entity *Entity // Current row in the DB results // contains filtered or unexported fields }
func NewJsonWriter ¶
func NewJsonWriter(info *RequestInfo, results *Result) *JsonWriter
func (*JsonWriter) Indent ¶
func (jw *JsonWriter) Indent()
func (*JsonWriter) LoadCollections ¶
func (jw *JsonWriter) LoadCollections(level int)
func (*JsonWriter) NextEntity ¶
func (jw *JsonWriter) NextEntity() (*Entity, error)
func (*JsonWriter) OptPrintf ¶
func (jw *JsonWriter) OptPrintf(format string, args ...any)
func (*JsonWriter) Outdent ¶
func (jw *JsonWriter) Outdent()
func (*JsonWriter) Print ¶
func (jw *JsonWriter) Print(str string)
func (*JsonWriter) Printf ¶
func (jw *JsonWriter) Printf(format string, args ...any)
func (*JsonWriter) WriteCollection ¶
func (jw *JsonWriter) WriteCollection() (int, error)
func (*JsonWriter) WriteCollectionHeader ¶
func (jw *JsonWriter) WriteCollectionHeader(extra string) (string, error)
func (*JsonWriter) WriteEntity ¶
func (jw *JsonWriter) WriteEntity() error
func (*JsonWriter) WritePostCollections ¶
func (jw *JsonWriter) WritePostCollections(extra string, level int) string
func (*JsonWriter) WritePreCollections ¶
func (jw *JsonWriter) WritePreCollections(extra string, plural string, level int) string
type Model ¶
type Model struct { Registry *Registry `json:"-"` Schemas []string `json:"schemas,omitempty"` Attributes Attributes `json:"attributes,omitempty"` Groups map[string]*GroupModel `json:"groups,omitempty"` // Plural }
func (*Model) AddAttrArray ¶
func (*Model) AddGroupModel ¶
func (m *Model) AddGroupModel(plural string, singular string) (*GroupModel, error)
func (*Model) ApplyNewModel ¶
func (*Model) DelAttribute ¶
func (*Model) FindGroupModel ¶
func (m *Model) FindGroupModel(gTypePlural string) *GroupModel
func (*Model) GetBaseAttributes ¶
func (m *Model) GetBaseAttributes() Attributes
func (*Model) SetPointers ¶
func (m *Model) SetPointers()
func (*Model) SetSchemas ¶
func (*Model) VerifyAndSave ¶
VerifyAndSave() should be called by automatically but there may be cases where someone would need to call it manually (e.g. setting an attribute's property - we should technically find a way to catch those cases so code above this shouldn't need to think about it
type ModelSerializer ¶
func GetModelSerializer ¶
func GetModelSerializer(format string) ModelSerializer
type Object ¶
func ExtractIncomingObject ¶
func ExtractIncomingObject(info *RequestInfo, body []byte) (Object, error)
type PageWriter ¶
type PageWriter struct { Info *RequestInfo OldWriter HTTPWriter Headers *map[string]string Buffer *bytes.Buffer }
func NewPageWriter ¶
func NewPageWriter(info *RequestInfo) *PageWriter
func (*PageWriter) AddHeader ¶
func (pw *PageWriter) AddHeader(name, value string)
func (*PageWriter) Done ¶
func (pw *PageWriter) Done()
type PropPath ¶
type PropPath struct {
Parts []PropPart
}
func MustPropPathFromDB ¶
func MustPropPathFromPath ¶
func MustPropPathFromUI ¶
func PropPathFromDB ¶
func PropPathFromPath ¶
func PropPathFromUI ¶
type Registry ¶
func GetDefaultReg ¶
func (*Registry) AddGroupWithObject ¶
func (*Registry) LoadModelFromFile ¶
func (*Registry) UpsertGroup ¶
*Group, isNew, error
type RequestInfo ¶
type RequestInfo struct { Registry *Registry BaseURL string OriginalPath string OriginalRequest *http.Request `json:"-"` OriginalResponse http.ResponseWriter `json:"-"` Parts []string Root string Abstract string GroupType string GroupUID string GroupModel *GroupModel ResourceType string ResourceUID string ResourceModel *ResourceModel VersionUID string What string // Registry, Coll, Entity HasInline bool Inlines []string // TODO store a PropPaths instead Filters [][]*FilterExpr // [OR][AND] filter=e,e(and) &(or) filter=e ShowModel bool ShowMeta bool StatusCode int SentStatus bool HTTPWriter HTTPWriter `json:"-"` // contains filtered or unexported fields }
func ParseRequest ¶
func ParseRequest(tx *Tx, w http.ResponseWriter, r *http.Request) (*RequestInfo, error)
func (*RequestInfo) AddHeader ¶
func (ri *RequestInfo) AddHeader(name, value string)
func (*RequestInfo) AddInline ¶
func (info *RequestInfo) AddInline(path string) error
func (*RequestInfo) IsInlineSet ¶
func (info *RequestInfo) IsInlineSet(entityPath string) bool
func (*RequestInfo) ParseFilters ¶
func (info *RequestInfo) ParseFilters() error
func (*RequestInfo) ParseRequestURL ¶
func (info *RequestInfo) ParseRequestURL() error
func (*RequestInfo) ShouldInline ¶
func (info *RequestInfo) ShouldInline(entityPath string) bool
type Resource ¶
func (*Resource) AddVersionWithObject ¶
func (*Resource) EnsureMaxVersions ¶
func (*Resource) FindVersion ¶
Maybe replace error with a panic? same for other finds??
func (*Resource) GetDefault ¶
Maybe replace error with a panic?
func (*Resource) GetVersionIDs ¶
func (*Resource) GetVersions ¶
func (*Resource) SetDefault ¶
Only call this if you want things to be sticky (when not nil). Creating a new version should do this directly
func (*Resource) UpsertVersion ¶
type ResourceModel ¶
type ResourceModel struct { SID string `json:"-"` GroupModel *GroupModel `json:"-"` Plural string `json:"plural"` Singular string `json:"singular"` MaxVersions int `json:"maxversions"` // do not include omitempty SetVersionId *bool `json:"setversionid"` // do not include omitempty SetStickyDefault *bool `json:"setstickydefaultversion"` // do not include omitempty HasDocument *bool `json:"hasdocument"` // do not include omitempty ReadOnly bool `json:"readonly,omitempty"` TypeMap map[string]string `json:"typemap,omitempty"` Attributes Attributes `json:"attributes,omitempty"` }
func (*ResourceModel) AddAttr ¶
func (rm *ResourceModel) AddAttr(name, daType string) (*Attribute, error)
func (*ResourceModel) AddAttrArray ¶
func (rm *ResourceModel) AddAttrArray(name string, item *Item) (*Attribute, error)
func (*ResourceModel) AddAttrMap ¶
func (rm *ResourceModel) AddAttrMap(name string, item *Item) (*Attribute, error)
func (*ResourceModel) AddAttrObj ¶
func (rm *ResourceModel) AddAttrObj(name string) (*Attribute, error)
func (*ResourceModel) AddAttribute ¶
func (rm *ResourceModel) AddAttribute(attr *Attribute) (*Attribute, error)
func (*ResourceModel) AddTypeMap ¶
func (rm *ResourceModel) AddTypeMap(ct string, format string) error
func (*ResourceModel) DelAttribute ¶
func (rm *ResourceModel) DelAttribute(name string) error
func (*ResourceModel) Delete ¶
func (rm *ResourceModel) Delete() error
func (*ResourceModel) GetBaseAttributes ¶
func (rm *ResourceModel) GetBaseAttributes() Attributes
func (*ResourceModel) GetHasDocument ¶
func (rm *ResourceModel) GetHasDocument() bool
func (*ResourceModel) GetSetStickyDefault ¶
func (rm *ResourceModel) GetSetStickyDefault() bool
func (*ResourceModel) GetSetVersionId ¶
func (rm *ResourceModel) GetSetVersionId() bool
func (*ResourceModel) MapContentType ¶
func (rm *ResourceModel) MapContentType(ct string) string
Map incoming "contentType" (ct) to its typemap value. If there is no match (or more than one match with a different type) then default to "binary"
func (*ResourceModel) RemoveTypeMap ¶
func (rm *ResourceModel) RemoveTypeMap(ct string) error
func (*ResourceModel) Save ¶
func (rm *ResourceModel) Save() error
func (*ResourceModel) SetMaxVersions ¶
func (rm *ResourceModel) SetMaxVersions(maxV int) error
func (*ResourceModel) SetRegistry ¶
func (rm *ResourceModel) SetRegistry(reg *Registry)
func (*ResourceModel) SetSetStickyDefault ¶
func (rm *ResourceModel) SetSetStickyDefault(val bool) error
func (*ResourceModel) UnmarshalJSON ¶
func (r *ResourceModel) UnmarshalJSON(data []byte) error
func (*ResourceModel) Verify ¶
func (rm *ResourceModel) Verify(rmName string) error
func (*ResourceModel) VerifyAndSave ¶
func (rm *ResourceModel) VerifyAndSave() error
func (*ResourceModel) VerifyData ¶
func (rm *ResourceModel) VerifyData() error
type Result ¶
type Result struct { Data []*any // One row TempData []any Reuse bool AllRows [][]*any // contains filtered or unexported fields }
func (*Result) PullNextRow ¶
func (r *Result) PullNextRow()
func (*Result) RetrieveAllRowsFromDB ¶
func (r *Result) RetrieveAllRowsFromDB()
func (*Result) RetrieveNextRowFromDB ¶
type Tx ¶
type Tx struct { Registry *Registry CreateTime string // use for entity timestamps too User string // Cache of entities this Tx is dealing with. Things can get funky if // we have more than one instance of the same entity in memory. // TODO DUG expand this to save all types, not just Versions. // Also, consider having Commit() just automatically call ValidateAndSave // for all entities in the Tx - then people don't need to call save // explicitly // Registries map[string]*Registry // reg.UID // Groups map[string]*Group // reg.DbSID+g.UID // Resources map[string]*Resource // reg.DbSID+g.DbSID+r.UID Versions map[string]*Version // reg.DbSID+g.DbSID+r.DbSID+v.UID // contains filtered or unexported fields }
Holds info about the current transaction. In a lot of ways this is similar to golang's Context in that it holds other info related to the current changes that are going on. Maybe one day convert this to a Context where Tx is just as apsect of it.