Documentation ¶
Index ¶
- Constants
- Variables
- type HaAddress
- type HaOutput
- type HaStore
- func (has *HaStore) Addresses() ([]HaAddress, error)
- func (has *HaStore) Close() error
- func (has *HaStore) Delete(key string) error
- func (has *HaStore) Get(key string, value interface{}) error
- func (has *HaStore) List(values interface{}, patterns ...string) error
- func (has *HaStore) ListRaw() (map[string]string, error)
- func (has *HaStore) LogLevel(level int)
- func (has *HaStore) Logger() *log.Logger
- func (has *HaStore) Set(key string, value interface{}) error
- func (has *HaStore) Start(peers ...string) error
- type Options
- type StaticStore
- func (s *StaticStore) Addresses() ([]HaAddress, error)
- func (s *StaticStore) BindTo(addr *HaAddress)
- func (s *StaticStore) Close() error
- func (s *StaticStore) Delete(key string) error
- func (s *StaticStore) Get(key string, value interface{}) error
- func (s *StaticStore) List(values interface{}, patterns ...string) error
- func (s *StaticStore) ListRaw() (map[string]string, error)
- func (s *StaticStore) LogLevel(level int)
- func (s *StaticStore) Logger() *log.Logger
- func (s *StaticStore) Set(key string, value interface{}) error
- func (s *StaticStore) Sync() error
- type Store
Constants ¶
const ( // DEBUG log level DEBUG = 0 // INFO log level INFO = 1 // WARNING log level WARNING = 2 // ERROR log level ERROR = 3 )
Variables ¶
var ( // ErrMissingPath for a wrong configuration ErrMissingPath = errors.New("NewStaticStore missing Path") // ErrKeyNotFound for a given key which does not exist ErrKeyNotFound = errors.New("DB Key not found") )
Functions ¶
This section is empty.
Types ¶
type HaAddress ¶
HaAddress is a helper struct to define our listening ip:port addresses between Serf & Raft
func NewAddress ¶
NewAddress create a new HaAddress with an ip string and a port int
type HaOutput ¶
type HaOutput struct {
// contains filtered or unexported fields
}
HaOutput implements "io.Writer" interface to filter output content.
func NewOutputStr ¶
NewOutputStr create a new HaOutput thanks a log level string ("debug", "warning", "error", "info")
type HaStore ¶
type HaStore struct { Bind *HaAddress Advertise *HaAddress // contains filtered or unexported fields }
HaStore is a wrapper of our StaticStore with Serf & Raft running to replicate all data between nodes.
func NewHaStore ¶
NewHaStore create a new HaStore, "bindAddr" will be the local IP:PORT listening address "advAddr" will be the advertised IP:PORT address (for NAT Traversal)
func (*HaStore) Delete ¶
Delete forware the "key"/"value" as an UserEvent to our Serf cluster This event will be catched by the Leader of the Raft server to apply it everywhere
func (*HaStore) List ¶
List retreive all values in our Store, you could filter by keys with wildcard patterns (i.e. "prefix_*")
type Options ¶
type Options struct { // Path is the file path to the BoltDB to use Path string // BoltDB file mode FileMode os.FileMode // Bucket to create at the beginning Bucket string // BoltOptions contains any specific BoltDB options you might // want to specify [e.g. open timeout] BoltOptions *bolt.Options // NoSync causes the database to skip fsync calls after each // write to the log. This is unsafe, so it should be used // with caution. NoSync bool // Where our default Logger will output logs LogOutput io.Writer // Logger to use everywhere, if nil a new log.Logger will be defined with LogOutput Logger *log.Logger }
Options contains all the configuraiton used to open the BoltDB
type StaticStore ¶
type StaticStore struct {
// contains filtered or unexported fields
}
StaticStore is a wrapper of BoltDB which implements our Store interface
func NewStaticStore ¶
func NewStaticStore(options *Options) (*StaticStore, error)
NewStaticStore uses the supplied options to open the BoltDB and prepare it for use as a raft backend.
func (*StaticStore) Addresses ¶
func (s *StaticStore) Addresses() ([]HaAddress, error)
Addresses return slice which contains a signe entry : "GetPrivateIP" from go-sockaddr
func (*StaticStore) BindTo ¶
func (s *StaticStore) BindTo(addr *HaAddress)
BindTo change the behavior of "Addresses" function to return another IP address
func (*StaticStore) Close ¶
func (s *StaticStore) Close() error
Close is used to gracefully close the DB connection.
func (*StaticStore) Delete ¶
func (s *StaticStore) Delete(key string) error
Delete removes the "key" in BoltDB
func (*StaticStore) Get ¶
func (s *StaticStore) Get(key string, value interface{}) error
Get retreive the value associated to the "key" in BoltDB and "json.Unmashal" it to "value"
func (*StaticStore) List ¶
func (s *StaticStore) List(values interface{}, patterns ...string) error
List retreive all values in our BoltDB, evertyhing will be "unmarshal" thanks a JSON format BoltDB keys could be filtering thanks wildcard patterns
func (*StaticStore) ListRaw ¶
func (s *StaticStore) ListRaw() (map[string]string, error)
ListRaw retrive all "key"/"value" with any modification
func (*StaticStore) LogLevel ¶
func (s *StaticStore) LogLevel(level int)
LogLevel change the level of logs, only available with our HabOuput
func (*StaticStore) Logger ¶
func (s *StaticStore) Logger() *log.Logger
Logger return the log.Logger object
func (*StaticStore) Set ¶
func (s *StaticStore) Set(key string, value interface{}) error
Set "json.Mashal" the "value" and store it in BoltDB with the specified "key"
func (*StaticStore) Sync ¶
func (s *StaticStore) Sync() error
Sync performs an fsync on the database file handle. This is not necessary under normal operation unless NoSync is enabled, in which this forces the database file to sync against the disk.
type Store ¶
type Store interface { Close() error ListRaw() (map[string]string, error) List(interface{}, ...string) error Get(string, interface{}) error Set(string, interface{}) error Delete(string) error Addresses() ([]HaAddress, error) Logger() *log.Logger LogLevel(int) }
Store interface to define useful functions