Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/draganm/statemate
https://github.com/draganm/statemate
Last synced: 9 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/draganm/statemate
- Owner: draganm
- License: mit
- Created: 2023-10-10T20:14:39.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-10-17T21:20:54.000Z (3 months ago)
- Last Synced: 2024-10-30T09:38:22.707Z (2 months ago)
- Language: Go
- Size: 42 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# StateMate Go Library
## Overview
StateMate is a Go library designed for storing state as key-value pairs with efficient I/O operations and concurrency support.
## Features
- Memory-mapped files for efficient I/O.
- Thread-safe via read-write mutexes.
- Generics support for custom unsigned integer key types.
- Dynamic resizing of data and index files.
- Optional index gap allowance.## Requirements
- Go 1.18 or higher for generics support.
## InstallationInstall the package using:
```
go get -u github.com/draganm/statemate
```## Usage
### Initialize a StateMate instance
```go
options := statemate.Options{ AllowGaps: true }
sm, err := statemate.Open[uint64]("datafile", options)
if err != nil {
// Handle error
}
```### Append Data
```go
err := sm.Append(1, []byte("some data"))
if err != nil {
// Handle error
}
```### Read Data
```go
err := sm.Read(1, func(data []byte) error {
// Process data
return nil
})
if err != nil {
// Handle error
}
```### Check if Empty
```go
isEmpty := sm.IsEmpty()
```### Get Last Index
```go
lastIndex := sm.LastIndex()
```## Errors
- `ErrIndexMustBeIncreasing`: The provided index must be greater than the last index.
- `ErrIndexGapsAreNotAllowed`: If `AllowGaps` is `false`, indexes must be consecutive.
- `ErrNotFound`: The requested index was not found.## License
MIT License