Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 573086694b | |||
|
|
3992a2bfb2 | ||
| b5d9fd5764 | |||
|
|
39ad61b34e | ||
| 1cb2b3c241 | |||
| 732b5685fb | |||
| 6cddb5f218 | |||
| dd4578a57d | |||
| c6b72d7a7a | |||
| 545e372b82 | |||
| d7ffae7b16 | |||
| 8c745c3f74 | |||
| db910c9ff5 | |||
|
|
984c6495c6 | ||
| 7f904d0cc7 |
@@ -1,14 +0,0 @@
|
|||||||
---
|
|
||||||
name: Question
|
|
||||||
about: Ask a question about go-micro
|
|
||||||
title: ''
|
|
||||||
labels: ''
|
|
||||||
assignees: ''
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
Before asking, please check if your question has already been answered:
|
|
||||||
|
|
||||||
1. Check the documentation - https://micro.mu/docs/
|
|
||||||
2. Check the examples and plugins - https://github.com/micro/examples & https://github.com/micro/go-plugins
|
|
||||||
3. Search existing issues
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
name: Bug report
|
name: Bug report
|
||||||
about: For reporting bugs in go-micro
|
about: For reporting bugs in micro
|
||||||
title: "[BUG]"
|
title: "[BUG]"
|
||||||
labels: ''
|
labels: ''
|
||||||
assignees: ''
|
assignees: ''
|
||||||
@@ -16,9 +16,3 @@ assignees: ''
|
|||||||
**How to reproduce the bug:**
|
**How to reproduce the bug:**
|
||||||
|
|
||||||
If possible, please include a minimal code snippet here.
|
If possible, please include a minimal code snippet here.
|
||||||
|
|
||||||
**Environment:**
|
|
||||||
Go Version: please paste `go version` output here
|
|
||||||
```
|
|
||||||
please paste `go env` output here
|
|
||||||
```
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
name: Feature request / Enhancement
|
name: Feature request / Enhancement
|
||||||
about: If you have a need not served by go-micro
|
about: If you have a need not served by micro
|
||||||
title: "[FEATURE]"
|
title: "[FEATURE]"
|
||||||
labels: ''
|
labels: ''
|
||||||
assignees: ''
|
assignees: ''
|
||||||
8
.github/ISSUE_TEMPLATE/question.md
vendored
Normal file
8
.github/ISSUE_TEMPLATE/question.md
vendored
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
---
|
||||||
|
name: Question
|
||||||
|
about: Ask a question about micro
|
||||||
|
title: ''
|
||||||
|
labels: ''
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
28
.github/autoapprove.yml
vendored
Normal file
28
.github/autoapprove.yml
vendored
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
name: "autoapprove"
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request_target:
|
||||||
|
types: [assigned, opened, synchronize, reopened]
|
||||||
|
workflow_run:
|
||||||
|
workflows: ["prbuild"]
|
||||||
|
types:
|
||||||
|
- completed
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
pull-requests: write
|
||||||
|
contents: write
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
autoapprove:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: approve
|
||||||
|
run: [ "curl -o tea https://dl.gitea.com/tea/main/tea-main-linux-amd64",
|
||||||
|
"chmod +x ./tea",
|
||||||
|
"./tea login add --name unistack --token ${{ secrets.GITHUB_TOKEN }} --url https://git.unistack.org",
|
||||||
|
"./tea pr --repo ${{ github.event.repository.name }}"
|
||||||
|
]
|
||||||
|
if: github.actor == 'vtolstov'
|
||||||
|
id: approve
|
||||||
|
with:
|
||||||
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
53
.github/workflows/job_coverage.yml
vendored
Normal file
53
.github/workflows/job_coverage.yml
vendored
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
name: coverage
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ main, v3, v4 ]
|
||||||
|
paths-ignore:
|
||||||
|
- '.github/**'
|
||||||
|
- '.gitea/**'
|
||||||
|
pull_request:
|
||||||
|
branches: [ main, v3, v4 ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
build:
|
||||||
|
if: github.server_url != 'https://github.com'
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
filter: 'blob:none'
|
||||||
|
|
||||||
|
- name: setup go
|
||||||
|
uses: actions/setup-go@v5
|
||||||
|
with:
|
||||||
|
cache-dependency-path: "**/*.sum"
|
||||||
|
go-version: 'stable'
|
||||||
|
|
||||||
|
- name: test coverage
|
||||||
|
run: |
|
||||||
|
go test -v -cover ./... -covermode=count -coverprofile coverage.out -coverpkg ./...
|
||||||
|
go tool cover -func coverage.out -o coverage.out
|
||||||
|
|
||||||
|
- name: coverage badge
|
||||||
|
uses: tj-actions/coverage-badge-go@v2
|
||||||
|
with:
|
||||||
|
green: 80
|
||||||
|
filename: coverage.out
|
||||||
|
|
||||||
|
- uses: stefanzweifel/git-auto-commit-action@v4
|
||||||
|
name: autocommit
|
||||||
|
with:
|
||||||
|
commit_message: Apply Code Coverage Badge
|
||||||
|
skip_fetch: false
|
||||||
|
skip_checkout: false
|
||||||
|
file_pattern: ./README.md
|
||||||
|
|
||||||
|
- name: push
|
||||||
|
if: steps.auto-commit-action.outputs.changes_detected == 'true'
|
||||||
|
uses: ad-m/github-push-action@master
|
||||||
|
with:
|
||||||
|
github_token: ${{ github.token }}
|
||||||
|
branch: ${{ github.ref }}
|
||||||
@@ -3,10 +3,10 @@ name: lint
|
|||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
types: [opened, reopened, synchronize]
|
types: [opened, reopened, synchronize]
|
||||||
branches:
|
branches: [ master, v3, v4 ]
|
||||||
- master
|
paths-ignore:
|
||||||
- v3
|
- '.github/**'
|
||||||
- v4
|
- '.gitea/**'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
lint:
|
lint:
|
||||||
@@ -24,6 +24,6 @@ jobs:
|
|||||||
- name: setup deps
|
- name: setup deps
|
||||||
run: go get -v ./...
|
run: go get -v ./...
|
||||||
- name: run lint
|
- name: run lint
|
||||||
uses: https://github.com/golangci/golangci-lint-action@v6
|
uses: golangci/golangci-lint-action@v6
|
||||||
with:
|
with:
|
||||||
version: 'latest'
|
version: 'latest'
|
||||||
94
.github/workflows/job_sync.yml
vendored
Normal file
94
.github/workflows/job_sync.yml
vendored
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
name: sync
|
||||||
|
|
||||||
|
on:
|
||||||
|
schedule:
|
||||||
|
- cron: '*/5 * * * *'
|
||||||
|
# Allows you to run this workflow manually from the Actions tab
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
sync:
|
||||||
|
if: github.server_url != 'https://github.com'
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: init
|
||||||
|
run: |
|
||||||
|
git config --global user.email "vtolstov <vtolstov@users.noreply.github.com>"
|
||||||
|
git config --global user.name "github-actions[bot]"
|
||||||
|
echo "machine git.unistack.org login vtolstov password ${{ secrets.TOKEN_GITEA }}" >> /root/.netrc
|
||||||
|
echo "machine github.com login vtolstov password ${{ secrets.TOKEN_GITHUB }}" >> /root/.netrc
|
||||||
|
|
||||||
|
- name: check master
|
||||||
|
id: check_master
|
||||||
|
run: |
|
||||||
|
src_hash=$(git ls-remote https://github.com/${GITHUB_REPOSITORY} refs/heads/master | cut -f1)
|
||||||
|
dst_hash=$(git ls-remote ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY} refs/heads/master | cut -f1)
|
||||||
|
echo "src_hash=$src_hash"
|
||||||
|
echo "dst_hash=$dst_hash"
|
||||||
|
if [ "$src_hash" != "$dst_hash" ]; then
|
||||||
|
echo "sync_needed=true" >> $GITHUB_OUTPUT
|
||||||
|
else
|
||||||
|
echo "sync_needed=false" >> $GITHUB_OUTPUT
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: sync master
|
||||||
|
if: steps.check_master.outputs.sync_needed == 'true'
|
||||||
|
run: |
|
||||||
|
git clone --filter=blob:none --filter=tree:0 --branch master --single-branch ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY} repo
|
||||||
|
cd repo
|
||||||
|
git remote add --no-tags --fetch --track master upstream https://github.com/${GITHUB_REPOSITORY}
|
||||||
|
git pull --rebase upstream master
|
||||||
|
git push upstream master --progress
|
||||||
|
git push origin master --progress
|
||||||
|
cd ../
|
||||||
|
rm -rf repo
|
||||||
|
|
||||||
|
- name: check v3
|
||||||
|
id: check_v3
|
||||||
|
run: |
|
||||||
|
src_hash=$(git ls-remote https://github.com/${GITHUB_REPOSITORY} refs/heads/v3 | cut -f1)
|
||||||
|
dst_hash=$(git ls-remote ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY} refs/heads/v3 | cut -f1)
|
||||||
|
echo "src_hash=$src_hash"
|
||||||
|
echo "dst_hash=$dst_hash"
|
||||||
|
if [ "$src_hash" != "$dst_hash" ]; then
|
||||||
|
echo "sync_needed=true" >> $GITHUB_OUTPUT
|
||||||
|
else
|
||||||
|
echo "sync_needed=false" >> $GITHUB_OUTPUT
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: sync v3
|
||||||
|
if: steps.check_v3.outputs.sync_needed == 'true'
|
||||||
|
run: |
|
||||||
|
git clone --filter=blob:none --filter=tree:0 --branch v3 --single-branch ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY} repo
|
||||||
|
cd repo
|
||||||
|
git remote add --no-tags --fetch --track v3 upstream https://github.com/${GITHUB_REPOSITORY}
|
||||||
|
git pull --rebase upstream v3
|
||||||
|
git push upstream v3 --progress
|
||||||
|
git push origin v3 --progress
|
||||||
|
cd ../
|
||||||
|
rm -rf repo
|
||||||
|
|
||||||
|
- name: check v4
|
||||||
|
id: check_v4
|
||||||
|
run: |
|
||||||
|
src_hash=$(git ls-remote https://github.com/${GITHUB_REPOSITORY} refs/heads/v4 | cut -f1)
|
||||||
|
dst_hash=$(git ls-remote ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY} refs/heads/v4 | cut -f1)
|
||||||
|
echo "src_hash=$src_hash"
|
||||||
|
echo "dst_hash=$dst_hash"
|
||||||
|
if [ "$src_hash" != "$dst_hash" ]; then
|
||||||
|
echo "sync_needed=true" >> $GITHUB_OUTPUT
|
||||||
|
else
|
||||||
|
echo "sync_needed=false" >> $GITHUB_OUTPUT
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: sync v4
|
||||||
|
if: steps.check_v4.outputs.sync_needed == 'true'
|
||||||
|
run: |
|
||||||
|
git clone --filter=blob:none --filter=tree:0 --branch v4 --single-branch ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY} repo
|
||||||
|
cd repo
|
||||||
|
git remote add --no-tags --fetch --track v4 upstream https://github.com/${GITHUB_REPOSITORY}
|
||||||
|
git pull --rebase upstream v4
|
||||||
|
git push upstream v4 --progress
|
||||||
|
git push origin v4 --progress
|
||||||
|
cd ../
|
||||||
|
rm -rf repo
|
||||||
@@ -3,15 +3,12 @@ name: test
|
|||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
types: [opened, reopened, synchronize]
|
types: [opened, reopened, synchronize]
|
||||||
branches:
|
branches: [ master, v3, v4 ]
|
||||||
- master
|
|
||||||
- v3
|
|
||||||
- v4
|
|
||||||
push:
|
push:
|
||||||
branches:
|
branches: [ master, v3, v4 ]
|
||||||
- master
|
paths-ignore:
|
||||||
- v3
|
- '.github/**'
|
||||||
- v4
|
- '.gitea/**'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
@@ -3,15 +3,12 @@ name: test
|
|||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
types: [opened, reopened, synchronize]
|
types: [opened, reopened, synchronize]
|
||||||
branches:
|
branches: [ master, v3, v4 ]
|
||||||
- master
|
|
||||||
- v3
|
|
||||||
- v4
|
|
||||||
push:
|
push:
|
||||||
branches:
|
branches: [ master, v3, v4 ]
|
||||||
- master
|
paths-ignore:
|
||||||
- v3
|
- '.github/**'
|
||||||
- v4
|
- '.gitea/**'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
@@ -35,19 +32,19 @@ jobs:
|
|||||||
go-version: 'stable'
|
go-version: 'stable'
|
||||||
- name: setup go work
|
- name: setup go work
|
||||||
env:
|
env:
|
||||||
GOWORK: /workspace/${{ github.repository_owner }}/go.work
|
GOWORK: ${{ github.workspace }}/go.work
|
||||||
run: |
|
run: |
|
||||||
go work init
|
go work init
|
||||||
go work use .
|
go work use .
|
||||||
go work use micro-tests
|
go work use micro-tests
|
||||||
- name: setup deps
|
- name: setup deps
|
||||||
env:
|
env:
|
||||||
GOWORK: /workspace/${{ github.repository_owner }}/go.work
|
GOWORK: ${{ github.workspace }}/go.work
|
||||||
run: go get -v ./...
|
run: go get -v ./...
|
||||||
- name: run tests
|
- name: run tests
|
||||||
env:
|
env:
|
||||||
INTEGRATION_TESTS: yes
|
INTEGRATION_TESTS: yes
|
||||||
GOWORK: /workspace/${{ github.repository_owner }}/go.work
|
GOWORK: ${{ github.workspace }}/go.work
|
||||||
run: |
|
run: |
|
||||||
cd micro-tests
|
cd micro-tests
|
||||||
go test -mod readonly -v ./... || true
|
go test -mod readonly -v ./... || true
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
run:
|
run:
|
||||||
concurrency: 8
|
concurrency: 8
|
||||||
deadline: 5m
|
timeout: 5m
|
||||||
issues-exit-code: 1
|
issues-exit-code: 1
|
||||||
tests: true
|
tests: true
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
# HTTP Server
|
# HTTP Server
|
||||||
|

