itisadb

package module
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2024 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 :8888.
func main() {
	ctx := context.TODO()

	db := itisadb.New(ctx, ":8888").Unwrap()

	db.SetOne(ctx, "qwe", "111").Unwrap()

	if x := db.GetOne(ctx, "qwe").Unwrap().Value; x != "111" {
		log.Fatal("Wrong value")
	} else {
		log.Println("Value:", x)
	}
}

Documentation

Index

Constants

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

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")
View Source
var Internal internal

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])

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) (res gost.ResultN)

func (*Client) ChangePassword

func (c *Client) ChangePassword(ctx context.Context, login, newPassword string) (res gost.ResultN)

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]Value])

GetMany gets a lot of values from gRPCis.

func (*Client) GetManyOpts

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

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[Value])

GetOne gets the value by the key from gRPCis.

func (*Client) NewUser added in v0.15.8

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

func (*Client) Object

func (c *Client) Object(name string) *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]ValueSpec) (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 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 KeySpec added in v0.13.0

type KeySpec struct {
	Key     string
	Options GetOptions
}

type Level

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

func (Level) String added in v0.15.2

func (l Level) String() string

type NewUserOptions added in v0.15.8

type NewUserOptions struct {
	Level Level
}

type Object

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

func (*Object) Attach

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

Attach attaches the object to another object.

func (*Object) Create added in v0.16.0

func (o *Object) Create(ctx context.Context, opts ...ObjectOptions) (res gost.Result[*Object])

func (*Object) DeleteKey

func (o *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 (o *Object) DeleteObject(ctx context.Context, opts ...DeleteObjectOptions) (res gost.Result[gost.Nothing])

DeleteObject deletes the object.

func (*Object) Get

func (o *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) Is added in v0.16.0

func (o *Object) Is(ctx context.Context) (res gost.Result[bool])

Is checks if it is an object or not.

func (*Object) JSON

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

JSON returns the object in JSON.

func (*Object) Name

func (o *Object) Name() string

Name returns the name of the object.

func (*Object) Object

func (o *Object) Object(name string) *Object

Object returns a new or an existing object.

func (*Object) Server added in v0.15.2

func (o *Object) Server() int32

Server returns the server ID of the object.

func (*Object) Set

func (o *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 (o *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 RAM added in v0.11.0

type RAM struct {
	Total     uint64
	Available uint64
}

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
	ReadOnly bool
	Level    Level
}

func (Value) MarshalJSON added in v0.15.2

func (v Value) MarshalJSON() ([]byte, error)

type ValueSpec added in v0.13.0

type ValueSpec 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