Documentation
¶
Index ¶
- Variables
- func SetDefaultLang(lang string)
- func WithDefaultLang(lang string) func(o *Option)
- func WithTablename(tableName string) func(o *Option)
- func WithThreadSafe() func(o *Option)
- type Book
- func (b *Book) Contains(s string, dst *[]int)
- func (b *Book) Hash() uint64
- func (b *Book) IsExist(id int) bool
- func (b *Book) JSON() []byte
- func (b *Book) Len() int
- func (b *Book) LoadFromSlice(slice interface{}, attrid string, attrname string) error
- func (b *Book) MarshalJSON() ([]byte, error)
- func (b *Book) Name(lc LangCode, id int) string
- func (b *Book) Optimize() error
- func (b *Book) Parse(buf []byte) error
- func (b *Book) Set(id int, name string)
- func (b *Book) Traverse(f func(id int, name string) (next bool))
- type FlexBook
- func (b *FlexBook) AddItem(item Item)
- func (b *FlexBook) AddItems(items []Item)
- func (b *FlexBook) AddMultiLangItem(item MultiLangItem)
- func (b *FlexBook) AddMultiLangItems(items []MultiLangItem)
- func (b *FlexBook) Book(lang string) *Book
- func (b *FlexBook) BookAsJSON(lang string, dst *[]byte)
- func (b *FlexBook) Hash(lang string) uint64
- func (b *FlexBook) IsExist(id int) bool
- func (b *FlexBook) Len() int
- func (b *FlexBook) LoadFromSlice(src interface{}, attrid string, attrname string) error
- func (b *FlexBook) Name(lc LangCode, id int) string
- func (b *FlexBook) Optimize() error
- func (b *FlexBook) Parse(src []byte) error
- func (b *FlexBook) SetThreadSafe()
- func (b *FlexBook) TableName() string
- type Item
- type LangCode
- type MultiLangItem
- type Option
Constants ¶
This section is empty.
Variables ¶
var (
// NotFoundName returns by Name() if key not found.
NotFoundName = "?"
)
Functions ¶
func WithDefaultLang ¶
WithDefaultLang replaces global default language.
func WithTablename ¶ added in v0.0.2
func WithThreadSafe ¶
func WithThreadSafe() func(o *Option)
WithThreadSafe informs that it is changeable book.
Types ¶
type Book ¶
type Book struct {
// contains filtered or unexported fields
}
Book implements in-memory storage of reference book in a single language.
func NewBook ¶
func NewBook() *Book
NewBook returns new instance of concurrent unsafe Book. Use this function if you does not expect items modification in runtime.
func NewConcurrentBook ¶
func NewConcurrentBook() *Book
NewConcurrentBook returns new instance of concurrent safe Book.
func (*Book) Contains ¶
Contains adds to dst ID of reference book items if name contains s. The function is case unsensitive.
func (*Book) LoadFromSlice ¶
LoadFromSlice init reference book with id, name pairs from any slice.
func (*Book) MarshalJSON ¶ added in v0.0.2
func (*Book) Name ¶
Name return reference book item's name by id. Returns variable NotFoundName if id is not found.
type FlexBook ¶
type FlexBook struct {
// contains filtered or unexported fields
}
FlexBook implements reference book in-memory storage.
func NewFlexBook ¶
NewFlexBook returns new reference book instance.
func (*FlexBook) AddMultiLangItem ¶
func (b *FlexBook) AddMultiLangItem(item MultiLangItem)
AddMultiLangItem adds item to the book.
func (*FlexBook) AddMultiLangItems ¶
func (b *FlexBook) AddMultiLangItems(items []MultiLangItem)
AddMultiLangItems adds multiple items to the book.
func (*FlexBook) Book ¶
Book returns pointer to the reference book associated with lang. Returns pointer to the book associates with default language if lang not found.
func (*FlexBook) BookAsJSON ¶
func (*FlexBook) LoadFromSlice ¶
func (*FlexBook) Parse ¶
Parse recognizes input JSON presented as [{"id": 1, "name" : "Hello"},..] or [{"id":1, "name":{"en":"Hello","ru":"Привет"}},...] or mix [{"id":1, "name":"Hello"}, {"id":2, "name":{"en":"World", "ru":"Мир"}},...]
func (*FlexBook) SetThreadSafe ¶
func (b *FlexBook) SetThreadSafe()
SetThreadSafe sets flag what wraps access to internals by mutex.
type MultiLangItem ¶
MultiLangItem describes JSON unmarshal destination for multi language reference table.