-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6724c04
Showing
39 changed files
with
2,925 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
FROM golang:alpine AS build | ||
|
||
ARG VERSION=unspecified | ||
ARG GIT_COMMIT=unspecified | ||
LABEL git_commit=$GIT_COMMIT | ||
|
||
ENV GO111MODULE=on \ | ||
CGO_ENABLED=0 \ | ||
GOOS=linux \ | ||
GOARCH=amd64 | ||
|
||
RUN mkdir -p /go/src/github.com/HotPotatoC/kvstore | ||
|
||
ADD go.mod /go/src/github.com/HotPotatoC/kvstore | ||
ADD go.sum /go/src/github.com/HotPotatoC/kvstore | ||
|
||
WORKDIR /go/src/github.com/HotPotatoC/kvstore | ||
|
||
RUN go mod download | ||
|
||
COPY . . | ||
|
||
RUN mkdir .bin | ||
|
||
RUN go build -ldflags="-s -w -X 'build.Version=${VERSION}' -X 'build.Build=${GIT_COMMIT}'" -v -o \ | ||
/go/bin/kvstore-server cmd/kvstore-server/main.go | ||
|
||
FROM scratch | ||
|
||
WORKDIR /usr/bin/ | ||
|
||
COPY --from=build /go/bin/kvstore-server . | ||
|
||
ENV PATH=/usr/bin/:$PATH | ||
|
||
EXPOSE 7275 | ||
|
||
ENTRYPOINT [ "kvstore-server" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: Lint | ||
|
||
on: | ||
push: | ||
branches: [master] | ||
pull_request: | ||
branches: [master] | ||
|
||
jobs: | ||
lint: | ||
name: Lint | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: checkout | ||
uses: actions/checkout@v1 | ||
|
||
- name: Run revive linter | ||
uses: docker://morphy/revive-action:v2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
name: Publish kvstore server image | ||
on: | ||
push: | ||
branches: | ||
- "master" | ||
tags: | ||
- "v*" | ||
|
||
jobs: | ||
push_to_registry: | ||
name: Push kvstore server Docker image to Docker Hub | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out the repo | ||
uses: actions/checkout@v2 | ||
- name: Set up Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: ^1.17 | ||
- name: Get dependencies | ||
run: | | ||
go get -v -t -d ./... | ||
if [ -f Gopkg.toml ]; then | ||
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh | ||
dep ensure | ||
fi | ||
- name: Run tests first | ||
run: go test -v ./... | ||
- name: Get tag | ||
if: contains(github.ref, 'refs/tags/') | ||
id: tag | ||
uses: dawidd6/action-get-tag@v1 | ||
- name: Docker meta | ||
id: docker_meta | ||
uses: crazy-max/ghaction-docker-meta@v2 | ||
with: | ||
images: hotpotatoc123/kvstore-server | ||
flavor: | | ||
latest=auto | ||
tags: | | ||
type=ref,event=branch | ||
type=ref,event=pr | ||
type=semver,pattern={{version}} | ||
type=semver,pattern={{major}}.{{minor}} | ||
- name: Login to DockerHub | ||
if: github.event_name != 'pull_request' | ||
uses: docker/login-action@v1 | ||
with: | ||
username: ${{ secrets.DOCKER_USERNAME }} | ||
password: ${{ secrets.DOCKER_PASSWORD }} | ||
- name: Push to Docker Hub | ||
uses: docker/[email protected] | ||
with: | ||
context: . | ||
push: true | ||
repository: hotpotatoc123/kvstore-server | ||
tags: ${{ steps.docker_meta.outputs.tags }} | ||
labels: ${{ steps.docker_meta.outputs.labels }} | ||
file: "./build/kvstore-server/Dockerfile" | ||
build-args: | | ||
GIT_COMMIT=${{ env.GITHUB_SHA }} | ||
VERSION=${{ steps.tag.outputs.tag }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: goreleaser | ||
|
||
on: | ||
push: | ||
tags: | ||
- "*" | ||
|
||
jobs: | ||
goreleaser: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
- name: Set up Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.17 | ||
- name: Run GoReleaser | ||
uses: goreleaser/goreleaser-action@v2 | ||
with: | ||
version: latest | ||
args: release --rm-dist | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: Ci | ||
|
||
on: | ||
push: | ||
branches: [master] | ||
pull_request: | ||
branches: [master] | ||
|
||
jobs: | ||
test: | ||
name: Test | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: ^1.17 | ||
|
||
- name: Get dependencies | ||
run: | | ||
go get -v -t -d ./... | ||
if [ -f Gopkg.toml ]; then | ||
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh | ||
dep ensure | ||
fi | ||
- name: Run tests | ||
run: go test -v ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
*.test | ||
*.out | ||
*.kvsdb | ||
|
||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
env: | ||
- GO111MODULE=on | ||
before: | ||
hooks: | ||
- go mod download | ||
builds: | ||
- main: ./cmd/kvstore-server/main.go | ||
id: "kvstore-server" | ||
binary: kvstore-server | ||
ldflags: | ||
- -X build.Version={{.Version}} -X build.Build={{.Commit}} | ||
env: | ||
- CGO_ENABLED=0 | ||
goos: | ||
- darwin | ||
- linux | ||
- windows | ||
- freebsd | ||
- dragonfly | ||
goarch: | ||
- 386 | ||
- arm | ||
- arm64 | ||
- amd64 | ||
ignore: | ||
- goos: darwin | ||
goarch: 386 | ||
- goos: freebsd | ||
goarch: 386 | ||
- goos: freebsd | ||
goarch: arm | ||
archives: | ||
- format: tar.gz | ||
format_overrides: | ||
- goos: windows | ||
format: zip | ||
name_template: "{{ .Binary }}_{{ .Version }}_{{ .Os }}-{{ .Arch }}" | ||
replacements: | ||
amd64: 64bit | ||
386: 32bit | ||
arm: ARM | ||
arm64: ARM64 | ||
darwin: macOS | ||
linux: Linux | ||
windows: Windows | ||
openbsd: OpenBSD | ||
netbsd: NetBSD | ||
freebsd: FreeBSD | ||
dragonfly: DragonFlyBSD | ||
snapshot: | ||
name_template: "{{ .Tag }}-next" | ||
changelog: | ||
sort: asc | ||
filters: | ||
exclude: | ||
- "^docs:" | ||
- "^test:" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 HotPotatoC | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
.DEFAULT_GOAL := help | ||
|
||
VERSION?=$(shell cat VERSION) | ||
BUILD=$(shell git rev-parse HEAD) | ||
|
||
VERSION_PACKAGE=github.com/HotPotatoC/kvstore/build | ||
LDFLAGS=-X ${VERSION_PACKAGE}.Version=${VERSION} -X ${VERSION_PACKAGE}.Build=${BUILD} | ||
|
||
GOPATH = $(shell go env GOPATH) | ||
|
||
.PHONY: lint | ||
lint: ## Lint the source code | ||
revive ./... | ||
|
||
.PHONY: fmt | ||
fmt: ## Format the source code | ||
go fmt ./... | ||
|
||
.PHONY: vet | ||
vet: ## Lint the source code | ||
go vet ./... | ||
|
||
.PHONY: test | ||
test: ## Run the tests | ||
go test -v ./... | ||
|
||
.PHONY: bench | ||
bench: ## Run the benchmarks | ||
go test -bench=. -benchmem ./... | ||
|
||
.PHONY: install | ||
install: ## Install the binary | ||
go install -ldflags "${LDFLAGS}" ./... | ||
|
||
.PHONY: help | ||
# Source: https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html | ||
help: ## Displays all the available commands | ||
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# **kvstore** | ||
|
||
An experimental key-value database server that is compatible with the redis **RESP** protocol. | ||
|
||
## Getting started | ||
|
||
Simply run the following command to start the server: | ||
|
||
```bash | ||
go run cmd/kvstore-server/main.go | ||
``` | ||
|
||
To connect to the server, currently the `kvstore-cli` is yet to be implemented. So for now, you can use the `redis-cli` command to connect to the server. | ||
|
||
```bash | ||
redis-cli -p 7275 # Default kvstore server port is 7275 | ||
``` | ||
|
||
Current available commands are: | ||
|
||
- `SET key value` | ||
- `GET key` | ||
- `DEL key` | ||
- `KEYS pattern` | ||
- `VALUES` | ||
|
||
## NOTE | ||
|
||
This project is not targeted for production use. This is only a proof of concept | ||
|
||
## Contributing | ||
|
||
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. | ||
|
||
## License | ||
|
||
[MIT](https://choosealicense.com/licenses/mit/) | ||
|
||
## Support | ||
|
||
<a href="https://www.buymeacoffee.com/hotpotato" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png" alt="Buy Me A Coffee" style="height: 41px !important;width: 174px !important;box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;-webkit-box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;" ></a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v2.0.0-alpha |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package build | ||
|
||
// Version is the current version of the build. | ||
var Version = "v2.0.0-alpha" | ||
|
||
// Build is the git commit of the build. | ||
var Build = "dev" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package client | ||
|
||
import ( | ||
"github.com/HotPotatoC/kvstore-rewrite/datastructure" | ||
"github.com/HotPotatoC/kvstore-rewrite/disk" | ||
"github.com/panjf2000/gnet" | ||
) | ||
|
||
// Client is a client that connects to a server. | ||
type Client struct { | ||
// Conn is the underlying connection. | ||
Conn gnet.Conn | ||
// DB is the database client. | ||
DB *datastructure.Map | ||
// kvsDB is the file used to persist the data structure. | ||
KVSDB *disk.KVSDB | ||
// Argc is the number of arguments excluding the command. | ||
Argc int | ||
// Argv is the arguments excluding the command. | ||
Argv [][]byte | ||
} |
Oops, something went wrong.