This project is a simple in-memory data store implemented in Go (Golang) with support for:
- Strings and Lists
- Time-To-Live (TTL) keys
- Authentication (JWT)
- Data Persistence (File-based & Database Support)
- REST API
- Go Client Library
- Unit & Integration Tests
- Docker Deployment
- ✅ String & List operations (Set, Get, Delete, Push, Pop)
- ✅ TTL (Automatic expiration of keys)
- ✅ Authentication using JWT (JSON Web Tokens)
- ✅ Data Persistence (Saving data to disk & loading on startup or saving to a database)
- ✅ Modular architecture (Separate core, API, client, and persistence modules)
- ✅ Docker Support for deployment
- ✅ Test coverage with Unit & Integration tests
/golang-memory-store
├── /cmd
│ └── /server # Main Application Entry Point
├── /internal
│ ├── /api # REST API Handlers
│ ├── /auth # Authentication Layer (JWT)
│ ├── /core # Core Logic (In-memory Store)
│ ├── /client # Go Client Library (SDK)
│ ├── /persistence # Data Persistence Layer (File & Database Storage)
├── /tests # Integration Tests
├── /Dockerfile
├── /Makefile
├── /go.mod
├── /go.sum
└── /README.md
- Go 1.20 or above
- Docker (Optional)
github.com/golang-jwt/jwt/v4
github.com/gorilla/mux
gorm.io/gorm
gorm.io/driver/sqlite
gorm.io/driver/postgres
git clone https://github.com/techlando/golang-memory-store.git
cd golang-memory-store
go mod tidy
go run ./cmd/server
export ENABLE_PERSISTENCE=true
export DB_TYPE=sqlite
export DB_DSN=gorm.db
export DB_TYPE=postgres
export DB_DSN="user=youruser password=yourpass dbname=yourdb port=5432 sslmode=disable"
go test -v ./internal/core
Ensure the server is running on http://localhost:8080
.
go test -v ./tests
curl -X POST http://localhost:8080/token -H "Content-Type: application/json" -d '{"username":"testuser"}'
curl -X POST http://localhost:8080/set -H "Authorization: Bearer YOUR_JWT_TOKEN" -H "Content-Type: application/json" -d '{"key": "foo", "value": "bar", "ttl": 60}'
curl -X GET http://localhost:8080/get/foo -H "Authorization: Bearer YOUR_JWT_TOKEN"
curl -X DELETE http://localhost:8080/delete/foo -H "Authorization: Bearer YOUR_JWT_TOKEN"
curl -X POST http://localhost:8080/list/push -H "Authorization: Bearer YOUR_JWT_TOKEN" -H "Content-Type: application/json" -d '{"key": "mylist", "value": "item1"}'
curl -X POST http://localhost:8080/list/pop/mylist -H "Authorization: Bearer YOUR_JWT_TOKEN"
docker build -t golang-memory-store .
docker run -p 8080:8080 -d golang-memory-store
Command | Description |
---|---|
make build |
Builds the application |
make run |
Runs the application locally |
make test |
Runs all tests |
make docker-build |
Builds the Docker image |
make docker-run |
Runs the Docker container |
make clean |
Cleans up build files |
See ClientLibraryAndDeploymentDocs.md