kvstore

package module
v0.0.0-...-4336eae Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2016 License: MIT Imports: 5 Imported by: 4

README

kvstore

GoDoc GoCard

kvstore - simple in-memory key-value store with persistense.

Features

  • setter Expire()

License

The MIT License (MIT), see LICENSE.

Copyright (c) 2016 Alexey Kovrizhkin ak@elfire.ru

Documentation

Overview

Package kvstore is a simple key-value in memory store with persistense in json file

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Config

func Config(c *Flags) func(s *Store) error

Config sets store config from flag var

Types

type DataMap

type DataMap map[string]StoreData

DataMap holds stored items

type Flags

type Flags struct {
	StoreName string `long:"store_file" default:"store.json" description:"File to store sent codes at program exit"`
}

Flags is a package flags sample in form ready for use with github.com/jessevdk/go-flags

type Store

type Store struct {
	Log    *log.Logger
	Config *Flags
	// contains filtered or unexported fields
}

Store holda all store attributes

func New

func New(t StoreData, logger *log.Logger, options ...func(*Store) error) (*Store, error)

New - store constructor

func (*Store) Del

func (s *Store) Del(key string) bool

Del deletes a key and returns true if it was founded

func (*Store) Destroy

func (s *Store) Destroy()

Destroy saves store data into file

func (Store) Get

func (s Store) Get(key string) (StoreData, bool)

Get returns data by key and true if it was founded

func (Store) Keys

func (s Store) Keys() []string

Keys returns list of store keys

func (*Store) Load

func (s *Store) Load()

Load reads json file and places it in store

func (*Store) Save

func (s *Store) Save() bool

Save saves store into json file

func (*Store) Set

func (s *Store) Set(key string, d StoreData) bool

Set saves data in store and returns true if key was rewritten

type StoreData

type StoreData interface {
	//	UnmarshalJSON(b []byte) (err error)
	Init() (StoreData, error)
	Fetch(buf []byte) (StoreData, error)
}

StoreData interface holds sore item methods

Jump to

Keyboard shortcuts

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