item

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2018 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Array

type Array struct {
	// contains filtered or unexported fields
}

Array is an implementation of Item interface

func (*Array) AddProperties

func (array *Array) AddProperties(set set.Set, safe bool) error

AddProperties implementation

func (*Array) ChangeName

func (array *Array) ChangeName(mark name.Mark)

ChangeName implementation

func (*Array) CollectObjects

func (array *Array) CollectObjects(limit, offset int) (set.Set, error)

CollectObjects implementation

func (*Array) CollectProperties

func (array *Array) CollectProperties(limit, offset int) (set.Set, error)

CollectProperties implementation

func (*Array) Compress

func (array *Array) Compress(source, destination hash.IHashable)

Compress implementation

func (*Array) ContainsObject

func (array *Array) ContainsObject() bool

ContainsObject implementation

func (*Array) Copy

func (array *Array) Copy() Item

Copy implementation

func (*Array) Default

func (array *Array) Default(suffix string) string

Default implementation

func (*Array) GenerateGetter

func (array *Array) GenerateGetter(
	variable,
	argument,
	interfaceSuffix string,
	depth int,
) string

GenerateGetter implementation

func (*Array) GenerateSetter

func (array *Array) GenerateSetter(
	variable,
	argument,
	typeSuffix string,
	depth int,
) string

GenerateSetter implementation

func (*Array) GetChildren

func (array *Array) GetChildren() []hash.IHashable

GetChildren implementation

func (*Array) InterfaceType

func (array *Array) InterfaceType(suffix string) string

InterfaceType implementation

func (*Array) IsNull

func (array *Array) IsNull() bool

IsNull implementation

func (*Array) MakeRequired

func (array *Array) MakeRequired()

MakeRequired implementation

func (*Array) Parse

func (array *Array) Parse(context ParseContext) (err error)

Parse implementation

func (*Array) ToString

func (array *Array) ToString() string

ToString implementation

func (*Array) Type

func (array *Array) Type(suffix string) string

Type implementation

type DBKind

type DBKind struct {
}

DBKind is an implementation of Kind interface

func (*DBKind) Annotation

func (dbKind *DBKind) Annotation(name string, item Item) string

Annotation implementation

func (*DBKind) Default

func (dbKind *DBKind) Default(suffix string, item Item) string

Default implementation

func (*DBKind) InterfaceType

func (dbKind *DBKind) InterfaceType(suffix string, item Item) string

InterfaceType implementation

func (*DBKind) Type

func (dbKind *DBKind) Type(suffix string, item Item) string

Type implementation

type Item

