itisadb

package module
v0.9.5 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2023 License: MIT Imports: 13 Imported by: 1

README

itisadb-go-sdk - itisadb Driver and Toolkit PkgGoDev

itisadb is a system consisting of several microservices (Memory Balancer, Storage, WebApplication), which is a distributed key-value database.

Documentation

Installation

go get github.com/egorgasay/itisadb-go-sdk

Quick start

package main

import (
	"context"
	"github.com/egorgasay/itisadb-go-sdk"
	"log"
)

// main to run this test, itisadb must be run on :800.
func main() {
	db, err := itisadb.New(":800")
	if err != nil {
		return
	}

	ctx := context.TODO()
	err = db.SetOne(ctx, "qwe", "111", false)
	if err != nil {
		log.Fatalln(err)
	}

	get, err := db.GetOne(ctx, "qwe")
	if err != nil {
		log.Fatalln(err)
	}

	if get != "111" {
		log.Fatal("Wrong value")
	} else {
		log.Println("Value:", get)
	}
}

Documentation

Index

Constants

View Source
const (
	DefaultUser     = "itisadb"
	DefaultPassword = "itisadb"
)

Variables

View Source
var (
	ErrNotFound         = gost.NewError(0, 0, "not found")
	ErrUnavailable      = gost.NewError(0, 0, "storage is unavailable")
	ErrUnauthorized     = gost.NewError(0, 0, "unauthorized")
	ErrObjectNotFound   = gost.NewError(0, 0, "object not found")
	ErrUniqueConstraint = gost.NewError(0, 0, "unique constraint failed")
	ErrPermissionDenied = gost.NewError(0, 0, "permission denied")
)
View Source
var ErrWrongTypeParameter = fmt.Errorf("wrong type parameter")

Functions

func GetCmp

func GetCmp[V comparable](ctx context.Context, from getter, key string) (val V, err error)

func New

func New(ctx context.Context, balancerIP string, conf ...Config) (res gost.Result[*Client])

func ToServerNumber

func ToServerNumber(x int) *int32

Types

type AttachToObjectOptions

type AttachToObjectOptions struct {
	Server *int32
}

type Client

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

func (*Client) ChangeLevel

func (c *Client) ChangeLevel(ctx context.Context, login string, level Level) error

func (*Client) ChangePassword

func (c *Client) ChangePassword(ctx context.Context, login, newPassword string) error

func (*Client) CreateUser

func (c *Client) CreateUser(ctx context.Context, login, password string, opts ...CreateUserOptions) (res gost.Result[gost.Nothing])

func (*Client) DelOne

func (c *Client) DelOne(ctx context.Context, key string, opts ...DeleteOptions) gost.Result[gost.Nothing]

func (*Client) DeleteUser

func (c *Client) DeleteUser(ctx context.Context, login string) (res gost.Result[bool])

func (*Client) GetMany

func (c *Client) GetMany(ctx context.Context, keys []string, opts ...GetOptions) (res gost.Result[map[string]string])

GetMany gets a lot of values from gRPCis.

func (*Client) GetManyOpts

func (c *Client) GetManyOpts(ctx context.Context, keys []Key) (res gost.Result[map[string]string])

GetManyOpts gets a lot of values from gRPCis with opts.

func (*Client) GetOne

func (c *Client) GetOne(ctx context.Context, key string, opts ...GetOptions) (res gost.Result[string])

GetOne gets the value by the key from gRPCis.

func (*Client) IsObject

func (c *Client) IsObject(ctx context.Context, name string) (res gost.Result[bool])

IsObject checks if it is an object or not.

func (*Client) Object

func (c *Client) Object(ctx context.Context, name string, opts ...ObjectOptions) (res gost.Result[*Object])

Object creates a new object.

func (*Client) ObjectToStruct

func (c *Client) ObjectToStruct(ctx context.Context, name string, data any) error

ObjectToStruct creates a struct from an object. Supported field types: Strings, Ints, Uints, Pointers to structs, Structs, Booleans, Floats.

DO NOT USE CYCLIC STRUCTURES.

func (*Client) SetMany

