Add version key to /stats and more arguments
Some checks failed
CI / build (push) Has been cancelled

This commit is contained in:
Fijxu 2024-10-29 19:34:26 -03:00
parent 6885fcfc28
commit 1549833bfb
Signed by: Fijxu
GPG key ID: 32C1DDF333EDA6A4
2 changed files with 19 additions and 6 deletions

View file

@ -7,7 +7,7 @@ RUN apk add --no-cache build-base libwebp-dev
COPY . . COPY . .
RUN --mount=type=cache,target=/root/.cache/go-build \ 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 FROM alpine:edge

23
main.go
View file

@ -10,6 +10,7 @@ import (
"net/http" "net/http"
"os" "os"
"regexp" "regexp"
"runtime"
"sync/atomic" "sync/atomic"
"syscall" "syscall"
"time" "time"
@ -52,7 +53,7 @@ var h2client = &http.Client{
} }
// https://github.com/lucas-clemente/quic-go/issues/2836 // https://github.com/lucas-clemente/quic-go/issues/2836
var client = h2client var client *http.Client
// Same user agent as Invidious // 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" 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 ipv6_only = false
var version string
type statusJson struct { type statusJson struct {
RequestCount int64 `json:"requestCount"` Version string `json:"version"`
RequestPerSecond int64 `json:"requestPerSecond"` RequestCount int64 `json:"requestCount"`
RequestPerMinute int64 `json:"requestPerMinute"` RequestPerSecond int64 `json:"requestPerSecond"`
RequestPerMinute int64 `json:"requestPerMinute"`
RequestsForbidden struct { RequestsForbidden struct {
Videoplayback int64 `json:"videoplayback"` Videoplayback int64 `json:"videoplayback"`
Vi int64 `json:"vi"` Vi int64 `json:"vi"`
@ -96,6 +100,7 @@ type statusJson struct {
} }
var stats_ = statusJson{ var stats_ = statusJson{
Version: version + "-" + runtime.GOARCH,
RequestCount: 0, RequestCount: 0,
RequestPerSecond: 0, RequestPerSecond: 0,
RequestPerMinute: 0, RequestPerMinute: 0,
@ -186,8 +191,10 @@ func main() {
path_prefix = os.Getenv("PREFIX_PATH") path_prefix = os.Getenv("PREFIX_PATH")
ipv6_only = os.Getenv("IPV6_ONLY") == "1" 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") 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_cert, "tls-cert", "", "TLS Certificate path")
flag.StringVar(&tls_key, "tls-key", "", "TLS Certificate Key path") flag.StringVar(&tls_key, "tls-key", "", "TLS Certificate Key path")
flag.StringVar(&sock, "s", "/tmp/http-ytproxy.sock", "Specify a socket name") 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.StringVar(&host, "l", "0.0.0.0", "Specify a listen address")
flag.Parse() flag.Parse()
if *h3 {
client = h3client
} else {
client = h2client
}
if *https { if *https {
if len(tls_cert) <= 0 { if len(tls_cert) <= 0 {
fmt.Println("tls-cert argument is missing") fmt.Println("tls-cert argument is missing")