type Item interface {
	hash.IHashable

	// Copy should make a copy of an item
	Copy() Item

	// ChangeName should change the name of an item recursively
	// args:
	//   1. name.Mark - mark that changes the items name
	ChangeName(name.Mark)

	// IsNull checks if an item can be null
	// return:
	//   true iff. item can be null
	IsNull() bool

	// MakeRequired should not allow item to be null
	MakeRequired()

	// ContainsObject checks if an item contains an object
	// return:
	//   true iff. item contains an object
	ContainsObject() bool

	// Default should return a default value for an item
	// args:
	//   1. string - a suffix added to a type
	// return:
	//   default value of an item
	Default(string) string

	// Type should return a go type of item
	// args:
	//   1. string - a suffix added to a type
	// return:
	//   type of item with suffix appended
	Type(string) string

	// InterfaceType should return an interface type of item
	// args:
	//   1. string - a suffix added to a type
	// return:
	//   interface type of item with suffix appended
	InterfaceType(string) string

	// AddProperties should add properties to an item
	// args:
	//   1. set.Set [Property] - a set of properties
	//   2. bool - flag; if in the set exists a property with the same type
	//             as one of the items properties, then if flag is set
	//             an error should be returned,
	//             otherwise that property should be ignored
	// return:
	//   1. error during execution
	AddProperties(set.Set, bool) error

	// Parse should create an item from given map
	// args:
	//   1. context - ParseContext; context used for parsing
	// return:
	//   1. error during execution
	Parse(ParseContext) error

	// CollectObjects should return a set of objects contained within an item
	// args:
	//   1. int - limit; how deep to search for an object; starting from 1;
	//            if limit is negative this parameter is ignored.
	//   2. int - offset; from which level gathering objects should begin;
	//            starting from 0;
	// return:
	//   1. set of collected objects
	//   2. error during execution
	// example:
	//   let objects be denoted by o and other items by i
	//   suppose we have the following tree:
	//             o1
	//            / \
	//           o2  o3
	//          /  \   \
	//        o4   o5   o6
	//        / \   \    \
	//       o7  i1  i2   i3
	//
	// CollectObjects(3, 1) should return a set of o2, o3, o4, o5, o6
	// CollectObjects(2, 2) should return an empty set
	// CollectObjects(-1, 4) should return a set of o7
	CollectObjects(int, int) (set.Set, error)

	// CollectProperties should return a set properties contained within an item
	// args:
	//   1. int - limit; how deep to search for a property; starting from 1;
	//            if limit is negative this parameter is ignored.
	//   2. int - offset; from which level gathering properties should begin;
	//            starting from 0;
	// return:
	//   1. set of collected properties
	//   2. error during execution
	CollectProperties(int, int) (set.Set, error)

	// GenerateGetter should return a body of a getter function for given item
	// args:
	//   1. string - variable; a name of a variable to get
	//   2. string - argument; a name of a result
	//   3. string - suffix; a suffix added to items type
	//   4. int - depth; a width of an indent
	// return:
	//   string representing a body of a getter function
	GenerateGetter(string, string, string, int) string

	// GenerateSetter should return a body of a setter function for given item
	// args:
	//   1. string - variable; a name of a variable to set
	//   2. string - argument; a name of an argument of the function
	//   3. string - suffix; a suffix added to items type
	//   4. int - depth; a width of an indent
	// return:
	//   string representing a body of a setter function
	GenerateSetter(string, string, string, int) string
}

Item is an interface for a type of a variable

func CreateItem

func CreateItem(itemType interface{}) (Item, error)

CreateItem is a factory for items

type JSONKind

type JSONKind struct {
}

JSONKind is an implementation of Kind interface

func (*JSONKind) Annotation

func (jsonKind *JSONKind) Annotation(name string, item Item) string

Annotation implementation

func (*JSONKind) Default

func (jsonKind *JSONKind) Default(suffix string, item Item) string

Default implementation

func (*JSONKind) InterfaceType

func (jsonKind *JSONKind) InterfaceType(suffix string, item Item) string

InterfaceType implementation

func (*JSONKind) Type

func (jsonKind *JSONKind) Type(suffix string, item Item) string

Type implementation

type Kind

type Kind interface {
	// Type should return a go type of a property
	// args:
	//   1. string - a suffix added to a type
	//   2. item - an item of a property
	// return:
	//   go type of a property
	Type(string, Item) string

	// Type should return an interface type of a property
	// args:
	//   1. string - a suffix added to a type
	//   2. item - an item of a property
	// return:
	//   interface type of a property
	InterfaceType(string, Item) string

	// Annotation should return an annotation for a property is a go struct
	// args:
	//   1. string - a name of a property
	//   2. item - an item of a property
	// return:
	//   go annotation of a property
	Annotation(string, Item) string

	// Default should return a default value for a property
	// args:
	//   1. string - a name of a property
	//   2. item - an item of a property
	// return:
	//   default value of a property as string
	Default(string, Item) string
}

Kind is an interface for a type of property it can be either db or json

type Object

type Object struct {
	// contains filtered or unexported fields
}

Object is an implementation of Item interface

func (*Object) AddProperties

func (object *Object) AddProperties(properties set.Set, safe bool) error

AddProperties implementation

func (*Object) ChangeName

func (object *Object) ChangeName(mark name.Mark)

ChangeName implementation

func (*Object) CollectObjects

func (object *Object) CollectObjects(limit, offset int) (set.Set, error)

CollectObjects implementation

func (*Object) CollectProperties

func (object *Object) CollectProperties(limit, offset int) (set.Set, error)

CollectProperties implementation

func (*Object) Compress

func (object *Object) Compress(source, destination hash.IHashable)

Compress implementation

func (*Object) ContainsObject

func (object *Object) ContainsObject() bool

ContainsObject implementation

func (*Object) Copy

func (object *Object) Copy() Item

Copy implementation

func (*Object) Default

