Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dreamsxin/go-gin
gin 相关组件
https://github.com/dreamsxin/go-gin
Last synced: 26 days ago
JSON representation
gin 相关组件
- Host: GitHub
- URL: https://github.com/dreamsxin/go-gin
- Owner: dreamsxin
- Created: 2024-01-27T03:54:29.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2024-01-27T10:58:36.000Z (12 months ago)
- Last Synced: 2024-10-30T03:48:59.281Z (2 months ago)
- Language: Go
- Size: 27.3 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# go-gin
存放 gin 相关的增强工具
## 安装
```shell
go get -u github.com/dreamsxin/go-gin
```## 缓存
### 使用本地缓存
```go
package mainimport (
"time""github.com/dreamsxin/go-gin/cache"
"github.com/dreamsxin/go-gin/cache/persist"
"github.com/gin-gonic/gin"
)func main() {
app := gin.New()memoryStore := persist.NewMemoryStore(1 * time.Minute)
app.GET("/hello",
cache.CacheByRequestURI(memoryStore, 2*time.Second),
func(c *gin.Context) {
c.String(200, "hello world")
},
)if err := app.Run(":8080"); err != nil {
panic(err)
}
}
```### 使用redis作为缓存
```go
package mainimport (
"time""github.com/dreamsxin/go-gin/cache"
"github.com/dreamsxin/go-gin/cache/persist"
"github.com/gin-gonic/gin"
"github.com/go-redis/redis/v8"
)func main() {
app := gin.New()redisStore := persist.NewRedisStore(redis.NewClient(&redis.Options{
Network: "tcp",
Addr: "127.0.0.1:6379",
}))app.GET("/hello",
cache.CacheByRequestURI(redisStore, 2*time.Second),
func(c *gin.Context) {
c.String(200, "hello world")
},
)
if err := app.Run(":8080"); err != nil {
panic(err)
}
}
```# 压测
```
wrk -c 500 -d 1m -t 5 http://127.0.0.1:8080/hello
```