feat: show version in stats

master
Shengjing Zhu 2022-07-24 21:09:07 +08:00
parent 74a362f803
commit 6962a4bdc6
4 changed files with 39 additions and 4 deletions

View File

@ -16,6 +16,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

View File

@ -1,10 +1,36 @@
# syntax=docker/dockerfile:1
FROM --platform=$BUILDPLATFORM golang as builder
WORKDIR /app
COPY . .
COPY go.mod .
RUN go mod download
COPY . .
RUN <<EOF
set -ex
tag=$(git describe --tags --always --abbrev=8 --dirty)
if echo "$tag" | grep -q dirty; then exit 1; fi
file_prefix=$(go env GOMODCACHE)/cache/download/github.com/zhsj/wghttp/@v/$tag
mkdir -p $(dirname "$file_prefix")
echo "{\"Version\": \"$tag\"}" > "$file_prefix".info
cp go.mod "$file_prefix".mod
git archive --prefix=github.com/zhsj/wghttp@"$tag"/ -o "$file_prefix".zip HEAD
EOF
ARG TARGETARCH
RUN CGO_ENABLED=0 GOARCH=$TARGETARCH go build -v -trimpath -ldflags="-w -s" .
RUN <<EOF
set -ex
export CGO_ENABLED=0
export GOARCH=$TARGETARCH
export GOPROXY=file://$(go env GOMODCACHE)/cache/download
export GOSUMDB=off
tag=$(git describe --tags --abbrev=8 --always)
go install -trimpath -ldflags="-w -s" github.com/zhsj/wghttp@"$tag"
cross_bin=/go/bin/$(go env GOOS)_$(go env GOARCH)/wghttp
if [ -e "$cross_bin" ]; then mv "$cross_bin" /go/bin/wghttp; fi
EOF
FROM scratch
COPY --from=builder /app/wghttp /
COPY --from=builder /go/bin/wghttp /
ENTRYPOINT ["/wghttp"]

View File

@ -60,7 +60,7 @@ Set `--resolve-interval=` to `0` to disable this behaviour.
## DNS server format
Both `--dns=` and `--resolve-dns=` options supports following format:
Both `--dns=` and `--resolve-dns=` options support following format:
- Plain DNS

View File

@ -4,6 +4,7 @@ import (
"bufio"
"bytes"
"runtime"
"runtime/debug"
"strconv"
"strings"
@ -25,10 +26,16 @@ func stats(dev *device.Device) func() (any, error) {
SentBytes int64
NumGoroutine int
Version string
}{
NumGoroutine: runtime.NumGoroutine(),
}
info, ok := debug.ReadBuildInfo()
if ok {
stats.Version = info.Main.Version
}
scanner := bufio.NewScanner(&buf)
for scanner.Scan() {
line := scanner.Text()