state/Readme.md

994 B

State

From time to time i need some small state persistens like e.g. for a bot how count the numbers of messages with a special value. I want to store them somewhere to not cound double without thin king about it so i store a struct as json.

This pkg will provice Methodes to store (read and write) structs to the hdd.

Idear for later:

  • Store in S3 as well
  • Function for dealing with lists on store. Like add to list, chcik if exists in list and so on
  • IF deal with list store each element in a seperate key and a list of index in one. PRovide filtert lists that it not needed to keep the complet list in ram

Working with State

Write State to HDD

state, err := NewLocaleFilesystem("data/")
if err != nil {
    panic(err)
}

err = satate.StoreState("key", data)
if err != nil {
    panic(err)
}

Get State from HDD

state, err := NewLocaleFilesystem("data/")
if err != nil {
    panic(err)
}

err = satate.GetState("key", &data)
if err != nil {
    panic(err)
}