init
This commit is contained in:
32
examples/other/cache/cache_proxy.go
vendored
Normal file
32
examples/other/cache/cache_proxy.go
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/darkit/goproxy"
|
||||
"github.com/darkit/goproxy/pkg/cache"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// 创建内存缓存
|
||||
memCache := cache.NewMemoryCache(time.Minute*5, time.Minute*5, 1000)
|
||||
|
||||
// 创建代理实例
|
||||
proxy := goproxy.NewProxy(
|
||||
goproxy.WithHTTPCache(memCache),
|
||||
goproxy.WithRequestTimeout(30*time.Second),
|
||||
goproxy.WithIdleTimeout(60*time.Second),
|
||||
)
|
||||
|
||||
// 启动代理服务器
|
||||
log.Println("缓存代理服务器启动在 :8080")
|
||||
log.Println("缓存配置:")
|
||||
log.Printf("- 缓存类型: 内存缓存\n")
|
||||
log.Printf("- 请求超时: 30s\n")
|
||||
log.Printf("- 空闲超时: 60s\n")
|
||||
if err := http.ListenAndServe(":8080", proxy); err != nil {
|
||||
log.Fatalf("代理服务器启动失败: %v", err)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user