Skip to content

Commit

Permalink
chore: go18
Browse files Browse the repository at this point in the history
  • Loading branch information
ahuigo committed Dec 18, 2023
1 parent 1b88216 commit a91daa7
Show file tree
Hide file tree
Showing 16 changed files with 53 additions and 53 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Tests
on:
push:
tags:
branches:
branches: [ go18 ]
pull_request:

jobs:
Expand All @@ -21,8 +21,8 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.21
stable: false
go-version: 1.18
stable: true
- name: Test
run: make test

Expand Down
2 changes: 1 addition & 1 deletion cache-map-redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"crypto/sha512"
"encoding/hex"

"github.com/ahuigo/gofnext/serial"
"github.com/ahuigo/gofnext/go18/serial"
"github.com/go-redis/redis"
)

Expand Down
2 changes: 1 addition & 1 deletion decorator.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"sync"
"time"

"github.com/ahuigo/gofnext/serial"
"github.com/ahuigo/gofnext/go18/serial"
)

type Config struct {
Expand Down
2 changes: 1 addition & 1 deletion examples/decorator-err_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"sync/atomic"
"testing"

"github.com/ahuigo/gofnext"
"github.com/ahuigo/gofnext/go18"
)

type UserInfo struct {
Expand Down
2 changes: 1 addition & 1 deletion examples/decorator-fib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"testing"

"github.com/ahuigo/gofnext"
"github.com/ahuigo/gofnext/go18"
)

// https://stackoverflow.com/questions/73379188/how-to-use-cache-decorator-with-a-recursive-function-in-go
Expand Down
2 changes: 1 addition & 1 deletion examples/decorator-key-custom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"testing"
"time"

"github.com/ahuigo/gofnext"
gofnext "github.com/ahuigo/gofnext/go18"
)

func TestCacheFuncKeyCustom(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion examples/decorator-key-ptr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package examples
import (
"testing"

"github.com/ahuigo/gofnext"
"github.com/ahuigo/gofnext/go18"
)

func TestCacheFuncKeyPointerAddr(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion examples/decorator-key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"testing"
"time"

"github.com/ahuigo/gofnext"
"github.com/ahuigo/gofnext/go18"
)

func TestCacheFuncKeyStruct(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion examples/decorator-lru_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"testing"
"time"

"github.com/ahuigo/gofnext"
"github.com/ahuigo/gofnext/go18"
)

func TestCacheFuncWithOneParamLRU(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion examples/decorator-redis-err_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"
"time"

"github.com/ahuigo/gofnext"
"github.com/ahuigo/gofnext/go18"
)

func TestRedisCacheClientPanic(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion examples/decorator-redis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"
"time"

"github.com/ahuigo/gofnext"
"github.com/ahuigo/gofnext/go18"
"github.com/go-redis/redis"
)

Expand Down
2 changes: 1 addition & 1 deletion examples/decorator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"
"time"

"github.com/ahuigo/gofnext"
"github.com/ahuigo/gofnext/go18"
)

func getUser() UserInfo {
Expand Down
2 changes: 1 addition & 1 deletion examples/serial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strings"
"testing"

"github.com/ahuigo/gofnext/serial"
"github.com/ahuigo/gofnext/go18/serial"
)

