From e0d49b4f85013792a82ce036ca72b35e1774eae3 Mon Sep 17 00:00:00 2001 From: Karan Sharma Date: Sun, 18 Dec 2022 20:50:03 +0530 Subject: [PATCH] chore: restructure pkg --- .github/workflows/release.yml | 24 ++++++++++++++++ .gitignore | 1 + .goreleaser.yml | 28 +++++++++++++++++++ Makefile | 2 +- README.md | 8 +++--- pkg/barrel/barrel.go => barrel.go | 0 pkg/barrel/barrel_test.go => barrel_test.go | 0 .../benchmark_test.go => benchmark_test.go | 2 +- cmd/server/main.go | 2 +- pkg/barrel/compact.go => compact.go | 0 pkg/barrel/config.go => config.go | 0 pkg/barrel/errors.go => errors.go | 0 examples/main.go | 2 +- pkg/barrel/flock.go => flock.go | 0 pkg/barrel/header.go => header.go | 0 pkg/barrel/keydir.go => keydir.go | 0 pkg/barrel/ops.go => ops.go | 0 pkg/barrel/utils.go => utils.go | 0 18 files changed, 61 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 .goreleaser.yml rename pkg/barrel/barrel.go => barrel.go (100%) rename pkg/barrel/barrel_test.go => barrel_test.go (100%) rename pkg/barrel/benchmark_test.go => benchmark_test.go (97%) rename pkg/barrel/compact.go => compact.go (100%) rename pkg/barrel/config.go => config.go (100%) rename pkg/barrel/errors.go => errors.go (100%) rename pkg/barrel/flock.go => flock.go (100%) rename pkg/barrel/header.go => header.go (100%) rename pkg/barrel/keydir.go => keydir.go (100%) rename pkg/barrel/ops.go => ops.go (100%) rename pkg/barrel/utils.go => utils.go (100%) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..a18ccd5 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,24 @@ +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.19 + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v2 + with: + version: latest + args: release --rm-dist diff --git a/.gitignore b/.gitignore index ea5c017..3009ba5 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ config.toml bin/ data/ coverage.txt +dist/ \ No newline at end of file diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..ea8133b --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,28 @@ +env: + - GO111MODULE=on + - CGO_ENABLED=0 + +before: + hooks: + - go mod tidy + +builds: + - binary: barreldb + id: barreldb + goos: + - linux + goarch: + - amd64 + ldflags: + - -s -w -X "main.buildVersion={{ .Tag }} ({{ .ShortCommit }} {{ .Date }})" + dir: ./cmd/server/ + + - skip: true + id: barrel_lib + +archives: + - format: tar.gz + files: + - README.md + - LICENSE + - cmd/server/config.sample.toml diff --git a/Makefile b/Makefile index a5f05ec..c3ea801 100644 --- a/Makefile +++ b/Makefile @@ -27,4 +27,4 @@ test: .PHONY: bench bench: - go test -bench=. -benchmem ./pkg/barrel/... + go test -bench=. -benchmem ./... diff --git a/README.md b/README.md index b8cc262..58e14e4 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ You can refer to [Writing a disk-based key-value store in Golang](https://mrkara ```go import ( - "github.com/mr-karan/barreldb/pkg/barrel" + "github.com/mr-karan/barreldb" ) barrel, _ := barrel.Init(barrel.WithDir("data/")) @@ -82,17 +82,17 @@ ERR: invalid key: key is already expired Using `make bench`: ``` -go test -bench=. -benchmem ./pkg/barrel/... +go test -bench=. -benchmem ./... HELLO goos: linux goarch: amd64 -pkg: github.com/mr-karan/barreldb/pkg/barrel +pkg: github.com/mr-karan/barreldb cpu: 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz BenchmarkPut/DisableSync-8 385432 3712 ns/op 1103.48 MB/s 88 B/op 4 allocs/op BenchmarkPut/AlwaysSync-8 222 5510563 ns/op 0.74 MB/s 115 B/op 4 allocs/op BenchmarkGet-8 840627 1304 ns/op 3142.20 MB/s 4976 B/op 5 allocs/op PASS -ok github.com/mr-karan/barreldb/pkg/barrel 10.751s +ok github.com/mr-karan/barreldb 10.751s ``` Using `redis-benchmark`: diff --git a/pkg/barrel/barrel.go b/barrel.go similarity index 100% rename from pkg/barrel/barrel.go rename to barrel.go diff --git a/pkg/barrel/barrel_test.go b/barrel_test.go similarity index 100% rename from pkg/barrel/barrel_test.go rename to barrel_test.go diff --git a/pkg/barrel/benchmark_test.go b/benchmark_test.go similarity index 97% rename from pkg/barrel/benchmark_test.go rename to benchmark_test.go index 2030018..fc0cff1 100644 --- a/pkg/barrel/benchmark_test.go +++ b/benchmark_test.go @@ -5,7 +5,7 @@ import ( "strings" "testing" - "github.com/mr-karan/barreldb/pkg/barrel" + barrel "github.com/mr-karan/barreldb" ) func BenchmarkPut(b *testing.B) { diff --git a/cmd/server/main.go b/cmd/server/main.go index 6ccc795..cf4e2af 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -7,7 +7,7 @@ import ( "os/signal" "syscall" - "github.com/mr-karan/barreldb/pkg/barrel" + barrel "github.com/mr-karan/barreldb" "github.com/tidwall/redcon" "github.com/zerodha/logf" ) diff --git a/pkg/barrel/compact.go b/compact.go similarity index 100% rename from pkg/barrel/compact.go rename to compact.go diff --git a/pkg/barrel/config.go b/config.go similarity index 100% rename from pkg/barrel/config.go rename to config.go diff --git a/pkg/barrel/errors.go b/errors.go similarity index 100% rename from pkg/barrel/errors.go rename to errors.go diff --git a/examples/main.go b/examples/main.go index 347d510..3806f2e 100644 --- a/examples/main.go +++ b/examples/main.go @@ -5,7 +5,7 @@ import ( "os" "time" - "github.com/mr-karan/barreldb/pkg/barrel" + barrel "github.com/mr-karan/barreldb" ) var ( diff --git a/pkg/barrel/flock.go b/flock.go similarity index 100% rename from pkg/barrel/flock.go rename to flock.go diff --git a/pkg/barrel/header.go b/header.go similarity index 100% rename from pkg/barrel/header.go rename to header.go diff --git a/pkg/barrel/keydir.go b/keydir.go similarity index 100% rename from pkg/barrel/keydir.go rename to keydir.go diff --git a/pkg/barrel/ops.go b/ops.go similarity index 100% rename from pkg/barrel/ops.go rename to ops.go diff --git a/pkg/barrel/utils.go b/utils.go similarity index 100% rename from pkg/barrel/utils.go rename to utils.go