db

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2018 License: MIT Imports: 11 Imported by: 0

README

Environment variables database

GoDoc Build Status Code Coverage Go Report Card

Documentation

Index

Constants

View Source
const (
	VarIDPrefix = "_"
	VarIDTie    = "."
)

envTie is used to join two environment'values.

Variables

View Source
var (
	ErrAlreadyExists = errors.New("already exists")
	ErrInvalid       = errors.New("invalid data")
	ErrMissing       = errors.New("missing data")
	ErrNotFound      = errors.New("not found")
	ErrOutOfBounds   = errors.New("out of bounds")
	ErrUnknown       = errors.New("unknown data")
)

Error messages.

View Source
var DefaultEnv = &Env{Values: []string{""}}

DefaultEnv is the default Environment used to build the variables's values.

View Source
var Kinds = []Kind{Int, Float, Bool, String}

Kinds returns the list of available kinds.

Functions

This section is empty.

Types

type AutoIncrementer

type AutoIncrementer interface {
	AutoIncrementing() bool
}

AutoIncrementer must be implement to manage the kind of primary key.

type Data

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

Data manages the collection of buckets.

func Open

func Open(db string) (*Data, error)

Open opens a new connection to the database.

func (*Data) AddEnv

func (m *Data) AddEnv(s *Env) error

AddEnv creates a env or returns on error if already exists.

func (*Data) AddNode

func (m *Data) AddNode(n *Node) error

AddNode adds a server as cache or returns on error if already exists.

func (*Data) AddProject

func (m *Data) AddProject(p *Project) error

AddProject creates a project or returns on error if already exists.

func (*Data) AddVarInProject

func (m *Data) AddVarInProject(d *Var, project string) error

AddVarInProject adds a var on a project with its name.

func (*Data) BindEnvInProject

func (m *Data) BindEnvInProject(s *Env, project string) error

BindEnvInProject binds a env to a project

func (*Data) Close

func (m *Data) Close() error

Close closes the connection to database.

func (*Data) DeleteNode

func (m *Data) DeleteNode(n *Node) error

DeleteNode removes a server.

func (*Data) DeleteProject

func (m *Data) DeleteProject(p *Project) error

DeleteProject removes a project.

func (*Data) DeleteVarInProject

func (m *Data) DeleteVarInProject(d *Var, project string) error

DeleteVarInProject removes a variable in the given project.

func (*Data) Envs

func (m *Data) Envs(ignores ...uint64) ([]Keyer, error)

Envs returns the list of available envs and skip those to ignore as asked.

func (*Data) GetEnv

func (m *Data) GetEnv(key uint64) (Keyer, error)

GetEnv returns an error or the env if it exists.

func (*Data) GetNode

func (m *Data) GetNode(key string) (Keyer, error)

GetNode returns an error or the node if it exists.

func (*Data) GetProject

func (m *Data) GetProject(key string) (Keyer, error)

GetProject returns an error or the project if it exists. It contains all its properties, as the list of vars or envs.

func (*Data) GetVarInProject

func (m *Data) GetVarInProject(key uint64, project string) (Keyer, error)

GetVarInProject returns an error or the var if it exists.

func (*Data) Nodes

func (m *Data) Nodes() ([]Keyer, error)

Nodes returns the list of server used as RPC cache.

func (*Data) Projects

func (m *Data) Projects() ([]Keyer, error)

Projects returns the list of projects.

func (*Data) UnbindEnvInProject

func (m *Data) UnbindEnvInProject(s *Env, project string) error

UnbindEnvInProject unbinds a env to a project.

func (*Data) UpdateVarInProject

func (m *Data) UpdateVarInProject(d *Var, project string) error

UpdateVarInProject updates a project's var or returns in error if not exists.

func (*Data) UpsertEnv

func (m *Data) UpsertEnv(s *Env) error

UpsertEnv updates or creates a env if not exists.

func (*Data) UpsertProject

func (m *Data) UpsertProject(p *Project) error

UpsertProject updates or creates if not exists a project.

type Deploy

type Deploy struct {
	ID           uint64                 `json:"id"`
	ProjectID    string                 `json:"project_id"`
	ServerList   []*Server              `json:"servers"`
	ItemList     map[string]interface{} `json:"items"`
	LastUpdateTs time.Time              `json:"upd_ts"`
}

Deploy represents one deployment.

func NewDeploy

func NewDeploy(projectID string, servers ...string) *Deploy

NewDeploy returns a new instance of Deploy.

func (*Deploy) AutoIncrementing

func (d *Deploy) AutoIncrementing() bool

AutoIncrementing return true in order to have auo-increment primary key.

func (*Deploy) Key

func (d *Deploy) Key() []byte

Key returns the key of the env.

func (*Deploy) SetKey

func (d *Deploy) SetKey(k []byte) error

SetKey returns if error if the change of the key failed.

func (*Deploy) Updated

func (d *Deploy) Updated()

Updated changes the last update date of the deployment.

func (*Deploy) Valid

func (d *Deploy) Valid(insert bool) error

Valid checks if all required data as well formed.

type Env

type Env struct {
	ID           uint64    `json:"id"`
	Name         string    `json:"name"`
	Values       []string  `json:"vals"`
	LastUpdateTs time.Time `json:"upd_ts"`
}

Env represents a env of execution.

func NewEnv

func NewEnv(name string, values []string) *Env

NewEnv returns a new instance of Environment.

func (*Env) AutoIncrementing

func (s *Env) AutoIncrementing() bool

AutoIncrementing return true in order to have auo-increment primary key.

func (*Env) Default

func (s *Env) Default() bool

Default returns true if the environment is a default env for Eve.

func (*Env) Key

func (s *Env) Key() []byte

Key returns the key of the env.

func (*Env) SetKey

func (s *Env) SetKey(k []byte) error

SetKey returns if error if the change of the key failed.

func (*Env) Updated

func (s *Env) Updated()

Updated changes the last update date of the environment.

func (*Env) Valid

func (s *Env) Valid(insert bool) error

Valid checks if all required data as well formed.

type EnvsValue

type EnvsValue map[string]interface{}

EnvsValue contains all variable's values by given envs. Key combines environment names with a colon.

type Keyer

type Keyer interface {
	Key() []byte
	SetKey([]byte) error
}

Keyer is implemented by any value that has a Key method, which returns the “key” identifier for that value.

type Kind

type Kind int

Kind specifies the kind of value.

const (
	// Unknown values
	Unknown Kind = iota

	// Numeric values
	Int
	Float

	// Non-numeric values
	Bool
	String
)

List of value's kind.

func NewKind

func NewKind(kind int) Kind

NewKind returns an instance a Kind.

func (Kind) Assert

func (k Kind) Assert(value interface{}) (v interface{}, ok bool)

Assert returns true if the value holds its kind.

func (Kind) Int

func (k Kind) Int() int

Int gives the value of the kind.

func (Kind) Parse

func (k Kind) Parse(s string) (interface{}, error)

Parse converts the string to expected value.

func (Kind) Pattern

func (k Kind) Pattern() string

Pattern returns the regex pattern to use to validate input.

func (Kind) String

func (k Kind) String() string

String gives the name of the kind.

func (Kind) ZeroString

func (k Kind) ZeroString() string

ZeroString returns the zero value of the kind as string.

func (Kind) ZeroValue

func (k Kind) ZeroValue() interface{}

ZeroValue returns the zero value of the kind.

type Node

type Node struct {
	Addr  string    `json:"naddr"`
	AddTs time.Time `json:"upd_ts"`
}

Node represents a server used as cache by EVE.

func NewNode

func NewNode(server string) *Node

NewNode creates a new instance of a server node.

func (*Node) AutoIncrementing

func (c *Node) AutoIncrementing() bool

AutoIncrementing return true in order to have auo-increment primary key.

func (*Node) ID

func (c *Node) ID() string

ID returns the key of the server node as string

func (*Node) Key

func (c *Node) Key() []byte

Key returns the key of the cache.

func (*Node) SetKey

func (c *Node) SetKey(k []byte) error

SetKey returns if error if the change of the key failed.

func (*Node) Updated

func (c *Node) Updated()

Updated must be implemented for the Valuable interface.

func (*Node) Valid

func (c *Node) Valid(insert bool) error

Valid checks if all required data as well formed.

type Project

type Project struct {
	ID           string    `json:"id"`
	Name         string    `json:"name"`
	Description  string    `json:"desc,omitempty"`
	LastUpdateTs time.Time `json:"upd_ts"`
	LastDeployTs time.Time `json:"dep_ts,omitempty"`
	EnvList      []uint64  `json:"envs,omitempty"`
	VarList      []uint64  `json:"vars,omitempty"`
	// contains filtered or unexported fields
}

Project represents the container of the vars.

func NewProject

func NewProject(name, desc string) *Project

NewProject creates a new instance of Project.

func (*Project) AddEnv

func (p *Project) AddEnv(e *Env) error

AddEnv adds a env to the project. Only two dimensions are managed by the system.

func (*Project) AddVar

func (p *Project) AddVar(v *Var) error

AddVar adds a variable to the project.

func (*Project) AutoIncrementing

func (p *Project) AutoIncrementing() bool

AutoIncrementing return false in order to manage primary by itself.

func (*Project) DeleteEnv

func (p *Project) DeleteEnv(e *Env) (err error)

DeleteEnv removes a project's env.

func (*Project) DeleteVar

func (p *Project) DeleteVar(v *Var) (err error)

DeleteVar removes a project's variable.

func (*Project) Deployed

func (p *Project) Deployed() bool

Deployed returns true if the project if already deployed.

func (*Project) Envs

func (p *Project) Envs() (envs []Keyer)

Envs returns the envs of the project.

func (*Project) EnvsValues

func (p *Project) EnvsValues() (firstEnvValues, secondEnvValues []string)

EnvsValues returns all available values by environment.

func (*Project) FirstEnv

func (p *Project) FirstEnv() *Env

FirstEnv is an alias to access the first environment.

func (*Project) Hash

func (p *Project) Hash(s string) []byte

Hash returns a unique hash for the string in the project's context.

func (*Project) Key

func (p *Project) Key() []byte

Key returns the key used to store it.

func (*Project) SecondEnv

func (p *Project) SecondEnv() *Env

SecondEnv is an alias to access the second environment.

func (*Project) SetKey

func (p *Project) SetKey(k []byte) error

SetKey returns if error if the change of the key failed.

func (*Project) ToDeploy

func (p *Project) ToDeploy(firstEnvValues, secondEnvValues []string) map[string]interface{}

ToDeploy returns the list of key / value to deploy. This list if filtered by the values of the first and the second env. Variable to remove are given with nil value.

func (*Project) Updated

func (p *Project) Updated()

Updated changes the last update date of the variable.

func (*Project) Valid

func (p *Project) Valid(insert bool) error

Valid checks if all required data as well formed.

func (*Project) Vars

func (p *Project) Vars() []Keyer

Vars returns all the variables of the project.

type Server

type Server struct {
	TCPAddr   string `json:"naddr"`
	Succeeded bool   `json:"ok,omitempty"`
}

Server represents one node with the status of the deployment on it.

type Updater

type Updater interface {
	Updated()
}

Updater is implemented to mark as updated the data.

type Validator

type Validator interface {
	Valid(insert bool) error
}

Validator is implemented to check if the data is correct.

type Valuable

type Valuable interface {
	AutoIncrementer
	Keyer
	Updater
	Validator
}

Valuable must be implemented by any value to store.

type Var

type Var struct {
	ID           uint64    `json:"id"`
	Name         string    `json:"name"`
	Kind         Kind      `json:"kind"`
	Values       EnvsValue `json:"vals,omitempty"`
	LastUpdateTs time.Time `json:"upd_ts"`
	DeletionTs   time.Time `json:"del_ts,omitempty"`
	Partial      bool
}

Var represents a variable.

func NewVar

func NewVar(name string, kind int) *Var

NewVar returns an instance a Var.

func (*Var) AutoIncrementing

func (v *Var) AutoIncrementing() bool

AutoIncrementing return true in order to have auo-increment primary key.

func (*Var) CleanValues

func (v *Var) CleanValues(env1, env2 *Env) error

CleanValues ensures that all values use the kind of the variable. It also checks that only the current environments values are used. A partial result is returned if one the environment does not exist. It return on error if the kind of value does not match.

func (*Var) Deleted

func (v *Var) Deleted() bool

Deleted returns true if the variable has been deleted.

func (*Var) Key

func (v *Var) Key() []byte

Key returns the key of the variable.

func (*Var) NewValues

func (v *Var) NewValues(env1, env2 *Env) EnvsValue

NewValues returns a new map of values for the given environments. Each value use the default value of the kind of the variable.

func (*Var) SetKey

func (v *Var) SetKey(k []byte) error

SetKey returns if error if the change of the key failed.

func (*Var) SetValues

func (v *Var) SetValues(m map[string]string) (err error)

SetValues sets the values of the variable without any check on the environments behind.

func (*Var) Updated

func (v *Var) Updated()

Updated changes the last update date of the variable.

func (*Var) Valid

func (v *Var) Valid(insert bool) error

Valid checks if the variable has required properties.

type VarID

type VarID struct {
	EnvValue1,
	EnvValue2 string
}

VarID is the internal name of the variable for the combination of the environments values.

func NewVarID

func NewVarID(s string) *VarID

NewVarID returns a VarID by parsing its string representation.

func (*VarID) String

func (v *VarID) String() string

String returns the string representation of the VarID.

Jump to

Keyboard shortcuts

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