|
||||||
|
|
||||||
The HTTP Server is a go-micro.Server. It's a partial implementation which strips out codecs, transports, etc but enables you
|
The HTTP Server is a go-micro.Server. It's a partial implementation which strips out codecs, transports, etc but enables you
|
||||||
to create a HTTP Server that could potentially be used for REST based API services.
|
to create a HTTP Server that could potentially be used for REST based API services.
|
||||||
|
|||||||
17
go.mod
17
go.mod
@@ -1,25 +1,28 @@
|
|||||||
module go.unistack.org/micro-server-http/v4
|
module go.unistack.org/micro-server-http/v4
|
||||||
|
|
||||||
go 1.23.0
|
go 1.24.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/stretchr/testify v1.10.0
|
||||||
go.unistack.org/micro-client-http/v4 v4.1.0
|
go.unistack.org/micro-client-http/v4 v4.1.0
|
||||||
go.unistack.org/micro-codec-yaml/v4 v4.1.0
|
go.unistack.org/micro-codec-yaml/v4 v4.1.0
|
||||||
go.unistack.org/micro-proto/v4 v4.1.0
|
go.unistack.org/micro-proto/v4 v4.1.0
|
||||||
go.unistack.org/micro/v4 v4.1.2
|
go.unistack.org/micro/v4 v4.1.8
|
||||||
golang.org/x/net v0.35.0
|
golang.org/x/net v0.39.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/ash3in/uuidv8 v1.2.0 // indirect
|
github.com/ash3in/uuidv8 v1.2.0 // indirect
|
||||||
|
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
|
||||||
github.com/google/gnostic v0.7.0 // indirect
|
github.com/google/gnostic v0.7.0 // indirect
|
||||||
github.com/google/gnostic-models v0.6.9 // indirect
|
github.com/google/gnostic-models v0.6.9 // indirect
|
||||||
github.com/google/uuid v1.6.0 // indirect
|
github.com/google/uuid v1.6.0 // indirect
|
||||||
github.com/matoous/go-nanoid v1.5.1 // indirect
|
github.com/matoous/go-nanoid v1.5.1 // indirect
|
||||||
|
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
|
||||||
github.com/spf13/cast v1.7.1 // indirect
|
github.com/spf13/cast v1.7.1 // indirect
|
||||||
golang.org/x/sys v0.30.0 // indirect
|
golang.org/x/sys v0.32.0 // indirect
|
||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20250227231956-55c901821b1e // indirect
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20250428153025-10db94c68c34 // indirect
|
||||||
google.golang.org/grpc v1.70.0 // indirect
|
google.golang.org/grpc v1.72.0 // indirect
|
||||||
google.golang.org/protobuf v1.36.5 // indirect
|
google.golang.org/protobuf v1.36.6 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
34
go.sum
34
go.sum
@@ -639,6 +639,8 @@ github.com/cncf/xds/go v0.0.0-20230105202645-06c439db220b/go.mod h1:eXthEFrGJvWH
|
|||||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
|
||||||
|
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
|
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
|
||||||
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
|
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
|
||||||
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||||
@@ -824,6 +826,8 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
|
|||||||
github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI=
|
github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI=
|
||||||
github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg=
|
github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
|
||||||
|
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||||
github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||||
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
|
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
|
||||||
@@ -854,6 +858,8 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
|
|||||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||||
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||||
|
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||||
|
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
|
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
|
||||||
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ=
|
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ=
|
||||||
github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
|
github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
|
||||||
@@ -882,8 +888,8 @@ go.unistack.org/micro-codec-yaml/v4 v4.1.0 h1:9utR2ka47CDEShbuF7QBAfv0lAFp06pXh7
|
|||||||
go.unistack.org/micro-codec-yaml/v4 v4.1.0/go.mod h1:aMd5xKrJiUMvh6PNdYbO3G59JZfjSHRXdmNA4RCr8Mw=
|
go.unistack.org/micro-codec-yaml/v4 v4.1.0/go.mod h1:aMd5xKrJiUMvh6PNdYbO3G59JZfjSHRXdmNA4RCr8Mw=
|
||||||
go.unistack.org/micro-proto/v4 v4.1.0 h1:qPwL2n/oqh9RE3RTTDgt28XK3QzV597VugQPaw9lKUk=
|
go.unistack.org/micro-proto/v4 v4.1.0 h1:qPwL2n/oqh9RE3RTTDgt28XK3QzV597VugQPaw9lKUk=
|
||||||
go.unistack.org/micro-proto/v4 v4.1.0/go.mod h1:ArmK7o+uFvxSY3dbJhKBBX4Pm1rhWdLEFf3LxBrMtec=
|
go.unistack.org/micro-proto/v4 v4.1.0/go.mod h1:ArmK7o+uFvxSY3dbJhKBBX4Pm1rhWdLEFf3LxBrMtec=
|
||||||
go.unistack.org/micro/v4 v4.1.2 h1:9SOlPYyPNNFpg1A7BsvhDyQm3gysLH1AhWbDCp1hyoY=
|
go.unistack.org/micro/v4 v4.1.8 h1:bbqnQ7nzTYNIYt4HhRgmh/++qzwGJvlNbrTOoXzkQiU=
|
||||||
go.unistack.org/micro/v4 v4.1.2/go.mod h1:lr3oYED8Ay1vjK68QqRw30QOtdk/ffpZqMFDasOUhKw=
|
go.unistack.org/micro/v4 v4.1.8/go.mod h1:b4dr7RFlbpSfSsKCva9UuX4zLtkYQteEK+Uuac39qJE=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
@@ -1005,8 +1011,8 @@ golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws=
|
|||||||
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||||
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||||
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
|
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
|
||||||
golang.org/x/net v0.35.0 h1:T5GQRQb2y08kTAByq9L4/bz8cipCdA8FbRTXewonqY8=
|
golang.org/x/net v0.39.0 h1:ZCu7HMWDxpXpaiKdhzIfaltL9Lp31x/3fCP11bc6/fY=
|
||||||
golang.org/x/net v0.35.0/go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk=
|
golang.org/x/net v0.39.0/go.mod h1:X7NRbYVEA+ewNkCNyJ513WmMdQ3BineSwVtN2zD/d+E=
|
||||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||||
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||||
@@ -1126,8 +1132,8 @@ golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|||||||
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
|
golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20=
|
||||||
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||||
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
|
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
|
||||||
@@ -1149,8 +1155,8 @@ golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
|||||||
golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||||
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||||
golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
|
golang.org/x/text v0.24.0 h1:dd5Bzh4yt5KYA8f9CJHCP4FB4D51c2c6JvN37xJJkJ0=
|
||||||
golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
|
golang.org/x/text v0.24.0/go.mod h1:L8rBsPeo2pSS+xqN0d5u2ikmjtmoJbDBT1b7nHvFCdU=
|
||||||
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
@@ -1434,8 +1440,8 @@ google.golang.org/genproto/googleapis/api v0.0.0-20230525234020-1aefcd67740a/go.
|
|||||||
google.golang.org/genproto/googleapis/api v0.0.0-20230525234035-dd9d682886f9/go.mod h1:vHYtlOoi6TsQ3Uk2yxR7NI5z8uoV+3pZtR4jmHIkRig=
|
google.golang.org/genproto/googleapis/api v0.0.0-20230525234035-dd9d682886f9/go.mod h1:vHYtlOoi6TsQ3Uk2yxR7NI5z8uoV+3pZtR4jmHIkRig=
|
||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234015-3fc162c6f38a/go.mod h1:xURIpW9ES5+/GZhnV6beoEtxQrnkRGIfP5VQG2tCBLc=
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234015-3fc162c6f38a/go.mod h1:xURIpW9ES5+/GZhnV6beoEtxQrnkRGIfP5VQG2tCBLc=
|
||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19/go.mod h1:66JfowdXAEgad5O9NnYcsNPLCPZJD++2L9X0PCMODrA=
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19/go.mod h1:66JfowdXAEgad5O9NnYcsNPLCPZJD++2L9X0PCMODrA=
|
||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20250227231956-55c901821b1e h1:YA5lmSs3zc/5w+xsRcHqpETkaYyK63ivEPzNTcUUlSA=
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20250428153025-10db94c68c34 h1:h6p3mQqrmT1XkHVTfzLdNz1u7IhINeZkz67/xTbOuWs=
|
||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20250227231956-55c901821b1e/go.mod h1:LuRYeWDFV6WOn90g357N17oMCaxpgCnbi/44qJvDn2I=
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20250428153025-10db94c68c34/go.mod h1:qQ0YXyHHx3XkvlzUtpXDkS29lDSafHMZBAZDc03LQ3A=
|
||||||
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
||||||
google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
|
google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
|
||||||
google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
|
google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
|
||||||
@@ -1475,8 +1481,8 @@ google.golang.org/grpc v1.50.1/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCD
|
|||||||
google.golang.org/grpc v1.51.0/go.mod h1:wgNDFcnuBGmxLKI/qn4T+m5BtEBYXJPvibbUPsAIPww=
|
google.golang.org/grpc v1.51.0/go.mod h1:wgNDFcnuBGmxLKI/qn4T+m5BtEBYXJPvibbUPsAIPww=
|
||||||
google.golang.org/grpc v1.53.0/go.mod h1:OnIrk0ipVdj4N5d9IUoFUx72/VlD7+jUsHwZgwSMQpw=
|
google.golang.org/grpc v1.53.0/go.mod h1:OnIrk0ipVdj4N5d9IUoFUx72/VlD7+jUsHwZgwSMQpw=
|
||||||
google.golang.org/grpc v1.54.0/go.mod h1:PUSEXI6iWghWaB6lXM4knEgpJNu2qUcKfDtNci3EC2g=
|
google.golang.org/grpc v1.54.0/go.mod h1:PUSEXI6iWghWaB6lXM4knEgpJNu2qUcKfDtNci3EC2g=
|
||||||
google.golang.org/grpc v1.70.0 h1:pWFv03aZoHzlRKHWicjsZytKAiYCtNS0dHbXnIdq7jQ=
|
google.golang.org/grpc v1.72.0 h1:S7UkcVa60b5AAQTaO6ZKamFp1zMZSU0fGDK2WZLbBnM=
|
||||||
google.golang.org/grpc v1.70.0/go.mod h1:ofIJqVKDXx/JiXrwr2IG4/zwdH9txy3IlF40RmcJSQw=
|
google.golang.org/grpc v1.72.0/go.mod h1:wH5Aktxcg25y1I3w7H69nHfXdOG3UiadoBtjh3izSDM=
|
||||||
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw=
|
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw=
|
||||||
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
||||||
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
|
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
|
||||||
@@ -1495,8 +1501,8 @@ google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqw
|
|||||||
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||||
google.golang.org/protobuf v1.29.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
google.golang.org/protobuf v1.29.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||||
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||||
google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM=
|
google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY=
|
||||||
google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
|
google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||||
|
|||||||
136
handler.go
136
handler.go
@@ -9,7 +9,6 @@ import (
|
|||||||
"slices"
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go.unistack.org/micro/v4/errors"
|
"go.unistack.org/micro/v4/errors"
|
||||||
@@ -46,7 +45,6 @@ type httpHandler struct {
|
|||||||
handlers *rhttp.Trie
|
handlers *rhttp.Trie
|
||||||
name string
|
name string
|
||||||
sopts server.Options
|
sopts server.Options
|
||||||
sync.RWMutex
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpHandler) Name() string {
|
func (h *httpHandler) Name() string {
|
||||||
@@ -103,8 +101,9 @@ func (h *Server) HTTPHandlerFunc(handler interface{}) (http.HandlerFunc, error)
|
|||||||
ct = htype
|
ct = htype
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := context.WithValue(r.Context(), rspCodeKey{}, &rspCodeVal{})
|
ctx := context.WithValue(r.Context(), rspStatusCodeKey{}, &rspStatusCodeVal{})
|
||||||
ctx = context.WithValue(ctx, rspHeaderKey{}, &rspHeaderVal{})
|
ctx = context.WithValue(ctx, rspMetadataKey{}, &rspMetadataVal{m: metadata.New(0)})
|
||||||
|
|
||||||
md, ok := metadata.FromIncomingContext(ctx)
|
md, ok := metadata.FromIncomingContext(ctx)
|
||||||
if !ok {
|
if !ok {
|
||||||
md = metadata.New(len(r.Header) + 8)
|
md = metadata.New(len(r.Header) + 8)
|
||||||
@@ -128,6 +127,7 @@ func (h *Server) HTTPHandlerFunc(handler interface{}) (http.HandlerFunc, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ctx = metadata.NewIncomingContext(ctx, md)
|
ctx = metadata.NewIncomingContext(ctx, md)
|
||||||
|
ctx = metadata.NewOutgoingContext(ctx, metadata.New(0))
|
||||||
|
|
||||||
path := r.URL.Path
|
path := r.URL.Path
|
||||||
|
|
||||||
@@ -159,22 +159,19 @@ func (h *Server) HTTPHandlerFunc(handler interface{}) (http.HandlerFunc, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !match && h.registerRPC {
|
if !match && h.registerRPC {
|
||||||
microMethod, mok := md.Get(metadata.HeaderEndpoint)
|
for _, microMethod := range md.Get(metadata.HeaderEndpoint) {
|
||||||
if mok {
|
serviceMethod := strings.Split(microMethod, ".")
|
||||||
for i := range microMethod {
|
if len(serviceMethod) == 2 {
|
||||||
serviceMethod := strings.Split(microMethod[i], ".")
|
if shdlr, ok := h.handlers[serviceMethod[0]]; ok {
|
||||||
if len(serviceMethod) == 2 {
|
hdlr := shdlr.(*httpHandler)
|
||||||
if shdlr, ok := h.handlers[serviceMethod[0]]; ok {
|
fh, mp, err := hdlr.handlers.Search(http.MethodPost, "/"+microMethod)
|
||||||
hdlr := shdlr.(*httpHandler)
|
if err == nil {
|
||||||
fh, mp, err := hdlr.handlers.Search(http.MethodPost, "/"+microMethod[i])
|
// match = true
|
||||||
if err == nil {
|
for k, v := range mp {
|
||||||
// match = true
|
matches[k] = v
|
||||||
for k, v := range mp {
|
|
||||||
matches[k] = v
|
|
||||||
}
|
|
||||||
hldr = fh.(*patHandler)
|
|
||||||
handler = hdlr
|
|
||||||
}
|
}
|
||||||
|
hldr = fh.(*patHandler)
|
||||||
|
handler = hdlr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -260,17 +257,6 @@ func (h *Server) HTTPHandlerFunc(handler interface{}) (http.HandlerFunc, error)
|
|||||||
err = rerr.(error)
|
err = rerr.(error)
|
||||||
}
|
}
|
||||||
|
|
||||||
md, ok := metadata.FromOutgoingContext(ctx)
|
|
||||||
if !ok {
|
|
||||||
md = metadata.New(0)
|
|
||||||
}
|
|
||||||
if nmd, ok := metadata.FromOutgoingContext(fctx); ok {
|
|
||||||
for k, v := range nmd {
|
|
||||||
md[k] = append(md[k], v...)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ctx = metadata.NewOutgoingContext(ctx, md)
|
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -294,19 +280,8 @@ func (h *Server) HTTPHandlerFunc(handler interface{}) (http.HandlerFunc, error)
|
|||||||
appErr := fn(ctx, hr, replyv.Interface())
|
appErr := fn(ctx, hr, replyv.Interface())
|
||||||
|
|
||||||
w.Header().Set(metadata.HeaderContentType, ct)
|
w.Header().Set(metadata.HeaderContentType, ct)
|
||||||
if md, ok := metadata.FromOutgoingContext(ctx); ok {
|
for k, v := range getResponseMetadata(ctx) {
|
||||||
for k, v := range md {
|
w.Header()[k] = v
|
||||||
for i := range v {
|
|
||||||
w.Header().Set(k, v[i])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if md := getRspHeader(ctx); md != nil {
|
|
||||||
for k, v := range md {
|
|
||||||
for _, vv := range v {
|
|
||||||
w.Header().Add(k, vv)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if nct := w.Header().Get(metadata.HeaderContentType); nct != ct {
|
if nct := w.Header().Get(metadata.HeaderContentType); nct != ct {
|
||||||
if cf, err = h.newCodec(nct); err != nil {
|
if cf, err = h.newCodec(nct); err != nil {
|
||||||
@@ -335,7 +310,7 @@ func (h *Server) HTTPHandlerFunc(handler interface{}) (http.HandlerFunc, error)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if nscode := GetRspCode(ctx); nscode != 0 {
|
if nscode := GetResponseStatusCode(ctx); nscode != 0 {
|
||||||
scode = nscode
|
scode = nscode
|
||||||
}
|
}
|
||||||
w.WriteHeader(scode)
|
w.WriteHeader(scode)
|
||||||
@@ -354,8 +329,8 @@ func (h *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
ts := time.Now()
|
ts := time.Now()
|
||||||
|
|
||||||
ctx := context.WithValue(r.Context(), rspCodeKey{}, &rspCodeVal{})
|
ctx := context.WithValue(r.Context(), rspStatusCodeKey{}, &rspStatusCodeVal{})
|
||||||
ctx = context.WithValue(ctx, rspHeaderKey{}, &rspHeaderVal{})
|
ctx = context.WithValue(ctx, rspMetadataKey{}, &rspMetadataVal{m: metadata.New(0)})
|
||||||
|
|
||||||
md, ok := metadata.FromIncomingContext(ctx)
|
md, ok := metadata.FromIncomingContext(ctx)
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -376,10 +351,11 @@ func (h *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
md["Proto"] = append(md["Proto"], r.Proto)
|
md["Proto"] = append(md["Proto"], r.Proto)
|
||||||
md["Content-Length"] = append(md["Content-Length"], fmt.Sprintf("%d", r.ContentLength))
|
md["Content-Length"] = append(md["Content-Length"], fmt.Sprintf("%d", r.ContentLength))
|
||||||
if len(r.TransferEncoding) > 0 {
|
if len(r.TransferEncoding) > 0 {
|
||||||
md["TransferEncoding"] = append(md["Content-Length"], r.TransferEncoding...)
|
md["Transfer-Encoding"] = append(md["Transfer-Encoding"], r.TransferEncoding...)
|
||||||
}
|
}
|
||||||
md["Host"] = append(md["Host"], r.Host)
|
md["Host"] = append(md["Host"], r.Host)
|
||||||
md["RequestURI"] = append(md["RequestURI"], r.RequestURI)
|
md["RequestURI"] = append(md["RequestURI"], r.RequestURI)
|
||||||
|
|
||||||
ctx = metadata.NewIncomingContext(ctx, md)
|
ctx = metadata.NewIncomingContext(ctx, md)
|
||||||
ctx = metadata.NewOutgoingContext(ctx, metadata.New(0))
|
ctx = metadata.NewOutgoingContext(ctx, metadata.New(0))
|
||||||
|
|
||||||
@@ -413,23 +389,21 @@ func (h *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !match && h.registerRPC {
|
if !match && h.registerRPC {
|
||||||
microMethod, mok := md.Get(metadata.HeaderEndpoint)
|
for _, microMethod := range md.Get(metadata.HeaderEndpoint) {
|
||||||
if mok {
|
serviceMethod := strings.Split(microMethod, ".")
|
||||||
for i := range microMethod {
|
if len(serviceMethod) == 2 {
|
||||||
serviceMethod := strings.Split(microMethod[i], ".")
|
if shdlr, ok := h.handlers[serviceMethod[0]]; ok {
|
||||||
if len(serviceMethod) == 2 {
|
hdlr := shdlr.(*httpHandler)
|
||||||
if shdlr, ok := h.handlers[serviceMethod[0]]; ok {
|
fh, mp, err := hdlr.handlers.Search(http.MethodPost, "/"+microMethod)
|
||||||
hdlr := shdlr.(*httpHandler)
|
if err == nil {
|
||||||
fh, mp, err := hdlr.handlers.Search(http.MethodPost, "/"+microMethod[i])
|
match = true
|
||||||
if err == nil {
|
for k, v := range mp {
|
||||||
match = true
|
matches[k] = v
|
||||||
for k, v := range mp {
|
|
||||||
matches[k] = v
|
|
||||||
}
|
|
||||||
hldr = fh.(*patHandler)
|
|
||||||
handler = hdlr
|
|
||||||
}
|
}
|
||||||
|
hldr = fh.(*patHandler)
|
||||||
|
handler = hdlr
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -447,7 +421,7 @@ func (h *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
defer func() {
|
defer func() {
|
||||||
n := GetRspCode(ctx)
|
n := GetResponseStatusCode(ctx)
|
||||||
if s, _ := sp.Status(); s != tracer.SpanStatusError && n > 399 {
|
if s, _ := sp.Status(); s != tracer.SpanStatusError && n > 399 {
|
||||||
sp.SetStatus(tracer.SpanStatusError, http.StatusText(n))
|
sp.SetStatus(tracer.SpanStatusError, http.StatusText(n))
|
||||||
}
|
}
|
||||||
@@ -459,7 +433,7 @@ func (h *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
h.opts.Meter.Counter(semconv.ServerRequestInflight, "endpoint", endpointName, "server", "http").Inc()
|
h.opts.Meter.Counter(semconv.ServerRequestInflight, "endpoint", endpointName, "server", "http").Inc()
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
n := GetRspCode(ctx)
|
n := GetResponseStatusCode(ctx)
|
||||||
if n > 399 {
|
if n > 399 {
|
||||||
h.opts.Meter.Counter(semconv.ServerRequestTotal, "endpoint", endpointName, "server", "http", "status", "success", "code", strconv.Itoa(n)).Inc()
|
h.opts.Meter.Counter(semconv.ServerRequestTotal, "endpoint", endpointName, "server", "http", "status", "success", "code", strconv.Itoa(n)).Inc()
|
||||||
} else {
|
} else {
|
||||||
@@ -487,7 +461,7 @@ func (h *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if n := GetRspCode(ctx); n > 399 {
|
if n := GetResponseStatusCode(ctx); n > 399 {
|
||||||
sp.SetStatus(tracer.SpanStatusError, http.StatusText(n))
|
sp.SetStatus(tracer.SpanStatusError, http.StatusText(n))
|
||||||
} else {
|
} else {
|
||||||
sp.SetStatus(tracer.SpanStatusError, http.StatusText(http.StatusNotFound))
|
sp.SetStatus(tracer.SpanStatusError, http.StatusText(http.StatusNotFound))
|
||||||
@@ -526,7 +500,7 @@ func (h *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
h.opts.Meter.Histogram(semconv.ServerRequestDurationSeconds, "endpoint", handler.name, "server", "http").Update(te.Seconds())
|
h.opts.Meter.Histogram(semconv.ServerRequestDurationSeconds, "endpoint", handler.name, "server", "http").Update(te.Seconds())
|
||||||
h.opts.Meter.Counter(semconv.ServerRequestInflight, "endpoint", handler.name, "server", "http").Dec()
|
h.opts.Meter.Counter(semconv.ServerRequestInflight, "endpoint", handler.name, "server", "http").Dec()
|
||||||
|
|
||||||
n := GetRspCode(ctx)
|
n := GetResponseStatusCode(ctx)
|
||||||
if n > 399 {
|
if n > 399 {
|
||||||
h.opts.Meter.Counter(semconv.ServerRequestTotal, "endpoint", handler.name, "server", "http", "status", "failure", "code", strconv.Itoa(n)).Inc()
|
h.opts.Meter.Counter(semconv.ServerRequestTotal, "endpoint", handler.name, "server", "http", "status", "failure", "code", strconv.Itoa(n)).Inc()
|
||||||
} else {
|
} else {
|
||||||
@@ -536,7 +510,7 @@ func (h *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
n := GetRspCode(ctx)
|
n := GetResponseStatusCode(ctx)
|
||||||
if n > 399 {
|
if n > 399 {
|
||||||
if s, _ := sp.Status(); s != tracer.SpanStatusError {
|
if s, _ := sp.Status(); s != tracer.SpanStatusError {
|
||||||
sp.SetStatus(tracer.SpanStatusError, http.StatusText(n))
|
sp.SetStatus(tracer.SpanStatusError, http.StatusText(n))
|
||||||
@@ -630,17 +604,6 @@ func (h *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
err = rerr.(error)
|
err = rerr.(error)
|
||||||
}
|
}
|
||||||
|
|
||||||
md, ok := metadata.FromOutgoingContext(ctx)
|
|
||||||
if !ok {
|
|
||||||
md = metadata.New(0)
|
|
||||||
}
|
|
||||||
if nmd, ok := metadata.FromOutgoingContext(fctx); ok {
|
|
||||||
for k, v := range nmd {
|
|
||||||
md[k] = append(md[k], v...)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ctx = metadata.NewOutgoingContext(ctx, md)
|
|
||||||
|
|
||||||
if err != nil && sp != nil {
|
if err != nil && sp != nil {
|
||||||
sp.SetStatus(tracer.SpanStatusError, err.Error())
|
sp.SetStatus(tracer.SpanStatusError, err.Error())
|
||||||
}
|
}
|
||||||
@@ -667,19 +630,8 @@ func (h *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
appErr := fn(ctx, hr, replyv.Interface())
|
appErr := fn(ctx, hr, replyv.Interface())
|
||||||
|
|
||||||
w.Header().Set(metadata.HeaderContentType, ct)
|
w.Header().Set(metadata.HeaderContentType, ct)
|
||||||
if md, ok := metadata.FromOutgoingContext(ctx); ok {
|
for k, v := range getResponseMetadata(ctx) {
|
||||||
for k, v := range md {
|
w.Header()[k] = v
|
||||||
for i := range v {
|
|
||||||
w.Header().Set(k, v[i])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if md := getRspHeader(ctx); md != nil {
|
|
||||||
for k, v := range md {
|
|
||||||
for _, vv := range v {
|
|
||||||
w.Header().Add(k, vv)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if nct := w.Header().Get(metadata.HeaderContentType); nct != ct {
|
if nct := w.Header().Get(metadata.HeaderContentType); nct != ct {
|
||||||
if cf, err = h.newCodec(nct); err != nil {
|
if cf, err = h.newCodec(nct); err != nil {
|
||||||
@@ -708,7 +660,7 @@ func (h *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
handler.sopts.Logger.Error(handler.sopts.Context, "handler error", err)
|
handler.sopts.Logger.Error(handler.sopts.Context, "handler error", err)
|
||||||
}
|
}
|
||||||
scode = http.StatusInternalServerError
|
scode = http.StatusInternalServerError
|
||||||
} else if nscode := GetRspCode(ctx); nscode != 0 {
|
} else if nscode := GetResponseStatusCode(ctx); nscode != 0 {
|
||||||
scode = nscode
|
scode = nscode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,11 +4,14 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
http "net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
codecpb "go.unistack.org/micro-proto/v4/codec"
|
codecpb "go.unistack.org/micro-proto/v4/codec"
|
||||||
|
httpsrv "go.unistack.org/micro-server-http/v4"
|
||||||
"go.unistack.org/micro/v4/logger"
|
"go.unistack.org/micro/v4/logger"
|
||||||
"go.unistack.org/micro/v4/metadata"
|
"go.unistack.org/micro/v4/metadata"
|
||||||
"go.unistack.org/micro/v4/meter"
|
"go.unistack.org/micro/v4/meter"
|
||||||
@@ -84,34 +87,85 @@ func NewHandler(opts ...Option) *Handler {
|
|||||||
return &Handler{Options: options}
|
return &Handler{Options: options}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handler) Metrics(ctx context.Context, req *codecpb.Frame, rsp *codecpb.Frame) error {
|
func (h *Handler) HTTPHandlerFunc(w http.ResponseWriter, r *http.Request) {
|
||||||
log, ok := logger.FromContext(ctx)
|
var wr io.Writer
|
||||||
if !ok {
|
if v := r.Header.Get(acceptEncodingHeader); strings.Contains(v, "gzip") && !h.Options.DisableCompress {
|
||||||
log = logger.DefaultLogger
|
w.Header().Add(contentEncodingHeader, "gzip")
|
||||||
}
|
|
||||||
|
|
||||||
buf := bufPool.Get().(*bytes.Buffer)
|
|
||||||
defer bufPool.Put(buf)
|
|
||||||
buf.Reset()
|
|
||||||
|
|
||||||
w := io.Writer(buf)
|
|
||||||
|
|
||||||
if md, ok := metadata.FromOutgoingContext(ctx); gzipAccepted(md) && ok && !h.Options.DisableCompress {
|
|
||||||
omd, _ := metadata.FromOutgoingContext(ctx)
|
|
||||||
omd.Set(contentEncodingHeader, "gzip")
|
|
||||||
gz := gzipPool.Get().(*gzip.Writer)
|
gz := gzipPool.Get().(*gzip.Writer)
|
||||||
defer gzipPool.Put(gz)
|
defer gzipPool.Put(gz)
|
||||||
|
|
||||||
gz.Reset(w)
|
gz.Reset(w)
|
||||||
defer gz.Close()
|
defer gz.Close()
|
||||||
|
|
||||||
w = gz
|
wr = gz
|
||||||
gz.Flush()
|
} else {
|
||||||
|
wr = w
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := h.Options.Meter.Write(w, h.Options.MeterOptions...); err != nil {
|
if err := h.Options.Meter.Write(wr, h.Options.MeterOptions...); err != nil {
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// gz.Flush() must be called after writing metrics to ensure buffered data is written to the underlying writer.
|
||||||
|
if gz, ok := wr.(*gzip.Writer); ok {
|
||||||
|
gz.Flush()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *Handler) Metrics(ctx context.Context, req *codecpb.Frame, rsp *codecpb.Frame) error {
|
||||||
|
log, ok := logger.FromContext(ctx)
|
||||||
|
if !ok {
|
||||||
|
log = logger.DefaultLogger
|
||||||
|
}
|
||||||
|
|
||||||
|
var err error
|
||||||
|
|
||||||
|
if md, ok := metadata.FromIncomingContext(ctx); ok && gzipAccepted(md) && !h.Options.DisableCompress {
|
||||||
|
err = h.writeMetricsGzip(ctx, rsp)
|
||||||
|
} else {
|
||||||
|
err = h.writeMetricsPlain(ctx, rsp)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
log.Error(ctx, "http/meter write failed", err)
|
log.Error(ctx, "http/meter write failed", err)
|
||||||
return nil
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *Handler) writeMetricsGzip(ctx context.Context, rsp *codecpb.Frame) error {
|
||||||
|
httpsrv.AppendResponseMetadata(ctx, metadata.Pairs(contentEncodingHeader, "gzip"))
|
||||||
|
|
||||||
|
buf := bufPool.Get().(*bytes.Buffer)
|
||||||
|
defer bufPool.Put(buf)
|
||||||
|
buf.Reset()
|
||||||
|
|
||||||
|
gz := gzipPool.Get().(*gzip.Writer)
|
||||||
|
defer gzipPool.Put(gz)
|
||||||
|
gz.Reset(buf)
|
||||||
|
|
||||||
|
if err := h.Options.Meter.Write(gz, h.Options.MeterOptions...); err != nil {
|
||||||
|
return fmt.Errorf("meter write: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := gz.Close(); err != nil {
|
||||||
|
return fmt.Errorf("gzip close: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
rsp.Data = buf.Bytes()
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *Handler) writeMetricsPlain(_ context.Context, rsp *codecpb.Frame) error {
|
||||||
|
buf := bufPool.Get().(*bytes.Buffer)
|
||||||
|
defer bufPool.Put(buf)
|
||||||
|
buf.Reset()
|
||||||
|
|
||||||
|
if err := h.Options.Meter.Write(buf, h.Options.MeterOptions...); err != nil {
|
||||||
|
return fmt.Errorf("meter write: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
rsp.Data = buf.Bytes()
|
rsp.Data = buf.Bytes()
|
||||||
@@ -121,15 +175,7 @@ func (h *Handler) Metrics(ctx context.Context, req *codecpb.Frame, rsp *codecpb.
|
|||||||
|
|
||||||
// gzipAccepted returns whether the client will accept gzip-encoded content.
|
// gzipAccepted returns whether the client will accept gzip-encoded content.
|
||||||
func gzipAccepted(md metadata.Metadata) bool {
|
func gzipAccepted(md metadata.Metadata) bool {
|
||||||
a, ok := md.Get(acceptEncodingHeader)
|
a := md.GetJoined(acceptEncodingHeader)
|
||||||
if !ok {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
for i := range a {
|
|
||||||
if strings.Contains(a[i], "gzip") {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
return strings.Contains(a, "gzip")
|
||||||
}
|
}
|
||||||
|
|||||||
84
http.go
84
http.go
@@ -36,18 +36,18 @@ type Server struct {
|
|||||||
stateReady *atomic.Uint32
|
stateReady *atomic.Uint32
|
||||||
stateHealth *atomic.Uint32
|
stateHealth *atomic.Uint32
|
||||||
registerRPC bool
|
registerRPC bool
|
||||||
sync.RWMutex
|
mu sync.RWMutex
|
||||||
registered bool
|
registered bool
|
||||||
init bool
|
init bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Server) newCodec(ct string) (codec.Codec, error) {
|
func (h *Server) newCodec(ct string) (codec.Codec, error) {
|
||||||
if idx := strings.IndexRune(ct, ';'); idx >= 0 {
|
if idx := strings.IndexRune(ct, ';'); idx >= 0 {
|
||||||
ct = ct[:idx]
|
ct = ct[:idx]
|
||||||
}
|
}
|
||||||
h.RLock()
|
h.mu.RLock()
|
||||||
cf, ok := h.opts.Codecs[ct]
|
cf, ok := h.opts.Codecs[ct]
|
||||||
h.RUnlock()
|
h.mu.RUnlock()
|
||||||
if ok {
|
if ok {
|
||||||
return cf, nil
|
return cf, nil
|
||||||
}
|
}
|
||||||
@@ -55,9 +55,9 @@ func (h *Server) newCodec(ct string) (codec.Codec, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *Server) Options() server.Options {
|
func (h *Server) Options() server.Options {
|
||||||
h.Lock()
|
h.mu.Lock()
|
||||||
opts := h.opts
|
opts := h.opts
|
||||||
h.Unlock()
|
h.mu.Unlock()
|
||||||
return opts
|
return opts
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ func (h *Server) Init(opts ...server.Option) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
h.Lock()
|
h.mu.Lock()
|
||||||
|
|
||||||
for _, o := range opts {
|
for _, o := range opts {
|
||||||
o(&h.opts)
|
o(&h.opts)
|
||||||
@@ -89,41 +89,41 @@ func (h *Server) Init(opts ...server.Option) error {
|
|||||||
for pm, ps := range phs.h {
|
for pm, ps := range phs.h {
|
||||||
for pp, ph := range ps {
|
for pp, ph := range ps {
|
||||||
if err := h.pathHandlers.Insert([]string{pm}, pp, ph); err != nil {
|
if err := h.pathHandlers.Insert([]string{pm}, pp, ph); err != nil {
|
||||||
h.Unlock()
|
h.mu.Unlock()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
h.Unlock()
|
h.mu.Unlock()
|
||||||
|
|
||||||
h.RLock()
|
h.mu.RLock()
|
||||||
if err := h.opts.Register.Init(); err != nil {
|
if err := h.opts.Register.Init(); err != nil {
|
||||||
h.RUnlock()
|
h.mu.RUnlock()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := h.opts.Broker.Init(); err != nil {
|
if err := h.opts.Broker.Init(); err != nil {
|
||||||
h.RUnlock()
|
h.mu.RUnlock()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := h.opts.Tracer.Init(); err != nil {
|
if err := h.opts.Tracer.Init(); err != nil {
|
||||||
h.RUnlock()
|
h.mu.RUnlock()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := h.opts.Logger.Init(); err != nil {
|
if err := h.opts.Logger.Init(); err != nil {
|
||||||
h.RUnlock()
|
h.mu.RUnlock()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := h.opts.Meter.Init(); err != nil {
|
if err := h.opts.Meter.Init(); err != nil {
|
||||||
h.RUnlock()
|
h.mu.RUnlock()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
h.RUnlock()
|
h.mu.RUnlock()
|
||||||
|
|
||||||
h.Lock()
|
h.mu.Lock()
|
||||||
h.init = true
|
h.init = true
|
||||||
h.Unlock()
|
h.mu.Unlock()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -132,27 +132,27 @@ func (h *Server) Handle(handler server.Handler) error {
|
|||||||
// passed unknown handler
|
// passed unknown handler
|
||||||
hdlr, ok := handler.(*httpHandler)
|
hdlr, ok := handler.(*httpHandler)
|
||||||
if !ok {
|
if !ok {
|
||||||
h.Lock()
|
h.mu.Lock()
|
||||||
h.hd = handler
|
h.hd = handler
|
||||||
h.Unlock()
|
h.mu.Unlock()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// passed http.Handler like some muxer
|
// passed http.Handler like some muxer
|
||||||
if _, ok := hdlr.hd.(http.Handler); ok {
|
if _, ok := hdlr.hd.(http.Handler); ok {
|
||||||
h.Lock()
|
h.mu.Lock()
|
||||||
h.hd = handler
|
h.hd = handler
|
||||||
h.Unlock()
|
h.mu.Unlock()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// passed micro compat handler
|
// passed micro compat handler
|
||||||
h.Lock()
|
h.mu.Lock()
|
||||||
if h.handlers == nil {
|
if h.handlers == nil {
|
||||||
h.handlers = make(map[string]server.Handler)
|
h.handlers = make(map[string]server.Handler)
|
||||||
}
|
}
|
||||||
h.handlers[handler.Name()] = handler
|
h.handlers[handler.Name()] = handler
|
||||||
h.Unlock()
|
h.mu.Unlock()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -294,10 +294,10 @@ func (h *Server) NewHandler(handler interface{}, opts ...server.HandlerOption) s
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *Server) Register() error {
|
func (h *Server) Register() error {
|
||||||
h.RLock()
|
h.mu.RLock()
|
||||||
rsvc := h.rsvc
|
rsvc := h.rsvc
|
||||||
config := h.opts
|
config := h.opts
|
||||||
h.RUnlock()
|
h.mu.RUnlock()
|
||||||
|
|
||||||
// if service already filled, reuse it and return early
|
// if service already filled, reuse it and return early
|
||||||
if rsvc != nil {
|
if rsvc != nil {
|
||||||
@@ -312,9 +312,9 @@ func (h *Server) Register() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
h.RLock()
|
h.mu.RLock()
|
||||||
registered := h.registered
|
registered := h.registered
|
||||||
h.RUnlock()
|
h.mu.RUnlock()
|
||||||
|
|
||||||
if !registered {
|
if !registered {
|
||||||
if config.Logger.V(logger.InfoLevel) {
|
if config.Logger.V(logger.InfoLevel) {
|
||||||
@@ -332,19 +332,19 @@ func (h *Server) Register() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
h.Lock()
|
h.mu.Lock()
|
||||||
|
|
||||||
h.registered = true
|
h.registered = true
|
||||||
h.rsvc = service
|
h.rsvc = service
|
||||||
h.Unlock()
|
h.mu.Unlock()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Server) Deregister() error {
|
func (h *Server) Deregister() error {
|
||||||
h.RLock()
|
h.mu.RLock()
|
||||||
config := h.opts
|
config := h.opts
|
||||||
h.RUnlock()
|
h.mu.RUnlock()
|
||||||
|
|
||||||
service, err := server.NewRegisterService(h)
|
service, err := server.NewRegisterService(h)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -359,24 +359,24 @@ func (h *Server) Deregister() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
h.Lock()
|
h.mu.Lock()
|
||||||
h.rsvc = nil
|
h.rsvc = nil
|
||||||
|
|
||||||
if !h.registered {
|
if !h.registered {
|
||||||
h.Unlock()
|
h.mu.Unlock()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
h.registered = false
|
h.registered = false
|
||||||
|
|
||||||
h.Unlock()
|
h.mu.Unlock()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Server) Start() error {
|
func (h *Server) Start() error {
|
||||||
h.RLock()
|
h.mu.RLock()
|
||||||
config := h.opts
|
config := h.opts
|
||||||
h.RUnlock()
|
h.mu.RUnlock()
|
||||||
|
|
||||||
// micro: config.Transport.Listen(config.Address)
|
// micro: config.Transport.Listen(config.Address)
|
||||||
var ts net.Listener
|
var ts net.Listener
|
||||||
@@ -406,9 +406,9 @@ func (h *Server) Start() error {
|
|||||||
config.Logger.Info(config.Context, "Listening on "+ts.Addr().String())
|
config.Logger.Info(config.Context, "Listening on "+ts.Addr().String())
|
||||||
}
|
}
|
||||||
|
|
||||||
h.Lock()
|
h.mu.Lock()
|
||||||
h.opts.Address = ts.Addr().String()
|
h.opts.Address = ts.Addr().String()
|
||||||
h.Unlock()
|
h.mu.Unlock()
|
||||||
|
|
||||||
var handler http.Handler
|
var handler http.Handler
|
||||||
|
|
||||||
@@ -499,9 +499,9 @@ func (h *Server) Start() error {
|
|||||||
select {
|
select {
|
||||||
// register self on interval
|
// register self on interval
|
||||||
case <-t.C:
|
case <-t.C:
|
||||||
h.RLock()
|
h.mu.RLock()
|
||||||
registered := h.registered
|
registered := h.registered
|
||||||
h.RUnlock()
|
h.mu.RUnlock()
|
||||||
rerr := config.RegisterCheck(h.opts.Context)
|
rerr := config.RegisterCheck(h.opts.Context)
|
||||||
// nolint: nestif
|
// nolint: nestif
|
||||||
if rerr != nil && registered {
|
if rerr != nil && registered {
|
||||||
|
|||||||
47
metadata.go
Normal file
47
metadata.go
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
package http
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"go.unistack.org/micro/v4/metadata"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
rspMetadataKey struct{}
|
||||||
|
rspMetadataVal struct {
|
||||||
|
m metadata.Metadata
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// AppendResponseMetadata adds metadata entries to metadata.Metadata stored in the context.
|
||||||
|
// It expects the context to contain a *rspMetadataVal value under the rspMetadataKey{} key.
|
||||||
|
// If the value is missing or invalid, the function does nothing.
|
||||||
|
//
|
||||||
|
// Note: this function is not thread-safe. Synchronization is required if used from multiple goroutines.
|
||||||
|
func AppendResponseMetadata(ctx context.Context, md metadata.Metadata) {
|
||||||
|
if md == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val, ok := ctx.Value(rspMetadataKey{}).(*rspMetadataVal)
|
||||||
|
if !ok || val == nil || val.m == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for key, values := range md {
|
||||||
|
val.m.Append(key, values...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// getResponseMetadata retrieves the metadata.Metadata stored in the context.
|
||||||
|
//
|
||||||
|
// Note: this function is not thread-safe. Synchronization is required if used from multiple goroutines.
|
||||||
|
// If you plan to modify the returned metadata, make a full copy to avoid affecting shared state.
|
||||||
|
func getResponseMetadata(ctx context.Context) metadata.Metadata {
|
||||||
|
val, ok := ctx.Value(rspMetadataKey{}).(*rspMetadataVal)
|
||||||
|
if !ok || val == nil || val.m == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return val.m
|
||||||
|
}
|
||||||
136
metadata_test.go
Normal file
136
metadata_test.go
Normal file
@@ -0,0 +1,136 @@
|
|||||||
|
package http
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
"go.unistack.org/micro/v4/metadata"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestAppendResponseMetadata(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
ctx context.Context
|
||||||
|
md metadata.Metadata
|
||||||
|
expected context.Context
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "nil metadata",
|
||||||
|
ctx: context.WithValue(context.Background(), rspMetadataKey{}, &rspMetadataVal{m: metadata.Metadata{}}),
|
||||||
|
md: nil,
|
||||||
|
expected: context.WithValue(context.Background(), rspMetadataKey{}, &rspMetadataVal{m: metadata.Metadata{}}),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "empty metadata",
|
||||||
|
ctx: context.WithValue(context.Background(), rspMetadataKey{}, &rspMetadataVal{m: metadata.Metadata{}}),
|
||||||
|
md: metadata.Metadata{},
|
||||||
|
expected: context.WithValue(context.Background(), rspMetadataKey{}, &rspMetadataVal{m: metadata.Metadata{}}),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "context without response metadata key",
|
||||||
|
ctx: context.Background(),
|
||||||
|
md: metadata.Pairs("key1", "val1"),
|
||||||
|
expected: context.Background(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "context with nil response metadata value",
|
||||||
|
ctx: context.WithValue(context.Background(), rspMetadataKey{}, nil),
|
||||||
|
md: metadata.Pairs("key1", "val1"),
|
||||||
|
expected: context.WithValue(context.Background(), rspMetadataKey{}, nil),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "context with incorrect type in response metadata value",
|
||||||
|
ctx: context.WithValue(context.Background(), rspMetadataKey{}, struct{}{}),
|
||||||
|
md: metadata.Pairs("key1", "val1"),
|
||||||
|
expected: context.WithValue(context.Background(), rspMetadataKey{}, struct{}{}),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "context with response metadata value, but nil metadata",
|
||||||
|
ctx: context.WithValue(context.Background(), rspMetadataKey{}, &rspMetadataVal{m: nil}),
|
||||||
|
md: metadata.Pairs("key1", "val1"),
|
||||||
|
expected: context.WithValue(context.Background(), rspMetadataKey{}, &rspMetadataVal{m: nil}),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "basic metadata append",
|
||||||
|
ctx: context.WithValue(context.Background(), rspMetadataKey{}, &rspMetadataVal{m: metadata.Metadata{}}),
|
||||||
|
md: metadata.Pairs("key1", "val1"),
|
||||||
|
expected: context.WithValue(context.Background(), rspMetadataKey{}, &rspMetadataVal{
|
||||||
|
m: metadata.Metadata{
|
||||||
|
"key1": []string{"val1"},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "multiple values for same key",
|
||||||
|
ctx: context.WithValue(context.Background(), rspMetadataKey{}, &rspMetadataVal{m: metadata.Metadata{}}),
|
||||||
|
md: metadata.Pairs("key1", "val1", "key1", "val2"),
|
||||||
|
expected: context.WithValue(context.Background(), rspMetadataKey{}, &rspMetadataVal{
|
||||||
|
m: metadata.Metadata{
|
||||||
|
"key1": []string{"val1", "val2"},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "multiple values for different keys",
|
||||||
|
ctx: context.WithValue(context.Background(), rspMetadataKey{}, &rspMetadataVal{m: metadata.Metadata{}}),
|
||||||
|
md: metadata.Pairs("key1", "val1", "key1", "val2", "key2", "val3", "key2", "val4", "key3", "val5"),
|
||||||
|
expected: context.WithValue(context.Background(), rspMetadataKey{}, &rspMetadataVal{
|
||||||
|
m: metadata.Metadata{
|
||||||
|
"key1": []string{"val1", "val2"},
|
||||||
|
"key2": []string{"val3", "val4"},
|
||||||
|
"key3": []string{"val5"},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
AppendResponseMetadata(tt.ctx, tt.md)
|
||||||
|
require.Equal(t, tt.expected, tt.ctx)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetResponseMetadata(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
ctx context.Context
|
||||||
|
expected metadata.Metadata
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "context without response metadata key",
|
||||||
|
ctx: context.Background(),
|
||||||
|
expected: nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "context with nil response metadata value",
|
||||||
|
ctx: context.WithValue(context.Background(), rspMetadataKey{}, nil),
|
||||||
|
expected: nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "context with incorrect type in response metadata value",
|
||||||
|
ctx: context.WithValue(context.Background(), rspMetadataKey{}, &struct{}{}),
|
||||||
|
expected: nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "context with response metadata value, but nil metadata",
|
||||||
|
ctx: context.WithValue(context.Background(), rspMetadataKey{}, &rspMetadataVal{m: nil}),
|
||||||
|
expected: nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "valid metadata",
|
||||||
|
ctx: context.WithValue(context.Background(), rspMetadataKey{}, &rspMetadataVal{
|
||||||
|
m: metadata.Pairs("key1", "value1"),
|
||||||
|
}),
|
||||||
|
expected: metadata.Metadata{"key1": {"value1"}},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
require.Equal(t, tt.expected, getResponseMetadata(tt.ctx))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
45
options.go
45
options.go
@@ -31,51 +31,6 @@ func (err *Error) Error() string {
|
|||||||
return fmt.Sprintf("%v", err.err)
|
return fmt.Sprintf("%v", err.err)
|
||||||
}
|
}
|
||||||
|
|
||||||
type (
|
|
||||||
rspCodeKey struct{}
|
|
||||||
rspCodeVal struct {
|
|
||||||
code int
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
type (
|
|
||||||
rspHeaderKey struct{}
|
|
||||||
rspHeaderVal struct {
|
|
||||||
h http.Header
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
// SetRspHeader add response headers
|
|
||||||
func SetRspHeader(ctx context.Context, h http.Header) {
|
|
||||||
if rsp, ok := ctx.Value(rspHeaderKey{}).(*rspHeaderVal); ok {
|
|
||||||
rsp.h = h
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetRspCode saves response code in context, must be used by handler to specify http code
|
|
||||||
func SetRspCode(ctx context.Context, code int) {
|
|
||||||
if rsp, ok := ctx.Value(rspCodeKey{}).(*rspCodeVal); ok {
|
|
||||||
rsp.code = code
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// getRspHeader get http.Header from context
|
|
||||||
func getRspHeader(ctx context.Context) http.Header {
|
|
||||||
if rsp, ok := ctx.Value(rspHeaderKey{}).(*rspHeaderVal); ok {
|
|
||||||
return rsp.h
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetRspCode used internally by generated http server handler
|
|
||||||
func GetRspCode(ctx context.Context) int {
|
|
||||||
code := int(200)
|
|
||||||
if rsp, ok := ctx.Value(rspCodeKey{}).(*rspCodeVal); ok {
|
|
||||||
code = rsp.code
|
|
||||||
}
|
|
||||||
return code
|
|
||||||
}
|
|
||||||
|
|
||||||
type middlewareKey struct{}
|
type middlewareKey struct{}
|
||||||
|
|
||||||
// Middleware passes http middlewares
|
// Middleware passes http middlewares
|
||||||
|
|||||||
29
response.go
Normal file
29
response.go
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
package http
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
rspStatusCodeKey struct{}
|
||||||
|
rspStatusCodeVal struct {
|
||||||
|
code int
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// SetResponseStatusCode sets the status code in the context.
|
||||||
|
func SetResponseStatusCode(ctx context.Context, code int) {
|
||||||
|
if rsp, ok := ctx.Value(rspStatusCodeKey{}).(*rspStatusCodeVal); ok {
|
||||||
|
rsp.code = code
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetResponseStatusCode retrieves the response status code from the context.
|
||||||
|
func GetResponseStatusCode(ctx context.Context) int {
|
||||||
|
code := http.StatusOK
|
||||||
|
if rsp, ok := ctx.Value(rspStatusCodeKey{}).(*rspStatusCodeVal); ok {
|
||||||
|
code = rsp.code
|
||||||
|
}
|
||||||
|
return code
|
||||||
|
}
|
||||||
79
response_test.go
Normal file
79
response_test.go
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
package http
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSetResponseStatusCode(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
ctx context.Context
|
||||||
|
code int
|
||||||
|
expected context.Context
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "context without response status code key",
|
||||||
|
ctx: context.Background(),
|
||||||
|
code: http.StatusOK,
|
||||||
|
expected: context.Background(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "context with incorrect type in response status code value",
|
||||||
|
ctx: context.WithValue(context.Background(), rspStatusCodeKey{}, struct{}{}),
|
||||||
|
code: http.StatusOK,
|
||||||
|
expected: context.WithValue(context.Background(), rspStatusCodeKey{}, struct{}{}),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "successfully set response status code",
|
||||||
|
ctx: context.WithValue(context.Background(), rspStatusCodeKey{}, &rspStatusCodeVal{}),
|
||||||
|
code: http.StatusOK,
|
||||||
|
expected: context.WithValue(context.Background(), rspStatusCodeKey{}, &rspStatusCodeVal{code: http.StatusOK}),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
SetResponseStatusCode(tt.ctx, tt.code)
|
||||||
|
require.Equal(t, tt.expected, tt.ctx)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetResponseStatusCode(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
ctx context.Context
|
||||||
|
expected int
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "no value in context, should return 200",
|
||||||
|
ctx: context.Background(),
|
||||||
|
expected: http.StatusOK,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "context with nil value",
|
||||||
|
ctx: context.WithValue(context.Background(), rspStatusCodeKey{}, nil),
|
||||||
|
expected: http.StatusOK,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "context with wrong type",
|
||||||
|
ctx: context.WithValue(context.Background(), rspStatusCodeKey{}, struct{}{}),
|
||||||
|
expected: http.StatusOK,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "context with valid status code",
|
||||||
|
ctx: context.WithValue(context.Background(), rspStatusCodeKey{}, &rspStatusCodeVal{code: http.StatusNotFound}),
|
||||||
|
expected: http.StatusNotFound,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
require.Equal(t, tt.expected, GetResponseStatusCode(tt.ctx))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
6
util.go
6
util.go
@@ -23,8 +23,8 @@ func FillRequest(ctx context.Context, req interface{}, opts ...FillRequestOption
|
|||||||
|
|
||||||
for idx := 0; idx < len(options.headers)/2; idx += 2 {
|
for idx := 0; idx < len(options.headers)/2; idx += 2 {
|
||||||
k := options.headers[idx]
|
k := options.headers[idx]
|
||||||
v, ok := md.Get(k)
|
v := md.Get(k)
|
||||||
if !ok {
|
if v == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,7 +38,7 @@ func FillRequest(ctx context.Context, req interface{}, opts ...FillRequestOption
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cookieVals, _ := md.Get("Cookie")
|
cookieVals := md.Get("Cookie")
|
||||||
for i := range cookieVals {
|
for i := range cookieVals {
|
||||||
cookies := strings.Split(cookieVals[i], ";")
|
cookies := strings.Split(cookieVals[i], ";")
|
||||||
cmd := make(map[string]string, len(cookies))
|
cmd := make(map[string]string, len(cookies))
|
||||||
|
|||||||
Reference in New Issue
Block a user