Simple Gin package main import ( "fmt" "log/slog" "net/http" "time" "github.com/gin-gonic/gin" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" ) type msg struct { Count int64 `json:"count"` } var pingCounter = prometheus.NewCounter( prometheus.CounterOpts{ Name: "ping_request_count", Help: "No of request handled by Ping handler", }, ) var httpReqs = prometheus.NewCounterVec( prometheus.CounterOpts{ Name: "http_requests_total", Help: "How many HTTP requests processed, partitioned by status code and HTTP method.", }, []string{"code", "method"}, ) func PromHandler(handler http.Handler) gin.HandlerFunc { return func(c
Exporter 开发 Prometheus Exporter是一个用来收集和暴露指标数据的工具,通过与Prometheus监控系统一起使用。它的结构包括两个组件:Collect
Go Wire wire是 Google 开源的一个依赖注入工具。它是一个代码生成器,并不是一个框架。我们只需要在一个特殊的go文件中告诉wire类型之间的依赖关系,
Jellyfin 家庭影院 docker 安装 docker pull jellyfin/jellyfin docker run -d --name=Jellyfin -p 8096:8096 \ # --name=Jellyfin 将容器名定义为 Jellyfin -p 8920:8920 -p 7359:7359/udp -p 1900:1900/udp #这三个端口为可选项 \ -v `pwd`/config:/config -v `pwd`/cache:/cache -v /media:/media \ -e TZ=Asia/Shanghai -e PUID=0 -e PGID=0 --device=/dev/dri:/dev/dri --add-host=api.themoviedb.org:13.224.161.90 \ #为容器增加 host 指向
Go 代码片段 go goroutines pool package main import ( "fmt" "github.com/sourcegraph/conc/pool" ) func main() { p := pool.New().WithMaxGoroutines(3) for i := 1; i <= 5; i++ { p.Go(func() { fmt.Println(i) }) } p.Wait() } 带ctx 的go goroutines pool package main import ( "context" "errors" "fmt" "github.com/sourcegraph/conc/pool" ) func main() { p := pool.New(). WithMaxGoroutines(4). WithContext(context.Background()). WithCancelOnError() for i := 0; i <
Go lo 使用 go get github.com/samber/lo 使用 // 将切片中的重复元素去掉,只保留第一个出现的元素。 names := lo.Uniq([]string{"Samuel", "John", "Samuel"}) // []string{"Samuel", "John"} // 生成map // 将切片或数组转换为map,key是call