This project provides a key-value storage API using Go and bbolt to store the database. Users can create their own key-value store via Telegram. With the ability to easily transfer storage to your server.
- Why?
- Cloud usage
- Telegram Bot Commands
- API Endpoints
- Migrate on your server
- Project Structure
- Requirements
- Dependencies
Because I can. I'm tired of mongo/postgresql/etc support for my small projects. Endless choice of providers, headache with migration to your servers, etc. (I also wanted to practice golang)
Make coding fun again.
- Start telegram bot - https://t.me/kvrest_bot
- Send /start in bot
Displays the documentation for all available commands to the user.
Creates a new key-value (KV) store for the user. It generates a unique API key and creates a new BoltDB file to store the user's data. The API key is then sent back to the user.
Allows the user to change their existing API key. It generates a new API key, renames the BoltDB file with the new key, and sends the new API key to the user.
Allows the user to view the keys stored in a specific bucket within their KV store. The user needs to provide the name of the bucket they want to view.
Usage: /view_bucket BUCKET_NAME
Lists all the buckets that the user has created in their KV store.
Allows the user to download their entire KV store as a BoltDB file. The bot will send the file directly to the user.
PUT /{bucketName}
name type data type description bucketNamerequired string Name of the bucket to create
http code content-type response 200text/plain;charset=UTF-8Bucket created successfully405text/plain;charset=UTF-8Bucket name 'system' not allowed500text/plain;charset=UTF-8Internal Server Error
curl -X PUT -H "API-KEY: your_api_key" https://kvrest.dev/api/yourBucketName
DELETE /{bucketName}
name type data type description bucketNamerequired string Name of the bucket to delete
http code content-type response 200text/plain;charset=UTF-8Bucket deleted successfully500text/plain;charset=UTF-8Internal Server Error
curl -X DELETE -H "API-KEY: your_api_key" https://kvrest.dev/api/yourBucketName
POST /buckets
http code content-type response 200application/json{"buckets": ["example-buckets1", "example-buckets2"]}500text/plain;charset=UTF-8Internal Server Error
curl -X POST -H "API-KEY: your_api_key" https://kvrest.dev/api/buckets
PUT /{bucketName}/{key}
name type data type description bucketNamerequired string Name of the bucket keyrequired string Name of the key within the bucket None (body) required object (JSON) Value to be set for the key
http code content-type response 200text/plain;charset=UTF-8None 400text/plain;charset=UTF-8Bad Request500text/plain;charset=UTF-8Internal Server Error
curl -X PUT -H "API-KEY: your_api_key" -H "Content-Type: application/json" --data '{"key": "value"}' https://kvrest.dev/api/yourBucketName/yourKey
GET /{bucketName}/{key}
name type data type description bucketNamerequired string Name of the bucket keyrequired string Name of the key within the bucket
http code content-type response 200application/jsonJSON object representing the value 404text/plain;charset=UTF-8Key not found500text/plain;charset=UTF-8Internal Server Error
curl -X GET -H "API-KEY: your_api_key" https://kvrest.dev/api/yourBucketName/yourKey
DELETE /{bucketName}/{key}
name type data type description bucketNamerequired string Name of the bucket keyrequired string Name of the key within the bucket
http code content-type response 200text/plain;charset=UTF-8None 500text/plain;charset=UTF-8Internal Server Error
curl -X DELETE -H "API-KEY: your_api_key" https://kvrest.dev/api/yourBucketName/yourKey
GET /{bucketName}
name type data type description bucketNamerequired string Name of the bucket to list keys from
http code content-type response 200application/json{"keys": ["example-key1", "example-key2"]}404text/plain;charset=UTF-8Bucket not found500text/plain;charset=UTF-8Internal Server Error
curl -X GET -H "API-KEY: your_api_key" https://kvrest.dev/api/yourBucketName
Download db file from bot /download_db.
mkdir -p ./kvrest && cp /file/from-bot/file.db ./kvrest/ cd ./kvrest/ docker run --rm -it -p 8080:8080 -v ${PWD}:/app/data ghcr.io/split174/kvrest:v1.0.1
Test:
curl -X POST -H "API-KEY: DB-FILE-FROM-BOT" http://localhost:8080/api/buckets
├── api
│ ├── api.go
│ └── api_test.go
├── Caddyfile
├── docker-compose.yml
├── Dockerfile
├── go.mod
├── go.sum
├── main.go
├── README.md
└── telegram_bot
└── telegram_bot.go
- Go 1.16 or later
- A valid Telegram Bot Token
This project uses the following Go packages: