Skip to content

Commit 03cad9f

Browse files
author
yusing
committed
added package version api, dependencies upgrade
1 parent aa6fafd commit 03cad9f

File tree

15 files changed

+107
-193
lines changed

15 files changed

+107
-193
lines changed

.github/workflows/docker-image.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ jobs:
6161
outputs: type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true
6262
cache-from: type=gha
6363
cache-to: type=gha,mode=max
64+
build-args: |
65+
VERSION=${{ github.ref_name }}
6466
6567
- name: Generate artifact attestation
6668
uses: actions/attest-build-provenance@v1

.gitlab-ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ build-image:
1111
- echo $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER $CI_REGISTRY --password-stdin
1212
script:
1313
- echo building $CI_REGISTRY_IMAGE
14-
- docker build --pull -t $CI_REGISTRY_IMAGE .
15-
- docker push $CI_REGISTRY_IMAGE
14+
- docker build --no-cache --build-arg VERSION=$CI_COMMIT_REF_NAME -t $CI_REGISTRY_IMAGE .
15+
- docker push $CI_REGISTRY_IMAGE

Dockerfile

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Stage 1: Builder
22
FROM golang:1.23.1-alpine AS builder
3-
RUN apk add --no-cache tzdata
3+
RUN apk add --no-cache tzdata make
44

55
WORKDIR /src
66

@@ -13,13 +13,20 @@ RUN --mount=type=cache,target="/go/pkg/mod" \
1313

1414
ENV GOCACHE=/root/.cache/go-build
1515

16-
# Build the application with better caching
16+
ARG VERSION
17+
ENV VERSION=${VERSION}
18+
19+
COPY scripts /src/scripts
20+
COPY Makefile /src/
21+
1722
RUN --mount=type=cache,target="/go/pkg/mod" \
1823
--mount=type=cache,target="/root/.cache/go-build" \
1924
--mount=type=bind,src=cmd,dst=/src/cmd \
2025
--mount=type=bind,src=internal,dst=/src/internal \
21-
CGO_ENABLED=0 GOOS=linux go build -ldflags '-w -s' -pgo=auto -o /app/go-proxy ./cmd && \
22-
mkdir /app/error_pages /app/certs
26+
--mount=type=bind,src=pkg,dst=/src/pkg \
27+
make build && \
28+
mkdir -p /app/error_pages /app/certs && \
29+
cp bin/go-proxy /app/go-proxy
2330

2431
# Stage 2: Final image
2532
FROM scratch

Makefile

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
BUILD_FLAG ?= -s -w
1+
VERSION ?= $(shell git describe --tags --abbrev=0)
2+
BUILD_FLAGS ?= -s -w -X github.com/yusing/go-proxy/pkg.version=${VERSION}
3+
export VERSION
4+
export BUILD_FLAGS
5+
export CGO_ENABLED = 0
6+
export GOOS = linux
27

38
.PHONY: all setup build test up restart logs get debug run archive repush rapid-crash debug-list-containers
49

510
all: debug
611

7-
setup:
8-
mkdir -p config certs
9-
[ -f config/config.yml ] || cp config.example.yml config/config.yml
10-
[ -f config/providers.yml ] || touch config/providers.yml
11-
1212
build:
13-
mkdir -p bin
14-
CGO_ENABLED=0 GOOS=linux \
15-
go build -ldflags '${BUILD_FLAG}' -pgo=auto -o bin/go-proxy ./cmd
13+
scripts/build.sh
1614

1715
test:
1816
GOPROXY_TEST=1 go test ./internal/...
@@ -30,10 +28,10 @@ get:
3028
go get -u ./cmd && go mod tidy
3129

3230
debug:
33-
make BUILD_FLAG="" build && sudo GOPROXY_DEBUG=1 bin/go-proxy
31+
make build && sudo GOPROXY_DEBUG=1 bin/go-proxy
3432

3533
run-test:
36-
make BUILD_FLAG="" build && sudo GOPROXY_TEST=1 bin/go-proxy
34+
make build && sudo GOPROXY_TEST=1 bin/go-proxy
3735

3836
run:
3937
make build && sudo bin/go-proxy

cmd/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
R "github.com/yusing/go-proxy/internal/route"
2929
"github.com/yusing/go-proxy/internal/server"
3030
F "github.com/yusing/go-proxy/internal/utils/functional"
31+
"github.com/yusing/go-proxy/pkg"
3132
)
3233

3334
func main() {
@@ -54,6 +55,7 @@ func main() {
5455
ForceColors: true,
5556
TimestampFormat: "01-02 15:04:05",
5657
})
58+
logrus.Infof("go-proxy version %s", pkg.GetVersion())
5759
}
5860

5961
if args.Command == common.CommandReload {

go.mod

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@ module github.com/yusing/go-proxy
33
go 1.23.1
44

55
require (
6+
github.com/coder/websocket v1.8.12
67
github.com/docker/cli v27.3.1+incompatible
78
github.com/docker/docker v27.3.1+incompatible
89
github.com/fsnotify/fsnotify v1.7.0
9-
github.com/go-acme/lego/v4 v4.18.0
10+
github.com/go-acme/lego/v4 v4.19.0
1011
github.com/puzpuzpuz/xsync/v3 v3.4.0
1112
github.com/santhosh-tekuri/jsonschema v1.2.4
1213
github.com/sirupsen/logrus v1.9.3
13-
golang.org/x/net v0.29.0
14-
golang.org/x/text v0.18.0
14+
golang.org/x/net v0.30.0
15+
golang.org/x/text v0.19.0
1516
gopkg.in/yaml.v3 v3.0.1
1617
)
1718

1819
require (
1920
github.com/Microsoft/go-winio v0.6.2 // indirect
2021
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
2122
github.com/cloudflare/cloudflare-go v0.106.0 // indirect
22-
github.com/coder/websocket v1.8.12 // indirect
2323
github.com/containerd/log v0.1.0 // indirect
2424
github.com/distribution/reference v0.6.0 // indirect
2525
github.com/docker/go-connections v0.5.0 // indirect
@@ -47,13 +47,13 @@ require (
4747
go.opentelemetry.io/otel/metric v1.30.0 // indirect
4848
go.opentelemetry.io/otel/sdk v1.30.0 // indirect
4949
go.opentelemetry.io/otel/trace v1.30.0 // indirect
50-
golang.org/x/crypto v0.27.0 // indirect
50+
golang.org/x/crypto v0.28.0 // indirect
5151
golang.org/x/mod v0.21.0 // indirect
5252
golang.org/x/oauth2 v0.23.0 // indirect
5353
golang.org/x/sync v0.8.0 // indirect
54-
golang.org/x/sys v0.25.0 // indirect
55-
golang.org/x/time v0.6.0 // indirect
56-
golang.org/x/tools v0.25.0 // indirect
54+
golang.org/x/sys v0.26.0 // indirect
55+
golang.org/x/time v0.7.0 // indirect
56+
golang.org/x/tools v0.26.0 // indirect
5757
gopkg.in/ini.v1 v1.67.0 // indirect
5858
gotest.tools/v3 v3.5.1 // indirect
5959
)

go.sum

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I=
1212
github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo=
1313
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
1414
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
15-
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
1615
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
16+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
17+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1718
github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk=
1819
github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
1920
github.com/docker/cli v27.3.1+incompatible h1:qEGdFBF3Xu6SCvCYhc7CzaQTlBmqDuzxPDpigSyeKQQ=
@@ -28,8 +29,8 @@ github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2
2829
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
2930
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
3031
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
31-
github.com/go-acme/lego/v4 v4.18.0 h1:2hH8KcdRBSb+p5o9VZIm61GAOXYALgILUCSs1Q+OYsk=
32-
github.com/go-acme/lego/v4 v4.18.0/go.mod h1:Blkg3izvXpl3zxk7WKngIuwR2I/hvYVP3vRnvgBp7m8=
32+
github.com/go-acme/lego/v4 v4.19.0 h1:c7YabBOwoa2URsPiCNGQsdzQnbd8Y23B4/66gxh4H7c=
33+
github.com/go-acme/lego/v4 v4.19.0/go.mod h1:wtDe3dDkmV4/oI2nydpNXSJpvV10J9RCyZ6MbYxNtlQ=
3334
github.com/go-jose/go-jose/v4 v4.0.4 h1:VsjPI33J0SB9vQM6PLmNjoHqMQNGPiZ0rHL7Ni7Q6/E=
3435
github.com/go-jose/go-jose/v4 v4.0.4/go.mod h1:NKb5HO1EZccyMpiZNbdUw/14tiXNyUJh188dfnMCAfc=
3536
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
@@ -48,8 +49,6 @@ github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD
4849
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
4950
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
5051
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
51-
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
52-
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
5352
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 h1:asbCHRVmodnJTuQ3qamDwqVOIjwqUPTYmYuemVOx+Ys=
5453
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0/go.mod h1:ggCgvZ2r7uOoQjOyu2Y1NhHmEPPzzuhWgcza5M1Ji1I=
5554
github.com/jarcoal/httpmock v1.3.0 h1:2RJ8GP0IIaWwcC9Fp2BmVi8Kog3v2Hn7VXM3fTd+nuc=
@@ -79,8 +78,9 @@ github.com/ovh/go-ovh v1.6.0/go.mod h1:cTVDnl94z4tl8pP1uZ/8jlVxntjSIf09bNcQ5TJSC
7978
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
8079
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
8180
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
82-
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
8381
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
82+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
83+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
8484
github.com/puzpuzpuz/xsync/v3 v3.4.0 h1:DuVBAdXuGFHv8adVXjWWZ63pJq+NRXOWVXlKDBZ+mJ4=
8585
github.com/puzpuzpuz/xsync/v3 v3.4.0/go.mod h1:VjzYrABPabuM4KyBh1Ftq6u8nhwY5tBPKP9jpmh0nnA=
8686
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
@@ -115,8 +115,8 @@ go.opentelemetry.io/proto/otlp v1.3.1/go.mod h1:0X1WI4de4ZsLrrJNLAQbFeLCm3T7yBkR
115115
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
116116
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
117117
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
118-
golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A=
119-
golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70=
118+
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
119+
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U=
120120
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
121121
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
122122
golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0=
@@ -125,8 +125,8 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
125125
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
126126
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
127127
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
128-
golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo=
129-
golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0=
128+
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
129+
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
130130
golang.org/x/oauth2 v0.23.0 h1:PbgcYx2W7i4LvjJWEbf0ngHV6qJYr86PkAV3bXdLEbs=
131131
golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
132132
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -138,25 +138,25 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h
138138
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
139139
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
140140
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
141-
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
142-
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
141+
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
142+
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
143143
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
144144
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
145-
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
146-
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
147-
golang.org/x/time v0.6.0 h1:eTDhh4ZXt5Qf0augr54TN6suAUudPcawVZeIAPU7D4U=
148-
golang.org/x/time v0.6.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
145+
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
146+
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
147+
golang.org/x/time v0.7.0 h1:ntUhktv3OPE6TgYxXWv9vKvUSJyIFJlyohwbkEwPrKQ=
148+
golang.org/x/time v0.7.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
149149
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
150150
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
151151
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
152152
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
153-
golang.org/x/tools v0.25.0 h1:oFU9pkj/iJgs+0DT+VMHrx+oBKs/LJMV+Uvg78sl+fE=
154-
golang.org/x/tools v0.25.0/go.mod h1:/vtpO8WL1N9cQC3FN5zPqb//fRXskFHbLKk4OW1Q7rg=
153+
golang.org/x/tools v0.26.0 h1:v/60pFQmzmT9ExmjDv2gGIfi3OqfKoEP6I5+umXlbnQ=
154+
golang.org/x/tools v0.26.0/go.mod h1:TPVVj70c7JJ3WCazhD8OdXcZg/og+b9+tH/KxylGwH0=
155155
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
156156
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
157157
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
158158
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
159-
google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de h1:F6qOa9AZTYJXOUEr4jDysRDLrm4PHePlge4v4TGAlxY=
159+
google.golang.org/genproto v0.0.0-20240903143218-8af14fe29dc1 h1:BulPr26Jqjnd4eYDVe+YvyR7Yc2vJGkO5/0UxD0/jZU=
160160
google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1 h1:hjSy6tcFQZ171igDaN5QHOw2n6vx40juYbC/x67CEhc=
161161
google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1/go.mod h1:qpvKtACPCQhAdu3PyQgV4l3LMXZEtft7y8QcarRsp9I=
162162
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 h1:pPJltXNxVzT4pK9yD8vR9X75DaWYYmLGMsEvBfFQZzQ=

internal/api/handler.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ func (mux ServeMux) HandleFunc(method, endpoint string, handler http.HandlerFunc
2424
func NewHandler(cfg *config.Config) http.Handler {
2525
mux := NewServeMux()
2626
mux.HandleFunc("GET", "/v1", v1.Index)
27+
mux.HandleFunc("GET", "/v1/version", v1.GetVersion)
2728
mux.HandleFunc("GET", "/v1/checkhealth", wrap(cfg, v1.CheckHealth))
2829
mux.HandleFunc("HEAD", "/v1/checkhealth", wrap(cfg, v1.CheckHealth))
2930
mux.HandleFunc("POST", "/v1/reload", wrap(cfg, v1.Reload))

internal/api/v1/version.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package v1
2+
3+
import (
4+
"net/http"
5+
6+
"github.com/yusing/go-proxy/pkg"
7+
)
8+
9+
func GetVersion(w http.ResponseWriter, r *http.Request) {
10+
w.Write([]byte(pkg.GetVersion()))
11+
}

internal/net/http/header_utils.go

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package http
22

33
import (
44
"net/http"
5+
"slices"
56
)
67

78
func RemoveHop(h http.Header) {
@@ -24,30 +25,18 @@ func CopyHeader(dst, src http.Header) {
2425
}
2526
}
2627

27-
func FilterHeaders(h http.Header, allowed []string) http.Header {
28-
if len(allowed) == 0 {
29-
return h
28+
func FilterHeaders(h http.Header, allowed []string) {
29+
if allowed == nil {
30+
return
3031
}
3132

32-
filtered := make(http.Header)
33-
34-
for i, header := range allowed {
35-
values := h.Values(header)
36-
if len(values) == 0 {
37-
continue
38-
}
39-
filtered[http.CanonicalHeaderKey(allowed[i])] = append([]string(nil), values...)
33+
for i := range allowed {
34+
allowed[i] = http.CanonicalHeaderKey(allowed[i])
4035
}
4136

42-
return filtered
43-
}
44-
45-
func HeaderToMap(h http.Header) map[string]string {
46-
result := make(map[string]string)
47-
for k, v := range h {
48-
if len(v) > 0 {
49-
result[k] = v[0] // Take the first value
37+
for key := range h {
38+
if !slices.Contains(allowed, key) {
39+
h.Del(key)
5040
}
5141
}
52-
return result
5342
}

0 commit comments

Comments
 (0)