A lightweight, high-performance, in-memory key-value store built with Go. This project provides a simple REST API to perform basic operations like Set
, Get
, and Delete
on key-value pairs. It's perfect for learning Go, building small-scale applications, or as a starting point for more complex projects.
- Learn Go: A great way to understand Go's concurrency model, HTTP server, and package organization.
- Lightweight: No external dependencies—just pure Go.
- Extensible: Easily extendable to add features like persistence, transactions, or advanced querying. (Hopefully will be able to implement that in future.)
- Production-Ready: Built with best practices like concurrency safety and clean code structure.
- In-Memory Storage: Fast and efficient key-value storage using Go's native
map
andsync.RWMutex
for concurrency safety. - REST API: Exposes a simple HTTP API to interact with the database.
- Concurrency Safe: Built with
sync.RWMutex
to handle concurrent read/write operations. - Easy to Use: Simple and intuitive API endpoints for
Set
,Get
, andDelete
operations. - Lightweight: No external dependencies—just pure Go.
- Go 1.21 or higher installed on your machine.
- Basic knowledge of HTTP and REST APIs.
- (Optional) Postman or any HTTP client for testing.
-
Clone the repository:
git clone https://github.com/nomannaq/simple-database-golang
-
Navigate to the project directory:
cd my-database-project
-
Build and run the project:
go run cmd/my-database/main.go
-
The server will start on
http://localhost:8000
.
- Method:
POST
- URL:
/set
- Request Body (JSON):
{ "key": "name", "value": "John Doe" }
- Response:
Key 'name' set successfully
- Method:
GET
- URL:
/get?key=<key>
- Example:
GET /get?key=name
- Response (JSON):
{ "name": "John Doe" }
- Method:
DELETE
- URL:
/delete?key=<key>
- Example:
DELETE /delete?key=name
- Response:
Key 'name' deleted successfully
-
Set a key-value pair:
curl -X POST -H "Content-Type: application/json" -d '{"key": "name", "value": "John Doe"}' http://localhost:8000/set
-
Get a value by key:
curl http://localhost:8000/get?key=name
-
Delete a key-value pair:
curl -X DELETE http://localhost:8000/delete?key=name
- Import the provided Postman collection (link to collection).
- Use the pre-configured requests to test the API.
my-database-project/
├── cmd/
│ └── main/
│ └── main.go # Entry point of the application
├── internal/
│ ├── database/
│ │ └── database.go # Core database logic
│ └── handlers/
│ └── handlers.go # HTTP handlers for the API
├── go.mod # Go module file
├── go.sum # Dependency checksum file
└── README.md # This file
This project is licensed under the MIT License. See the LICENSE file for details.
- Built with ❤️ using Go.
- Inspired by simple key-value stores like Redis.
- Special thanks to the Go community for amazing resources and tools.