From 1549833bfb448ee86c2258e6e333b1924c972878 Mon Sep 17 00:00:00 2001 From: Fijxu Date: Tue, 29 Oct 2024 19:34:26 -0300 Subject: [PATCH] Add version key to /stats and more arguments --- Dockerfile | 2 +- main.go | 23 ++++++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5021b4b..6f2a7af 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,7 @@ RUN apk add --no-cache build-base libwebp-dev COPY . . RUN --mount=type=cache,target=/root/.cache/go-build \ - go build -ldflags "-s -w" + go build -ldflags "-s -w -X 'main.version=$(date '+%Y-%m-%d')-$(git rev-list --abbrev-commit -1 HEAD)'" FROM alpine:edge diff --git a/main.go b/main.go index 8d8b5a3..f74c672 100644 --- a/main.go +++ b/main.go @@ -10,6 +10,7 @@ import ( "net/http" "os" "regexp" + "runtime" "sync/atomic" "syscall" "time" @@ -52,7 +53,7 @@ var h2client = &http.Client{ } // https://github.com/lucas-clemente/quic-go/issues/2836 -var client = h2client +var client *http.Client // Same user agent as Invidious var ua = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36" @@ -84,10 +85,13 @@ var manifest_re = regexp.MustCompile(`(?m)URI="([^"]+)"`) var ipv6_only = false +var version string + type statusJson struct { - RequestCount int64 `json:"requestCount"` - RequestPerSecond int64 `json:"requestPerSecond"` - RequestPerMinute int64 `json:"requestPerMinute"` + Version string `json:"version"` + RequestCount int64 `json:"requestCount"` + RequestPerSecond int64 `json:"requestPerSecond"` + RequestPerMinute int64 `json:"requestPerMinute"` RequestsForbidden struct { Videoplayback int64 `json:"videoplayback"` Vi int64 `json:"vi"` @@ -96,6 +100,7 @@ type statusJson struct { } var stats_ = statusJson{ + Version: version + "-" + runtime.GOARCH, RequestCount: 0, RequestPerSecond: 0, RequestPerMinute: 0, @@ -186,8 +191,10 @@ func main() { path_prefix = os.Getenv("PREFIX_PATH") ipv6_only = os.Getenv("IPV6_ONLY") == "1" - var https = flag.Bool("https", false, "Use built-in https server") + var https = flag.Bool("https", false, "Use built-in https server (recommended)") + var h3 = flag.Bool("h3", false, "Use HTTP/3 for requests (high CPU usage)") var ipv6 = flag.Bool("ipv6_only", false, "Only use ipv6 for requests") + flag.StringVar(&ua, "u", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36", "Set User-Agent (do not modify)") flag.StringVar(&tls_cert, "tls-cert", "", "TLS Certificate path") flag.StringVar(&tls_key, "tls-key", "", "TLS Certificate Key path") flag.StringVar(&sock, "s", "/tmp/http-ytproxy.sock", "Specify a socket name") @@ -195,6 +202,12 @@ func main() { flag.StringVar(&host, "l", "0.0.0.0", "Specify a listen address") flag.Parse() + if *h3 { + client = h3client + } else { + client = h2client + } + if *https { if len(tls_cert) <= 0 { fmt.Println("tls-cert argument is missing")