Skip to content

Commit

Permalink
feat: upgrade the minimum go version (#54)
Browse files Browse the repository at this point in the history
* feat: upgrade the mimimum go version

* ci: fuzz tests updated on

* chore: ignore testdata

* fix: upgrade to go 1.22

* fix: demo gmod

* fix: linter

* chore: remove unused command

* chore: fix linter

* fix: deps install

* fix: drop go 1.18 support

* fix: remove unused module

* fix: readme

* fix: remove example

* chore: remove example

* fix: remove cache

---------

Co-authored-by: GithubActions <laciferin@gmail.com>
  • Loading branch information
bxcodec and GithubActions authored Jun 9, 2024
1 parent f8b073d commit 8428f33
Show file tree
Hide file tree
Showing 22 changed files with 78 additions and 644 deletions.
31 changes: 13 additions & 18 deletions .github/workflows/go_cross.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,23 @@ on:
branches: ["main"]
workflow_dispatch:


concurrency:
group: ${{ github.workflow }}-${{ github.ref}}
cancel-in-progress: true


jobs:

build:
strategy:
matrix:
go-version: [ '1.18.x', '1.19.x', '1.20.x', '1.21.x']
arch: [ x64, arm, arm64 ]
os: [ macos-latest, ubuntu-latest ] #windows-latest
go-version: ["1.19.x", "1.20.x", "1.21.x", "1.22.x"]
arch: [x64, arm, arm64]
os: [macos-latest, ubuntu-latest] #windows-latest

include:
- os: ubuntu-latest
gocache: /tmp/go/gocache
# - os: windows-latest
# gocache: C:/gocache
# - os: windows-latest
# gocache: C:/gocache
- os: macos-latest
gocache: /tmp/go/gocache

Expand All @@ -40,7 +37,6 @@ jobs:
env:
GOCACHE: ${{matrix.gocache}}


steps:
- uses: actions/checkout@v3

Expand All @@ -50,15 +46,14 @@ jobs:
go-version: ${{ matrix.go-version }}
check-latest: true

- name: Cache Go tests
uses: actions/cache@v3
with:
path: |
${{env.GOCACHE}}
key: ${{ github.workflow }}-${{ runner.os }}-${{ matrix.arch }}-go-${{matrix.go-version}}-${{ hashFiles('**/go.mod','*_test.go') }}
restore-keys: |
${{ github.workflow }}-${{ runner.os }}-${{ matrix.arch }}-go-${{matrix.go-version}}-${{ hashFiles('**/go.mod','*_test.go') }}
# - name: Cache Go tests
# uses: actions/cache@v3
# with:
# path: |
# ${{env.GOCACHE}}
# key: ${{ github.workflow }}-${{ runner.os }}-${{ matrix.arch }}-go-${{matrix.go-version}}-${{ hashFiles('**/go.mod','*_test.go') }}
# restore-keys: |
# ${{ github.workflow }}-${{ runner.os }}-${{ matrix.arch }}-go-${{matrix.go-version}}-${{ hashFiles('**/go.mod','*_test.go') }}

- name: Linter
continue-on-error: true
Expand Down
48 changes: 17 additions & 31 deletions .github/workflows/go_fuzz.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ name: Go Fuzz
on:
push:
branches:
- '*'
- '**'
- "*"
- "**"
pull_request:
branches:
- 'main'
- "main"
workflow_dispatch:

schedule:
- cron: '0 * */1 * *'

- cron: "0 * */1 * *"

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand All @@ -38,15 +37,15 @@ jobs:
check-latest: true
cache-dependency-path: go.sum

- name: Cache Go
uses: actions/cache@v3
with:
path: |
${{ env.GOCACHE }}
${{ env.GOBIN }}
key: ${{ github.workflow }}-${{ runner.os }}-${{ hashFiles('*_test.go') }}
restore-keys: |
${{ github.workflow }}-${{ runner.os }}-${{ hashFiles('*_test.go') }}
# - name: Cache Go
# uses: actions/cache@v3
# with:
# path: |
# ${{ env.GOCACHE }}
# ${{ env.GOBIN }}
# key: ${{ github.workflow }}-${{ runner.os }}-${{ hashFiles('*_test.go') }}
# restore-keys: |
# ${{ github.workflow }}-${{ runner.os }}-${{ hashFiles('*_test.go') }}

- name: Build
timeout-minutes: 2
Expand All @@ -58,7 +57,6 @@ jobs:
run: |
go generate
# go generate fuzz.go

- name: Upload Artifacts
uses: actions/upload-artifact@v3
with:
Expand All @@ -68,12 +66,10 @@ jobs:
- name: Test Fuzz Functions
run: |
go test -cover -covermode=atomic -timeout=8m -race -run="Fuzz*" -json -short | \
tparse -follow -all -sort=elapsed

tparse -follow -all -sort=elapsed
fuzz:
needs: [ setup ]
needs: [setup]
runs-on: ubuntu-latest

env:
Expand Down Expand Up @@ -106,8 +102,6 @@ jobs:
name: go-test-utils
path: ${{ env.GOBIN }}



- run: chmod +x ${{ env.GOBIN }}/*

- name: FuzzMultiWrite
Expand Down Expand Up @@ -153,7 +147,7 @@ jobs:
git push
else
echo "All Fuzz Tests have passed"
fi
fi
- name: Upload TestCases
uses: actions/upload-artifact@v2
Expand All @@ -173,14 +167,6 @@ jobs:
echo "fuzz tests have passed on 2nd run"
fi
# fuzz:
# needs: [ build, fuzz-multiwrite ] #will fail if more than 1 fuzz function is present
# runs-on: ubuntu-latest
Expand Down Expand Up @@ -228,4 +214,4 @@ jobs:

# Fails if multiple Fuzz Functions match
# go test -fuzz=Fuzz -fuzztime=30s -cover -covermode=count -run="Fuzz*" -json -short | \
# tparse -follow -all -sort=elapsed
# tparse -follow -all -sort=elapsed
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ cover.txt


# Created by go-fuzz
testdata/
testdata/*
27 changes: 5 additions & 22 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
linters-settings:
depguard:
list-type: denylist
packages:
# logging is allowed only by logutils.Log, logrus
# is allowed to use only in logutils package
- github.com/sirupsen/logrus
packages-with-error-message:
- github.com/sirupsen/logrus: "logging is allowed only by logutils.Log"
dupl:
threshold: 100
funlen:
Expand All @@ -32,7 +24,7 @@ linters-settings:
min-complexity: 15
goimports:
local-prefixes: github.com/golangci/golangci-lint
gomnd:
mnd:
# don't include the "operation" and "assign"
checks:
- argument
Expand All @@ -47,21 +39,11 @@ linters-settings:
ignored-functions:
- strings.SplitN

govet:
check-shadowing: true
settings:
printf:
funcs:
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
lll:
line-length: 140
misspell:
locale: US
nolintlint:
allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space)
allow-unused: false # report any unused nolint directives
require-explanation: false # don't require an explanation for nolint directives
require-specific: false # don't require nolint directives to be specific about which linter is being skipped
Expand All @@ -88,7 +70,7 @@ linters:
- gocyclo
- gofmt
- goimports
- gomnd
- mnd
- goprintffuncname
- gosec
- gosimple
Expand Down Expand Up @@ -132,6 +114,8 @@ issues:
- path: _test\.go
linters:
- gomnd
- revive
- depguard
- path: db_test.go
text: "deferInLoop: Possible resource leak, 'defer' is called in the 'for' loop"

Expand Down Expand Up @@ -169,5 +153,4 @@ issues:

run:
timeout: 5m
go: "1.18"
skip-dirs: [examples]
go: "1.22"
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ export PATH := $(PWD)/bin:$(PATH)
# Default Shell
export SHELL := bash
# Type of OS: Linux or Darwin.
export OSTYPE := $(shell uname -s)
export OSTYPE := $(shell uname -s | tr A-Z a-z)
export ARCH := $(shell uname -m)

ifeq ($(OSTYPE),Darwin)
export MallocNanoZone=0
Expand Down
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@ Golang Database Resolver and Wrapper for any multiple database connections topol

This DBResolver library will split your connections to correct defined DBs. Eg, all read query will routed to ReadOnly replica db, and all write operation(Insert, Update, Delete) will routed to Primary/Master DB.

Read more for the explanation on this [blog post](https://betterprogramming.pub/create-a-cross-region-rdbms-connection-library-with-dbresolver-5072bed6a7b8)
**Read More**
|Items| Link|
------|-----|
|Blogpost| [blog post](https://betterprogramming.pub/create-a-cross-region-rdbms-connection-library-with-dbresolver-5072bed6a7b8) |
|Excalidraw| [diagram](https://excalidraw.com/#json=DTs8yxHOGF6uLkjnZny4z,RVo8iwhO0Rk6DRGkKuNZTg)|
|GoSG Meetup Demo| [repository](https://github.com/bxcodec/dbresolver-examples) |
| GoSG Presentation | [deck](https://www.canva.com/design/DAFgbpc7tfw/bEXVFtcHEnlFxKVBdnUggA/edit?utm_content=DAFgbpc7tfw&utm_campaign=designshare&utm_medium=link2&utm_source=sharebutton) |
| Instagram | [post](https://www.instagram.com/p/CnlDFPsBAJG/?utm_source=ig_web_copy_link&igsh=MzRlODBiNWFlZA==)|

Excalidraw live [diagram](https://excalidraw.com/#json=DTs8yxHOGF6uLkjnZny4z,RVo8iwhO0Rk6DRGkKuNZTg)
### Usecase 1: Separated RW and RO Database connection

<details open>
Expand Down Expand Up @@ -64,7 +70,7 @@ go get -u github.com/bxcodec/dbresolver/v2

# Example

### Implementing DB Resolver using *sql.DB
### Implementing DB Resolver using \*sql.DB

<details open>

Expand Down Expand Up @@ -152,6 +158,4 @@ func main() {

## Contribution

---

To contrib to this project, you can open a PR or an issue.
2 changes: 1 addition & 1 deletion db.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func (db *sqlDB) PrepareContext(ctx context.Context, query string) (_stmt Stmt,

err = multierr.Combine(errPrimaries, errReplicas)
if err != nil {
return
return //nolint: nakedret
}

_query := strings.ToUpper(query)
Expand Down
58 changes: 0 additions & 58 deletions examples/example_wrap_dbs_test.go

This file was deleted.

Loading

0 comments on commit 8428f33

Please sign in to comment.