easy_settings

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 13, 2022 License: MIT Imports: 12 Imported by: 0

README

Source package for easy saving settings

Package for savings JSON settings to single-alone database (type Bolt) with use minimal counts of lines code.

Add to use
$ go get github.com/KusoKaihatsuSha/easy_settings.git
Usage example

In example will be created database data.db in same folder and create data_group.json as export settings from database

package main

import (
	"fmt"

	es "github.com/KusoKaihatsuSha/easy_settings"
)

func main() {
	es.Pack("group").Item("test011").Add("id001", "001").Add("id002", "002")
	es.Pack("group").Item("test012").Add("id003", "003")
	es.Pack("group").Item("test021").Add("id004", "004")
	fmt.Println(es.Pack("group").Item("test011", true).Get("id001"))
	fmt.Println(es.Pack("group").Item("test01", true).Get("id", true))
	fmt.Println(es.Pack("group").Item("test", true).Get("id", true))
	es.Pack("group").Item("test", true).SaveJson()
}

Output file if using SaveJson()
{
  "ID": "4t81omdwfn8Am65c",
  "Name": "group",
  "Items": [
    {
      "Parent": null,
      "Name": "test011",
      "ID": "5pqsia7a5vC5lv67",
      "Values": [
        {
          "Key": "id001",
          "Value": "001"
        },
        {
          "Key": "id002",
          "Value": "002"
        }
      ]
    },
    {
      "Parent": null,
      "Name": "test012",
      "ID": "106UtcxTnn1w5Ux6",
      "Values": [
        {
          "Key": "id003",
          "Value": "003"
        }
      ]
    },
    {
      "Parent": null,
      "Name": "test021",
      "ID": "oeBj70fWn8gnjj65",
      "Values": [
        {
          "Key": "id004",
          "Value": "004"
        }
      ]
    }
  ],
  "Db": null,
  "Uniq": false
}

Documentation

Overview

Package easy_settings standalone DB with settings and other information

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(i int) string

Generate(int) string return random value

Types

type DataBase

type DataBase struct {
	Db      *bolt.DB
	Err     error
	Backets *[]DataBaseBucket
	Lock    chan bool
	Timeout time.Duration
}

DataBase working with Bolt DB

func NewDB

func NewDB(name string) *DataBase

NewDB(string) *DataBase consructor of DB Dolt function

func (*DataBase) Bucket

func (obj *DataBase) Bucket(name string) *DataBaseBucket

(*DataBase) Bucket(string) *DataBaseBucket return or create bucket of db

func (*DataBase) Close

func (o *DataBase) Close()

(*DataBase) Close() close DB file

func (*DataBase) Delete

func (obj *DataBase) Delete(name string)

(*DataBase) Delete(string) delete bucket by name

func (*DataBase) Open

func (o *DataBase) Open(name string) *DataBase

(*DataBase) Open(string) *DataBase open DB file

func (*DataBase) PrintAll

func (obj *DataBase) PrintAll(name string) map[string]([]byte)

(*DataBase) PrintAll(string) map[string]([]byte) Print all elements by bucket name

type DataBaseBucket

type DataBaseBucket struct {
	Parent  *bolt.DB
	Err     error
	Name    string
	Lock    chan bool
	Timeout time.Duration
	Inc     int
}

DataBaseBucket working with Bolt DB childs - buckets

func (*DataBaseBucket) Add

func (obj *DataBaseBucket) Add(key string, value string, uniq ...bool) string

(*DataBaseBucket) Add(string, string, ...bool) string Add new elements for saving in db as settings

func (*DataBaseBucket) Delete

func (obj *DataBaseBucket) Delete()

(*DataBaseBucket) Delete() delete bucket

func (*DataBaseBucket) Get

func (obj *DataBaseBucket) Get(key string, prefix ...bool) map[string]string

(*DataBaseBucket) Get(string, ...bool) map[string]string get elements from db

func (*DataBaseBucket) Print

func (obj *DataBaseBucket) Print(key string) []byte

func (*DataBaseBucket) PrintAllPrefix

func (obj *DataBaseBucket) PrintAllPrefix(prx string) map[string]([]byte)

type Item

type Item struct {
	Parent *Items
	Name   string
	ID     string
	Values []*Values
}

Item is elements of Data

func New

func New(type_ string) *Item

New(string) *Item constructor of new item of settings

func (*Item) Add

func (o *Item) Add(key string, val string) *Item

func (*Item) Find

func (o *Item) Find(key string) string

(*Item) Find(string) string find elements by key

func (*Item) GetValuesJson

func (o *Item) GetValuesJson() string

(*Item) GetValuesJson() string json marshaling data

func (*Item) New

func (o *Item) New(type_ string) *Item

New(string) *Item constructor of new item of settings

type Items

type Items struct {
	ID    string
	Name  string
	Items []*Item
	Db    *DataBase
	Uniq  bool
}

Items include elements of Data

func NewPack

func NewPack(elName string) *Items

NewPack(string) *Item constructor for settings values

func Pack

func Pack(name string) *Items

Pack

func (*Items) Add

func (o *Items) Add(key string, val string) *Items

func (*Items) Clear

func (o *Items) Clear(key string, flagFindAsPrefix ...bool)

func (*Items) Delete

func (o *Items) Delete()

func (*Items) End

func (o *Items) End()

End

func (*Items) Exist

func (o *Items) Exist(element *Item) *Item

Exist

func (*Items) Filter

func (o *Items) Filter(key string) *Items

(*Items) Filter(string) *Items filtering information as original kind // edited

func (*Items) Find

func (o *Items) Find(key string) []string

(*Items) Find(string) []string find information by key

func (*Items) Get

func (o *Items) Get(key string, flagFindAsPrefix ...bool) []string

func (*Items) Item

func (o *Items) Item(name interface{}, flagFindAsPrefix ...bool) *Items

Item

func (*Items) Json

func (o *Items) Json() string

(*Items) SaveJson() save Object to serialize value to Json

func (*Items) Load

func (o *Items) Load()

func (*Items) LoadJson

func (o *Items) LoadJson()

(*Items) LoadJson() Load Object from serialize value

func (*Items) Save

func (o *Items) Save(flagUniq ...bool)

func (*Items) SaveJson

func (o *Items) SaveJson()

(*Items) SaveJson() save Object to serialize value to Json

func (*Items) Test

func (o *Items) Test()

Test

func (*Items) UnmarshalJSON

func (o *Items) UnmarshalJSON(data []byte) error

(*Items) UnmarshalJSON([]byte) error wrapper around unmarshaling data

type Patern

type Patern struct {
	Generate func(int) string
}

Patern include randomize function

type Values

type Values struct {
	Key   string
	Value string
}

Values consist Pair values of data element

Jump to

Keyboard shortcuts

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