Skip to content

Commit

Permalink
Support generics (#3)
Browse files Browse the repository at this point in the history
* quick POC for generic implementation

* disable non-1.18 compat linters

* fix Example

* embed options into Cache interface

Co-authored-by: Dmitry Verkhoturov <[email protected]>
  • Loading branch information
umputun and paskal authored Sep 3, 2022
1 parent e9d36b6 commit a198afa
Show file tree
Hide file tree
Showing 10 changed files with 664 additions and 14 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/ci-v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: build-v2

on:
push:
branches:
tags:
paths:
- ".github/workflows/ci-v2.yml"
- "v2/**"
pull_request:
paths:
- ".github/workflows/ci-v2.yml"
- "v2/**"

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: set up go 1.18
uses: actions/setup-go@v2
with:
go-version: 1.18
id: go

- name: checkout
uses: actions/checkout@v2

- name: build and test
run: |
go test -timeout=60s -race -covermode=atomic -coverprofile=$GITHUB_WORKSPACE/profile.cov
go build -race
working-directory: v2

- name: install golangci-lint and goveralls
run: |
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $GITHUB_WORKSPACE v1.46.2
GO111MODULE=off go get -u -v github.com/mattn/goveralls
- name: run linters
run: $GITHUB_WORKSPACE/golangci-lint run --out-format=github-actions
working-directory: v2

- name: submit coverage
run: $(go env GOPATH)/bin/goveralls -service="github" -coverprofile=$GITHUB_WORKSPACE/profile.cov
env:
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
working-directory: v2
14 changes: 10 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,23 @@ on:
push:
branches:
tags:
paths-ignore:
- ".github/workflows/ci-v2.yml"
- "v2/**"
pull_request:
paths-ignore:
- ".github/workflows/ci-v2.yml"
- "v2/**"

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: set up go 1.14
uses: actions/setup-go@v1
- name: set up go 1.18
uses: actions/setup-go@v2
with:
go-version: 1.14
go-version: 1.18
id: go

- name: checkout
Expand All @@ -27,7 +33,7 @@ jobs:
- name: install golangci-lint and goveralls
run: |
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $GITHUB_WORKSPACE v1.25.0
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $GITHUB_WORKSPACE v1.46.2
GO111MODULE=off go get -u -v github.com/mattn/goveralls
- name: run linters
Expand Down
10 changes: 2 additions & 8 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
linters-settings:
govet:
check-shadowing: true
golint:
min-confidence: 0
gocyclo:
min-complexity: 15
maligned:
Expand All @@ -25,7 +23,7 @@ linters-settings:
linters:
enable:
- megacheck
- golint
- revive
- govet
- unconvert
- megacheck
Expand All @@ -42,7 +40,7 @@ linters:
- varcheck
- stylecheck
- gochecknoinits
- scopelint
- exportloopref
- gocritic
- nakedret
- gosimple
Expand All @@ -57,8 +55,4 @@ run:
- vendor

issues:
exclude-rules:
- text: "should have a package comment, unless it's in another file for this package"
linters:
- golint
exclude-use-default: false
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ import (
"fmt"
"time"

"github.com/go-pkgz/expirable-cache"
"github.com/go-pkgz/expirable-cache/v2"
)

func main() {
// make cache with short TTL and 3 max keys
c, _ := cache.NewCache(cache.MaxKeys(3), cache.TTL(time.Millisecond*10))
c := cache.NewCache[string, string]().WithMaxKeys(3).WithTTL(time.Millisecond * 10)

// set value under key1.
// with 0 ttl (last parameter) will use cache-wide setting instead (10ms).
Expand Down
64 changes: 64 additions & 0 deletions v2/.golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
linters-settings:
govet:
check-shadowing: true
golint:
min-confidence: 0
gocyclo:
min-complexity: 15
maligned:
suggest-new: true
goconst:
min-len: 2
min-occurrences: 2
misspell:
locale: US
lll:
line-length: 140
gocritic:
enabled-tags:
- performance
- style
- experimental
disabled-checks:
- wrapperFunc

linters:
enable:
- megacheck
- revive
- govet
- unconvert
- megacheck
#- structcheck
- gas
- gocyclo
- dupl
- misspell
#- unparam
- varcheck
- deadcode
- typecheck
- ineffassign
- varcheck
- stylecheck
- gochecknoinits
- exportloopref
#- gocritic
- nakedret
- gosimple
- prealloc
fast: false
disable-all: true

run:
output:
format: tab
skip-dirs:
- vendor

issues:
exclude-rules:
- text: "should have a package comment, unless it's in another file for this package"
linters:
- golint
exclude-use-default: false
Loading

0 comments on commit a198afa

Please sign in to comment.