func (c *Client) SetMany(ctx context.Context, kv map[string]string, opts ...SetOptions) (res gost.Result[gost.Nothing])

SetMany sets a set of vals for gRPCis.

func (*Client) SetManyOpts

func (c *Client) SetManyOpts(ctx context.Context, keyValue map[string]Value) (res gost.Result[gost.Nothing])

SetManyOpts gets a lot of vals from gRPCis with opts.

func (*Client) SetOne

func (c *Client) SetOne(ctx context.Context, key, val string, opts ...SetOptions) (res gost.Result[int32])

SetOne sets the val for the key to gRPCis.

func (*Client) SetToAll

func (c *Client) SetToAll(ctx context.Context, key, val string, opts ...SetOptions) (res gost.Result[gost.Nothing])

SetToAll sets the val for the key on all servers.

func (*Client) StructToObject

func (c *Client) StructToObject(ctx context.Context, name string, structure any) (*Object, error)

StructToObject creates an object from a struct.

DO NOT USE CYCLIC STRUCTURES.

type Config

type Config struct {
	Credentials Credentials
}

type ConnectOptions

type ConnectOptions struct {
	Server *int32
}

type CreateUserOptions

type CreateUserOptions struct {
	Level Level
}

type Credentials

type Credentials struct {
	Login    string
	Password string
}

type DeleteKeyOptions

type DeleteKeyOptions struct {
	Server *int32
}

type DeleteObjectOptions

type DeleteObjectOptions struct {
	Server *int32
}

type DeleteOptions

type DeleteOptions struct {
	Server *int32
}

type GetFromObjectOptions

type GetFromObjectOptions struct {
	Server *int32
}

type GetOptions

type GetOptions struct {
	Server *int32
}

type IsObjectOptions

type IsObjectOptions struct {
	Server *int32
}

type Key

type Key struct {
	Key     string
	Options GetOptions
}

type Level

type Level byte
const (
	DefaultLevel Level = iota
	RestrictedLevel
	SecretLevel
)

type Object

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

func (*Object) Attach

func (i *Object) Attach(ctx context.Context, name string, opts ...AttachToObjectOptions) (res gost.Result[gost.Nothing])

Attach attaches the object to another object.

func (*Object) DeleteKey

func (i *Object) DeleteKey(ctx context.Context, key string, opts ...DeleteKeyOptions) (res gost.Result[gost.Nothing])

DeleteKey deletes the attribute from the object.

func (*Object) DeleteObject

func (i *Object) DeleteObject(ctx context.Context, opts ...DeleteObjectOptions) (res gost.Result[gost.Nothing])

DeleteObject deletes the object.

func (*Object) Get

func (i *Object) Get(ctx context.Context, key string, opts ...GetFromObjectOptions) (res gost.Result[string])

Get gets the value for the key from the specified object.

func (*Object) JSON

func (i *Object) JSON(ctx context.Context, opts ...ObjectToJSONOptions) (res gost.Result[string])

JSON returns the object in JSON.

func (*Object) Name

func (i *Object) Name() string

Name returns the name of the object.

func (*Object) Object

func (i *Object) Object(ctx context.Context, name string, opts ...ObjectOptions) (res gost.Result[*Object])

Object returns a new or an existing object.

func (*Object) Set

func (i *Object) Set(ctx context.Context, key, value string, opts ...SetToObjectOptions) (res gost.Result[int32])

Set sets the value for the key in the specified object.

func (*Object) Size

func (i *Object) Size(ctx context.Context, opts ...SizeOptions) (res gost.Result[uint64])

Size returns the size of the object.

type ObjectOptions

type ObjectOptions struct {
	Server *int32
	Level  Level
}

type ObjectToJSONOptions

type ObjectToJSONOptions struct {
	Server *int32
}

type Options

type Options struct {
	Server int32
	Unique bool
}

type SetOptions

type SetOptions struct {
	Server   *int32
	ReadOnly bool
	Unique   bool
	Level    Level
}

type SetToObjectOptions

type SetToObjectOptions struct {
	Server   *int32
	ReadOnly bool
}

type SizeOptions

type SizeOptions struct {
	Server *int32
}

type Value

type Value struct {
	Value   string
	Options SetOptions
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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