37 lines
836 B
Markdown
37 lines
836 B
Markdown
# 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
|
|
|
|
# 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)
|
|
}
|
|
```
|