data

package
v0.0.1-2 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2023 License: MIT Imports: 1 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IChangeable

type IChangeable interface {
	// The UTC time at which the object was last changed (created or updated).
	GetChangeTime() time.Time
}

Interface for data objects that contain their latest change time.

Example
	type MyStruct struct {
		...
		changeTime time.Time
	}

	func (c *MyStruct) GetChangeTime() time.Time {
		return c.changeTime
	}
	func (c *MyStruct) SetGetChangeTime(changeTime time.Time) {
		c.changeTime = changeTime
	}

type IIdentifiable

type IIdentifiable[K any] interface {
	GetId() K
}

IIdentifiable interface for data objects to operate with ids.

Example
	type MyStruct struct {
		...
		id string
	}

	func (c *MyStruct) GetId() string {
		return c.id
	}
	func (c *MyStruct) SetId(id string) {
		c.id = id
	}

type IIdentifier

type IIdentifier[K any] interface {
	Empty() bool
	Equals(K) bool
}

type INamed

type INamed interface {
	GetName() string
}

Interface for data objects that have human-readable names.

Example
	type MyStruct struct {
		...
		name string
	}

	func (c *MyStruct) GetName() string {
		return c.name
	}
	func (c *MyStruct) SetName(name string) {
		c.name = name
	}

type IStringIdentifiable

type IStringIdentifiable interface {
	GetId() string
	SetId(string)
}

IStringIdentifiable interface for data objects to operate with ids.

Example
	type MyStruct struct {
		...
		id string
	}

	func (c *MyStruct) GetId() string {
		return c.id
	}
	func (c *MyStruct) SetId(id string) {
		c.id = id
	}

type ITrackable

type ITrackable interface {
	// The UTC time at which the object was created.
	GetCreateTime() time.Time
	// The UTC time at which the object was last changed (created, updated, or deleted).
	GetChangeTime() time.Time
	// The logical deletion flag. True when object is deleted and null or false otherwise
	GetDeleted() bool
}

Interface for data objects that can track their changes, including logical deletion.

Example
	type MyStruct struct {
		...
		changeTime time.Time
		createTime time.Time
		deleted bool
	}

	func (c *MyStruct) GetChangeTime() string {
		return c.changeTime
	}
	func (c *MyStruct) SetDeleted(deleted bool) {
		c.deleted = deleted
	}

type IVersioned

type IVersioned interface {
	// The object's version.
	GetVersion() string
}

Interface for data objects that can be versioned.

Versioning is often used as optimistic concurrency mechanism.

The version doesn't have to be a number, but it is recommended to use sequential values to determine if one object has newer or older version than another one.

It is a common pattern to use the time of change as the object version.

Example
	type MyStruct struct {
		...
		version string
	}

	func (c *MyStruct) GetVersion() string {
		return c.version
	}
	func (c *MyStruct) SetVersion(version string) {
		c.version = version
	}
	func (c *MyStruct) UpdateData(ctx context.Context, item: MyData) {
		if (item.version < oldItem.version) {
			panic("VERSION_CONFLICT")
		}
	}

type MultiString

type MultiString map[string]string

MultiString An object that contains string translations for multiple languages. Language keys use two-letter codes like: 'en', 'sp', 'de', 'ru', 'fr', 'pr'. When translation for specified language does not exists it defaults to English ('en'). When English does not exists it falls back to the first defined language.

Example:
values := NewMultiStringFromTuples(
	"en", "Hello World!",
	"ru", "Привет мир!"
);

value1 := values.Get("ru"); // Result: "Привет мир!"
value2 := values.Get("pt"); // Result: "Hello World!"

Jump to

Keyboard shortcuts

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