func (object *Object) Default(suffix string) string

Default implementation

func (*Object) Empty

func (object *Object) Empty() bool

Empty checks if object has no properties

func (*Object) GenerateConstructor

func (object *Object) GenerateConstructor(suffix string) string

GenerateConstructor creates a constructor for an object

func (*Object) GenerateFetch

func (object *Object) GenerateFetch(packageName, suffix string, params crud.Params) string

GenerateFetch generates a fetch function for an object

func (*Object) GenerateGetter

func (object *Object) GenerateGetter(
	variable,
	argument,
	interfaceSuffix string,
	depth int,
) string

GenerateGetter implementation

func (*Object) GenerateImplementation

func (object *Object) GenerateImplementation(interfaceSuffix, typeSuffix string) string

GenerateImplementation creates an implementation of an objects getter and setter methods

func (*Object) GenerateInterface

func (object *Object) GenerateInterface(suffix string) string

GenerateInterface creates an interface of an object with suffix added to objects type

func (*Object) GenerateList

func (object *Object) GenerateList(packageName, suffix string, params crud.Params) string

GenerateList generates a list function for an object

func (*Object) GenerateMutableInterface

func (object *Object) GenerateMutableInterface(
	interfaceSuffix,
	typeSuffix string,
) string

GenerateMutableInterface creates an interface of an object with suffix added to objects type this interface can be edited

func (*Object) GenerateSchemaName

func (object *Object) GenerateSchemaName(goextPackage, typename string) string

func (*Object) GenerateSetter

func (object *Object) GenerateSetter(
	variable,
	argument,
	typeSuffix string,
	depth int,
) string

GenerateSetter implementation

func (*Object) GenerateStruct

func (object *Object) GenerateStruct(suffix string) string

GenerateStruct creates a struct of an object with suffix added to type name of each field

func (*Object) GetChildren

func (object *Object) GetChildren() []hash.IHashable

GetChildren implementation

func (*Object) InterfaceType

func (object *Object) InterfaceType(suffix string) string

InterfaceType implementation

func (*Object) IsNull

func (object *Object) IsNull() bool

IsNull implementation

func (*Object) MakeRequired

func (object *Object) MakeRequired()

MakeRequired implementation

func (*Object) Name

func (object *Object) Name() string

Name is a function that allows object to be used as a set element

func (*Object) Parse

func (object *Object) Parse(context ParseContext) error

Parse implementation

func (*Object) ToString

func (object *Object) ToString() string

ToString implementation

func (*Object) Type

func (object *Object) Type(suffix string) string

Type implementation

type ParseContext

type ParseContext struct {
	Prefix   string
	Level    int
	Required bool
	Defaults interface{}
	Data     map[interface{}]interface{}
}

ParseContext represents context used in parsing

type PlainItem

type PlainItem struct {
	// contains filtered or unexported fields
}

PlainItem is an implementation of Item interface

func (*PlainItem) AddProperties

func (plainItem *PlainItem) AddProperties(set set.Set, safe bool) error

AddProperties implementation

func (*PlainItem) ChangeName

func (plainItem *PlainItem) ChangeName(mark name.Mark)

ChangeName implementation

func (*PlainItem) CollectObjects

func (plainItem *PlainItem) CollectObjects(limit, offset int) (set.Set, error)

CollectObjects implementation

func (*PlainItem) CollectProperties

func (plainItem *PlainItem) CollectProperties(limit, offset int) (set.Set, error)

CollectProperties implementation

func (*PlainItem) Compress

func (plainItem *PlainItem) Compress(hash.IHashable, hash.IHashable)

Compress implementation

func (*PlainItem) ContainsObject

func (plainItem *PlainItem) ContainsObject() bool

ContainsObject implementation

func (*PlainItem) Copy

func (plainItem *PlainItem) Copy() Item

Copy implementation

func (*PlainItem) Default

func (plainItem *PlainItem) Default(suffix string) string

Default implementation

func (*PlainItem) GenerateGetter

func (plainItem *PlainItem) GenerateGetter(
	variable,
	argument,
	interfaceSuffix string,
	depth int,
) string

GenerateGetter implementation

func (*PlainItem) GenerateSetter

func (plainItem *PlainItem) GenerateSetter(
	variable,
	argument,
	typeSuffix string,
	depth int,
) string

