gobeans

package
v1.5.6 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	Natural      = "nat"  // Простые типы: int, float, string или []T или map[string]T - где T простой тип @see golangInlineTypes down!
	DeepCopyObj  = "copy" // Глубокая копия сложный объект
	PointerToObj = "link" // Ссылка на объект
	BeansObj     = "obj"  // Включение вложенного Bean объекта

	AnonStructPrefixTypeName = "github.com/imperiuse/gobeans_anon_struct_" // AnonStructPrefixTypeName - Префикс обозначения типа анонимных структур
)

Типы свойств по аналогии с JAVA BEANS

Variables

This section is empty.

Functions

This section is empty.

Types

type AnonymousStructField

type AnonymousStructField struct {
	Name string `json:"name"` // name field
	Type string `json:"type"` // golang type name
	Tag  string `json:"tag"`  // golang tag
}

AnonymousStructField - структура описывающая одно поле анонимной структуры @see:reflect.AnonymousStructField

type BeanDescription

type BeanDescription struct {
	// IMPORTANT FIELDS
	ID         string       `json:"id"`         // Bean ID - MUST BE UNIQUE!
	Enable     bool         `json:"enable"`     // Enable for create (build) this Bean obj ?
	StructName string       `json:"structName"` // Registered structure name (@see func RegTypes and RegNamedTypes)
	Properties []Properties `json:"properties"` // bean properties

	// OTHERS FIELDS
	Description string `json:"description"` // Simple text description of Bean (doesn't matter)

	// Anonymous structs
	Anonymous    bool                   `json:"anonymous"`    // Bean base on Anonymous struct ? (Default = false)
	StructFields []AnonymousStructField `json:"structFields"` // anonymous struct fields descriptions (if Struct == "")
}

BeanDescription - структура описывающая Bean

type BeansStorage

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

BeansStorage - Главный объект библиотеки - Beans (Хранилище Beans)

func CreateStorage

func CreateStorage() (BeansStorage, error)

CreateStorage - главный конструктор, главной структуры - хранилища Bean

Example
Beans, err := CreateStorage()
if err != nil {
	print("\nError while gobeans.CreateStorage: %v\n", err)
} else {
	fmt.Print("\nStorage successful created!\n")
}

err = Beans.RegNamedTypes((*TestNatural)(nil), "TestNatural", (**TestNatural)(nil), "*TestNatural")

if err != nil {
	print("\nError while gobeans.RegType: %v\n", err)
} else {
	fmt.Printf("\nRegistrate types: %v\n", Beans.ShowRegTypes())
}

if err = Beans.CreateBeansFromJSON("./test_json/beansTest.json"); err != nil {
	print("Error while create Beans from json file", err)
} else {
	for id, bean := range Beans.GetMapBeans() {
		fmt.Printf("Bean name: [%+v] \n\n\tPIO: %v\n", id, bean.pio)
	}
}
Output:

func (*BeansStorage) CloneBean

func (bs *BeansStorage) CloneBean(id string) (interface{}, error)

CloneBean - получить клонированный объект pio Bean-а по его ID

func (*BeansStorage) CreateBeansFromJSON

func (bs *BeansStorage) CreateBeansFromJSON(pathFile string) (err error)

CreateBeansFromJSON - метод возращающий заполняющий хранилище Bean по данным из JSON файла

func (*BeansStorage) FoundReflectTypeByName

func (bs *BeansStorage) FoundReflectTypeByName(typeName string) (reflect.Type, bool)

FoundReflectTypeByName - метод возращающий reflect.Type по typeName и проверящий его наличие

func (*BeansStorage) GetAllBeansID

func (bs *BeansStorage) GetAllBeansID() []string

GetAllBeansID - метод возращающий slice BeanID cd (имён бинов) хранимых bean типов

func (*BeansStorage) GetBean

func (bs *BeansStorage) GetBean(id string) interface{}

GetBean - метод возращающий интерфейс (указатель) на объект Bean-а по его ID

func (*BeansStorage) GetMapBeans

func (bs *BeansStorage) GetMapBeans() MapOfBeans

GetMapBeans - метод возращающий map Beans

func (*BeansStorage) GetReflectTypeByName

func (bs *BeansStorage) GetReflectTypeByName(typeName string) reflect.Type

GetReflectTypeByName - метод возращающий reflect.Type по typeName

func (*BeansStorage) RegNamedTypes

func (bs *BeansStorage) RegNamedTypes(typesAndNames ...interface{}) error

RegNamedTypes - метод регистрирующий типы в MapOfRegType, и именует согласно переданному имени, нечетные типы, четные имя типа

func (*BeansStorage) RegTypes

func (bs *BeansStorage) RegTypes(typesNil ...interface{}) error

RegTypes - метод регистрирующий типы в MapOfRegType, именует согласно пути пакета

func (*BeansStorage) ShowRegTypes

func (bs *BeansStorage) ShowRegTypes() []string

ShowRegTypes - метод возращающий список зарегистрированных названий типов

type MapOfBeans

type MapOfBeans map[string]*beanInstance

MapOfBeans - map созданных Bean объектов

type MapOfRegType

type MapOfRegType map[string]reflect.Type

MapOfRegType - map зарегистрированных типов (рефлексионных)

type Properties

type Properties struct {
	Type  string      `json:"type"`  // тип инициализации см. выше const Natural, DeepCopyObj, PointerToObj, BeansObj
	Name  string      `json:"name"`  // имя поля
	Value interface{} `json:"value"` // значение поля, либо ссылка , либо объект
}

Properties - структура описывающая поля Bean

Jump to

Keyboard shortcuts

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