type Person struct {
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/ahuigo/gofnext
module github.com/ahuigo/gofnext/go18

go 1.21.1
go 1.18

require github.com/go-redis/redis v6.15.9+incompatible

Expand Down
36 changes: 18 additions & 18 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# 🛠️ Go function extended
[![tag](https://img.shields.io/github/tag/ahuigo/gofnext.svg)](https://github.com/ahuigo/gofnext/tags)
[![tag](https://img.shields.io/github/tag/ahuigo/gofnext.svg)](https://github.com/ahuigo/gofnext/go18/tags)
![Go Version](https://img.shields.io/badge/Go-%3E%3D%201.21-%23007d9c)
[![GoDoc](https://godoc.org/github.com/ahuigo/gofnext?status.svg)](https://pkg.go.dev/github.com/ahuigo/gofnext)
![Build Status](https://github.com/ahuigo/gofnext/actions/workflows/test.yml/badge.svg)
[![Go report](https://goreportcard.com/badge/github.com/ahuigo/gofnext)](https://goreportcard.com/report/github.com/ahuigo/gofnext)
[![GoDoc](https://godoc.org/github.com/ahuigo/gofnext/go18?status.svg)](https://pkg.go.dev/github.com/ahuigo/gofnext/go18)
![Build Status](https://github.com/ahuigo/gofnext/go18/actions/workflows/test.yml/badge.svg)
[![Go report](https://goreportcard.com/badge/github.com/ahuigo/gofnext/go18)](https://goreportcard.com/report/github.com/ahuigo/gofnext/go18)
[![Coverage](https://img.shields.io/codecov/c/github/ahuigo/gofnext)](https://codecov.io/gh/ahuigo/gofnext)
[![Contributors](https://img.shields.io/github/contributors/ahuigo/gofnext)](https://github.com/ahuigo/gofnext/graphs/contributors)
[![Contributors](https://img.shields.io/github/contributors/ahuigo/gofnext)](https://github.com/ahuigo/gofnext/go18/graphs/contributors)
[![License](https://img.shields.io/github/license/ahuigo/gofnext)](./LICENSE)

This **gofnext** provides the following functions extended(go>=1.21).
Expand Down Expand Up @@ -60,15 +60,15 @@ In addition to memory caching, it also supports Redis caching and custom caching
- [x] Support customization of the CacheMap(manually)

## Decorator examples
Refer to: [examples](https://github.com/ahuigo/gofnext/blob/main/examples)
Refer to: [examples](https://github.com/ahuigo/gofnext/blob/go18/examples)

### Cache fibonacii function
Refer to: [decorator fib example](https://github.com/ahuigo/gofnext/blob/main/examples/decorator-fib_test.go)
Refer to: [decorator fib example](https://github.com/ahuigo/gofnext/blob/go18/examples/decorator-fib_test.go)

```go
package main
import "fmt"
import "github.com/ahuigo/gofnext"
import "github.com/ahuigo/gofnext/go18"
func main() {
var fib func(int) int
fib = func(x int) int {
Expand All @@ -87,11 +87,11 @@ func main() {
```

### Cache function with 0 param
Refer to: [decorator example](https://github.com/ahuigo/gofnext/blob/main/examples/decorator_test.go)
Refer to: [decorator example](https://github.com/ahuigo/gofnext/blob/go18/examples/decorator_test.go)

package examples

import "github.com/ahuigo/gofnext"
import "github.com/ahuigo/gofnext/go18"

func getUserAnonymouse() (UserInfo, error) {
fmt.Println("select * from db limit 1", time.Now())
Expand All @@ -114,7 +114,7 @@ Refer to: [decorator example](https://github.com/ahuigo/gofnext/blob/main/exampl
}

### Cache function with 1 param
Refer to: [decorator example](https://github.com/ahuigo/gofnext/blob/main/examples/decorator-nil_test.go)
Refer to: [decorator example](https://github.com/ahuigo/gofnext/blob/go18/examples/decorator-nil_test.go)

func getUserNoError(age int) (UserInfo) {
time.Sleep(10 * time.Millisecond)
Expand All @@ -136,7 +136,7 @@ Refer to: [decorator example](https://github.com/ahuigo/gofnext/blob/main/exampl
}

### Cache function with 2 params
> Refer to: [decorator example](https://github.com/ahuigo/gofnext/blob/main/examples/decorator_test.go)
> Refer to: [decorator example](https://github.com/ahuigo/gofnext/blob/go18/examples/decorator_test.go)
func TestCacheFuncWith2Param(t *testing.T) {
// Original function
Expand Down Expand Up @@ -170,7 +170,7 @@ Refer to: [decorator example](https://github.com/ahuigo/gofnext/blob/main/exampl
}

### Cache function with more params(>2)
Refer to: [decorator example](https://github.com/ahuigo/gofnext/blob/main/examples/decorator_test.go)
Refer to: [decorator example](https://github.com/ahuigo/gofnext/blob/go18/examples/decorator_test.go)

executeCount := 0
type Stu struct {
Expand Down Expand Up @@ -218,7 +218,7 @@ Refer to: [decorator example](https://github.com/ahuigo/gofnext/blob/main/exampl
}

### Cache function with lru cache
Refer to: [decorator lru example](https://github.com/ahuigo/gofnext/blob/main/examples/decorator-lru_test.go)
Refer to: [decorator lru example](https://github.com/ahuigo/gofnext/blob/go18/examples/decorator-lru_test.go)

executeCount := 0
maxCacheSize := 2
Expand All @@ -236,7 +236,7 @@ Refer to: [decorator lru example](https://github.com/ahuigo/gofnext/blob/main/ex
### Cache function with redis cache(unstable)
> Warning: Since redis needs JSON marshaling, this may result in data loss.
Refer to: [decorator redis example](https://github.com/ahuigo/gofnext/blob/main/examples/decorator-redis_test.go)
Refer to: [decorator redis example](https://github.com/ahuigo/gofnext/blob/go18/examples/decorator-redis_test.go)

var (
// Cacheable Function
Expand Down Expand Up @@ -279,7 +279,7 @@ Set redis config:
})

### Custom cache map
Refer to: https://github.com/ahuigo/gofnext/blob/main/cache-map-mem.go
Refer to: https://github.com/ahuigo/gofnext/blob/go18/cache-map-mem.go

## Decorator config
### Config item(`gofnext.Config`)
Expand All @@ -304,7 +304,7 @@ e.g.
> By default, gofnext will cache error when there is an error.
To use the cache even when there is an **error**, just add `NeedCacheIfErr: true`.
Refer to: https://github.com/ahuigo/gofnext/blob/main/examples/decorator-err_test.go
Refer to: https://github.com/ahuigo/gofnext/blob/go18/examples/decorator-err_test.go

gofnext.CacheFn1Err(getUserScore, &gofnext.Config{
NeedCacheIfErr: true,
Expand All @@ -322,7 +322,7 @@ If you wanna hash pointer address, you should turn on `HashKeyPointerAddr`:

### Custom hash key function
> In this case, you need to ensure that duplicate keys are not generated.
Refer to: [example](https://github.com/ahuigo/gofnext/blob/main/examples/decorator-key-custom_test.go)
Refer to: [example](https://github.com/ahuigo/gofnext/blob/go18/examples/decorator-key-custom_test.go)

// hash key function
hashKeyFunc := func(keys ...any) []byte{
Expand Down
36 changes: 18 additions & 18 deletions readme.zh.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# 🛠️ Go function extended
[![标签](https://img.shields.io/github/tag/ahuigo/gofnext.svg)](https://github.com/ahuigo/gofnext/tags)
[![标签](https://img.shields.io/github/tag/ahuigo/gofnext.svg)](https://github.com/ahuigo/gofnext/go18/tags)
![Go 版本](https://img.shields.io/badge/Go-%3E%3D%201.21-%23007d9c)
[![GoDoc](https://godoc.org/github.com/ahuigo/gofnext?status.svg)](https://pkg.go.dev/github.com/ahuigo/gofnext)
![构建状态](https://github.com/ahuigo/gofnext/actions/workflows/test.yml/badge.svg)
[![Go 报告](https://goreportcard.com/badge/github.com/ahuigo/gofnext)](https://goreportcard.com/report/github.com/ahuigo/gofnext)
[![GoDoc](https://godoc.org/github.com/ahuigo/gofnext/go18?status.svg)](https://pkg.go.dev/github.com/ahuigo/gofnext/go18)
![构建状态](https://github.com/ahuigo/gofnext/go18/actions/workflows/test.yml/badge.svg)
[![Go 报告](https://goreportcard.com/badge/github.com/ahuigo/gofnext/go18)](https://goreportcard.com/report/github.com/ahuigo/gofnext/go18)
[![覆盖率](https://img.shields.io/codecov/c/github/ahuigo/gofnext)](https://codecov.io/gh/ahuigo/gofnext)
[![贡献者](https://img.shields.io/github/contributors/ahuigo/gofnext)](https://github.com/ahuigo/gofnext/graphs/contributors)
[![贡献者](https://img.shields.io/github/contributors/ahuigo/gofnext)](https://github.com/ahuigo/gofnext/go18/graphs/contributors)
[![许可证](https://img.shields.io/github/license/ahuigo/gofnext)](./LICENSE)

这个 **gofnext** 提供以下函数扩展(go>=1.21)。
Expand Down Expand Up @@ -58,15 +58,15 @@
- [x] 手动支持自定义 CacheMap

## 装饰器示例
参考:[示例](https://github.com/ahuigo/gofnext/blob/main/examples)
参考:[示例](https://github.com/ahuigo/gofnext/blob/go18/examples)

### 缓存斐波那契函数
参考:[装饰器斐波那契示例](https://github.com/ahuigo/gofnext/blob/main/examples/decorator-fib_test.go)
参考:[装饰器斐波那契示例](https://github.com/ahuigo/gofnext/blob/go18/examples/decorator-fib_test.go)

```go
package main
import "fmt"
import "github.com/ahuigo/gofnext"
import "github.com/ahuigo/gofnext/go18"
func main() {
var fib func(int) int
fib = func(x int) int {
Expand All @@ -85,11 +85,11 @@ func main() {
```

### 带有0个参数的缓存函数
参考: [decorator example](https://github.com/ahuigo/gofnext/blob/main/examples/decorator_test.go)
参考: [decorator example](https://github.com/ahuigo/gofnext/blob/go18/examples/decorator_test.go)

package examples

import "github.com/ahuigo/gofnext"
import "github.com/ahuigo/gofnext/go18"

func getUserAnonymouse() (UserInfo, error) {
fmt.Println("select * from db limit 1", time.Now())
Expand All @@ -112,7 +112,7 @@ func main() {
}

### 带有1个参数的缓存函数
参考: [decorator example](https://github.com/ahuigo/gofnext/blob/main/examples/decorator-nil_test.go)
参考: [decorator example](https://github.com/ahuigo/gofnext/blob/go18/examples/decorator-nil_test.go)

func getUserNoError(age int) (UserInfo) {
time.Sleep(10 * time.Millisecond)
Expand All @@ -134,7 +134,7 @@ func main() {
}

### 带有2个参数的缓存函数
> 参考: [decorator example](https://github.com/ahuigo/gofnext/blob/main/examples/decorator_test.go)
> 参考: [decorator example](https://github.com/ahuigo/gofnext/blob/go18/examples/decorator_test.go)
func TestCacheFuncWith2Param(t *testing.T) {
// Original function
Expand Down Expand Up @@ -168,7 +168,7 @@ func main() {
}

### 带有2个以上参数的缓存函数
参考: [decorator example](https://github.com/ahuigo/gofnext/blob/main/examples/decorator_test.go)
参考: [decorator example](https://github.com/ahuigo/gofnext/blob/go18/examples/decorator_test.go)

executeCount := 0
type Stu struct {
Expand Down Expand Up @@ -216,7 +216,7 @@ func main() {
}

### 带LRU 缓存的函数
参考: [decorator lru example](https://github.com/ahuigo/gofnext/blob/main/examples/decorator-lru_test.go)
参考: [decorator lru example](https://github.com/ahuigo/gofnext/blob/go18/examples/decorator-lru_test.go)

executeCount := 0
maxCacheSize := 2
Expand All @@ -235,7 +235,7 @@ func main() {
> 警告: 目前使用json序列化,可能会有私有属性丢失
> 后续序列化方法可能会有变化, 请不要用于生产
参考: [decorator redis example](https://github.com/ahuigo/gofnext/blob/main/examples/decorator-redis_test.go)
参考: [decorator redis example](https://github.com/ahuigo/gofnext/blob/go18/examples/decorator-redis_test.go)

var (
// Cacheable Function
Expand Down Expand Up @@ -278,7 +278,7 @@ Set redis config:
})

### 定制缓存函数
参考: https://github.com/ahuigo/gofnext/blob/main/cache-map-mem.go
参考: https://github.com/ahuigo/gofnext/blob/go18/cache-map-mem.go

## 装饰器配置
### 配置项清单(`gofnext.Config`)
Expand All @@ -302,7 +302,7 @@ e.g.
### 如果有error就不缓存
> 默认有error 不会缓存.
如果存在error时, 也使用缓存话。 参考: https://github.com/ahuigo/gofnext/blob/main/examples/decorator-err_test.go
如果存在error时, 也使用缓存话。 参考: https://github.com/ahuigo/gofnext/blob/go18/examples/decorator-err_test.go

gofnext.CacheFn1Err(getUserScore, &gofnext.Config{
NeedCacheIfErr: true,
Expand All @@ -320,7 +320,7 @@ e.g.
### 自定义哈希键函数
> 这种情况下,您需要保证不会有生成重复的key。
参考: [example](https://github.com/ahuigo/gofnext/blob/main/examples/decorator-key-custom_test.go)
参考: [example](https://github.com/ahuigo/gofnext/blob/go18/examples/decorator-key-custom_test.go)

// hash key function
hashKeyFunc := func(keys ...any) []byte{
Expand Down

0 comments on commit a91daa7

Please sign in to comment.