GenerateSetter implementation

func (*PlainItem) GetChildren

func (plainItem *PlainItem) GetChildren() []hash.IHashable

GetChildren implementation

func (*PlainItem) InterfaceType

func (plainItem *PlainItem) InterfaceType(suffix string) string

InterfaceType implementation

func (*PlainItem) IsNull

func (plainItem *PlainItem) IsNull() bool

IsNull implementation

func (*PlainItem) MakeRequired

func (plainItem *PlainItem) MakeRequired()

MakeRequired implementation

func (*PlainItem) Parse

func (plainItem *PlainItem) Parse(context ParseContext) (err error)

Parse implementation

func (*PlainItem) ToString

func (plainItem *PlainItem) ToString() string

ToString implementation

func (*PlainItem) Type

func (plainItem *PlainItem) Type(suffix string) string

Type implementation

type Property

type Property struct {
	// contains filtered or unexported fields
}

Property is a type for an item with name

func CreateProperty

func CreateProperty(name string) *Property

CreateProperty is a constructor

func (*Property) AddProperties

func (property *Property) AddProperties(set set.Set, safe bool) error

AddProperties adds properties to items of given property args:

set set.Set [Property] - a set of properties
safe bool - flag; if in the set exists a property with the same type
            as one of the items properties, then if flag is set
            an error should be returned,
            otherwise that property should be ignored

return:

  1. error during execution

func (*Property) ChangeName

func (property *Property) ChangeName(mark name.Mark)

ChangeName should change name of items of a property

func (*Property) CollectObjects

func (property *Property) CollectObjects(limit, offset int) (set.Set, error)

CollectObjects should return a set of objects contained within a property args:

  1. int - limit; how deep to search for an object; starting from 0; if limit is negative this parameter is ignored.
  2. int - offset; from which level gathering objects should begin;

return:

  1. set of collected objects
  2. error during execution

func (*Property) CollectProperties

func (property *Property) CollectProperties(limit, offset int) (set.Set, error)

CollectProperties should return a set properties contained within a property args:

  1. int - limit; how deep to search for a property; starting from 0; if limit is negative this parameter is ignored.
  2. int - offset; from which level gathering properties should begin;

return:

  1. set of collected properties
  2. error during execution

func (*Property) Compress

func (property *Property) Compress(source, destination hash.IHashable)

Compress implementation

func (*Property) CompressObjects

func (property *Property) CompressObjects()

CompressObjects removes duplicate objects from an object tree rooted at a property

func (*Property) GenerateConstructor

func (property *Property) GenerateConstructor(suffix string) string

GenerateConstructor creates a constructor for a property

func (*Property) GenerateGetter

func (property *Property) GenerateGetter(
	variable,
	suffix string,
) string

GenerateGetter returns a getter for a property

func (*Property) GenerateProperty

func (property *Property) GenerateProperty(suffix string) string

GenerateProperty creates a property of a go struct from given property with suffix added to type name

func (*Property) GenerateSetter

func (property *Property) GenerateSetter(
	variable,
	interfaceSuffix,
	typeSuffix string,
) string

GenerateSetter returns a setter for a property

func (*Property) GetChildren

func (property *Property) GetChildren() []hash.IHashable

GetChildren implementation

func (*Property) GetterHeader

func (property *Property) GetterHeader(suffix string) string

GetterHeader returns a header of a getter for a property

func (*Property) IsObject

func (property *Property) IsObject() bool

IsObject checks if an item in property is an object

func (*Property) MakeRequired

func (property *Property) MakeRequired() bool

MakeRequired makes an item in property required returns true if property was changed

func (*Property) Name

func (property *Property) Name() string

Name gets a name of a property

func (*Property) Parse

func (property *Property) Parse(context ParseContext) (err error)

Parse creates property from given map, prefix and level prefix is used to determine a go type of an item level is used to determine a kind of a property args:

context ParseContext - a context used for parsing

return:

  1. error during execution

func (*Property) SetterHeader

func (property *Property) SetterHeader(suffix string, argument bool) string

SetterHeader returns a header of a setter for a property

func (*Property) ToString

func (property *Property) ToString() string

ToString implementation

Jump to

Keyboard shortcuts

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