Compare commits
206 Commits
Author | SHA1 | Date | |
---|---|---|---|
52bbed93c4 | |||
0706a76f3c | |||
841f688ce6 | |||
be904bc534 | |||
b23469853f | |||
afebe71814 | |||
0e122ca5e3 | |||
be7e042282 | |||
ab7da93001 | |||
75437a46c8 | |||
cee07d11d4 | |||
d5360e2804 | |||
2d23f347eb | |||
78664a34ed | |||
bec0e310e9 | |||
92436e9016 | |||
25618a3859 | |||
b22f150601 | |||
71bcb63b60 | |||
698bfbc6f1 | |||
209042de3a | |||
990685628d | |||
0f8ead6acc | |||
2fbcee7b59 | |||
19a469c4e2 | |||
2a6a93a792 | |||
2adba9d0da | |||
9d70c4dd34 | |||
b9704903f2 | |||
4eda58e404 | |||
0f8d0a1123 | |||
603b855e2a | |||
f2cfd562c3 | |||
781cf3d719 | |||
1b65507fe5 | |||
40b5402aa5 | |||
|
e8b7e30e4d | ||
55e7e3d61d | |||
|
d75c36938a | ||
a7cec360e9 | |||
|
3978256931 | ||
6dfff28203 | |||
|
373acda151 | ||
3f9ed4e83b | |||
|
0486780f36 | ||
36788b5fbf | |||
|
c79b83a3c1 | ||
a6585fd6d4 | |||
|
7fce5ccad9 | ||
b5a5e98f9e | |||
|
e419c6a67c | ||
17c46e63a2 | |||
|
cdf1a2c3e3 | ||
aba3df63df | |||
|
337df46029 | ||
bfe4839a00 | |||
|
5474c37f8f | ||
ba88a5568a | |||
|
57f903a8c2 | ||
9f918bd3f2 | |||
|
0d88050daf | ||
|
d1ed5bed51 | ||
|
42697318b1 | ||
28aea45725 | |||
|
ed72c05645 | ||
|
d239dcde63 | ||
6eb07dc351 | |||
|
a0d704f845 | ||
4b8a761f30 | |||
|
a2c711a1b5 | ||
be564f50aa | |||
|
b7b1eff81c | ||
671a6b6f7c | |||
27c1c4d86b | |||
76d37a99eb | |||
|
4c2827172f | ||
e3461dd23f | |||
|
d8b5c011e5 | ||
|
15abd38afd | ||
5865a0f388 | |||
|
67da8d1165 | ||
|
c7d24caa03 | ||
8c222c4715 | |||
6e91cd5cf5 | |||
a9e673b2ef | |||
251f06cc31 | |||
e97e4580a1 | |||
bd7dbe94ca | |||
|
0f32fad4c0 | ||
|
858111106e | ||
|
dc35dc6d3e | ||
|
24b1abfb9a | ||
|
205fd53047 | ||
|
b3b7d1af13 | ||
80e2184bba | |||
|
a920d15d95 | ||
5ecbfac164 | |||
|
61d7a322de | ||
|
b43c207f6a | ||
|
d243b884c7 | ||
107b470b9a | |||
|
878bac53ac | ||
e28c584056 | |||
b8dc821784 | |||
|
907d2591df | ||
|
8cc656eec7 | ||
|
5792434604 | ||
402ccee5b9 | |||
|
90986a26e2 | ||
6d41afd5a0 | |||
2e645748bb | |||
f6b1c8d745 | |||
ea503d0583 | |||
048773c669 | |||
|
e3cb87ffe3 | ||
b1af43c4b0 | |||
|
f994df9e04 | ||
c556f7157f | |||
|
17be582d19 | ||
131a150d3d | |||
|
7f874a286e | ||
2f40797303 | |||
|
3e1b2b7c5d | ||
6442f4c474 | |||
|
1dda7e6b83 | ||
2b85cabe1f | |||
02895dd712 | |||
42b93ce57e | |||
763c299ab7 | |||
|
937a6d62b2 | ||
fb6e2c8845 | |||
3e9a3a917d | |||
289a765784 | |||
b13ad231d1 | |||
0793e84da6 | |||
|
f2c6d7cc80 | ||
6969b228a7 | |||
84362e6dd9 | |||
|
b83cc26ca0 | ||
|
6591845ded | ||
7c7c93521f | |||
9e10237b97 | |||
|
856c7dae7c | ||
e85f2e1f45 | |||
|
0a8ccce4e1 | ||
1b7e22442f | |||
|
4c81ce6a9d | ||
89ffe47d06 | |||
|
a03274011f | ||
186ec6bf00 | |||
|
fefcc273d9 | ||
a5ca5ec499 | |||
|
7104528c7d | ||
eaa61e254e | |||
|
00aa5331f6 | ||
c165c0f1a8 | |||
|
fa6fe590bd | ||
8cae060e05 | |||
a10275ad1f | |||
|
f247a8c906 | ||
|
015b2a4b05 | ||
|
c9da9d36a0 | ||
1f69062916 | |||
c4ca900a56 | |||
|
569d95e3e3 | ||
d2f1b7b3b9 | |||
|
65c10f7b0a | ||
76537a045a | |||
|
7f19288476 | ||
c3d10b669b | |||
20c5840f47 | |||
8b2dd91711 | |||
|
08621f7cf3 | ||
|
8d7d802730 | ||
137fbae58e | |||
|
13093dd404 | ||
12cf576b9c | |||
|
b91014d287 | ||
6b867760e5 | |||
|
f61f056a8e | ||
0525dae1cd | |||
|
50d0d836e5 | ||
a1e7560d6f | |||
a510f982e2 | |||
1129a1e992 | |||
|
033fcd3e2b | ||
c2ef582962 | |||
4c9f1f21a9 | |||
|
4585b73513 | ||
|
728d3f2a8c | ||
c1a2cfae67 | |||
8edc3d35bb | |||
|
4d0bb35dd9 | ||
0539d08195 | |||
f40591a520 | |||
acfab7e10c | |||
6697ccddf2 | |||
d536140a5b | |||
db02559a00 | |||
0fae2e1bdd | |||
|
7a1fdef33a | ||
2bb81ff232 | |||
|
9ac268b2f0 | ||
510fa4b379 | |||
|
08def4d244 | ||
a4683c0b78 |
8
.github/ISSUE_TEMPLATE/bug_report.md
vendored
8
.github/ISSUE_TEMPLATE/bug_report.md
vendored
@@ -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
8
.github/ISSUE_TEMPLATE/question.md
vendored
@@ -1,14 +1,8 @@
|
|||||||
---
|
---
|
||||||
name: Question
|
name: Question
|
||||||
about: Ask a question about go-micro
|
about: Ask a question about micro
|
||||||
title: ''
|
title: ''
|
||||||
labels: ''
|
labels: ''
|
||||||
assignees: ''
|
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
|
|
||||||
|
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 }}
|
19
.github/renovate.json
vendored
19
.github/renovate.json
vendored
@@ -1,19 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": [
|
|
||||||
"config:base"
|
|
||||||
],
|
|
||||||
"packageRules": [
|
|
||||||
{
|
|
||||||
"matchUpdateTypes": ["minor", "patch", "pin", "digest"],
|
|
||||||
"automerge": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"groupName": "all deps",
|
|
||||||
"separateMajorMinor": true,
|
|
||||||
"groupSlug": "all",
|
|
||||||
"packagePatterns": [
|
|
||||||
"*"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
13
.github/stale.sh
vendored
13
.github/stale.sh
vendored
@@ -1,13 +0,0 @@
|
|||||||
#!/bin/bash -ex
|
|
||||||
|
|
||||||
export PATH=$PATH:$(pwd)/bin
|
|
||||||
export GO111MODULE=on
|
|
||||||
export GOBIN=$(pwd)/bin
|
|
||||||
|
|
||||||
#go get github.com/rvflash/goup@v0.4.1
|
|
||||||
|
|
||||||
#goup -v ./...
|
|
||||||
#go get github.com/psampaz/go-mod-outdated@v0.6.0
|
|
||||||
go list -u -m -mod=mod -json all | go-mod-outdated -update -direct -ci || true
|
|
||||||
|
|
||||||
#go list -u -m -json all | go-mod-outdated -update
|
|
46
.github/workflows/build.yml
vendored
46
.github/workflows/build.yml
vendored
@@ -1,46 +0,0 @@
|
|||||||
name: build
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
jobs:
|
|
||||||
test:
|
|
||||||
name: test
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: setup
|
|
||||||
uses: actions/setup-go@v2
|
|
||||||
with:
|
|
||||||
go-version: 1.16
|
|
||||||
- name: checkout
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
- name: cache
|
|
||||||
uses: actions/cache@v2
|
|
||||||
with:
|
|
||||||
path: ~/go/pkg/mod
|
|
||||||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
|
||||||
restore-keys: ${{ runner.os }}-go-
|
|
||||||
- name: deps
|
|
||||||
run: go get -v -t -d ./...
|
|
||||||
- name: test
|
|
||||||
env:
|
|
||||||
INTEGRATION_TESTS: yes
|
|
||||||
run: go test -mod readonly -v ./...
|
|
||||||
lint:
|
|
||||||
name: lint
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: checkout
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
- name: lint
|
|
||||||
uses: golangci/golangci-lint-action@v2
|
|
||||||
continue-on-error: true
|
|
||||||
with:
|
|
||||||
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
|
|
||||||
version: v1.30
|
|
||||||
# Optional: working directory, useful for monorepos
|
|
||||||
# working-directory: somedir
|
|
||||||
# Optional: golangci-lint command line arguments.
|
|
||||||
# args: --issues-exit-code=0
|
|
||||||
# Optional: show only new issues if it's a pull request. The default value is `false`.
|
|
||||||
# only-new-issues: true
|
|
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 }}
|
29
.github/workflows/job_lint.yml
vendored
Normal file
29
.github/workflows/job_lint.yml
vendored
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
name: lint
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
types: [opened, reopened, synchronize]
|
||||||
|
branches: [ master, v3, v4 ]
|
||||||
|
paths-ignore:
|
||||||
|
- '.github/**'
|
||||||
|
- '.gitea/**'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
lint:
|
||||||
|
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: setup deps
|
||||||
|
run: go get -v ./...
|
||||||
|
- name: run lint
|
||||||
|
uses: golangci/golangci-lint-action@v6
|
||||||
|
with:
|
||||||
|
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
|
31
.github/workflows/job_test.yml
vendored
Normal file
31
.github/workflows/job_test.yml
vendored
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
name: test
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
types: [opened, reopened, synchronize]
|
||||||
|
branches: [ master, v3, v4 ]
|
||||||
|
push:
|
||||||
|
branches: [ master, v3, v4 ]
|
||||||
|
paths-ignore:
|
||||||
|
- '.github/**'
|
||||||
|
- '.gitea/**'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
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: setup deps
|
||||||
|
run: go get -v ./...
|
||||||
|
- name: run test
|
||||||
|
env:
|
||||||
|
INTEGRATION_TESTS: yes
|
||||||
|
run: go test -mod readonly -v ./...
|
50
.github/workflows/job_tests.yml
vendored
Normal file
50
.github/workflows/job_tests.yml
vendored
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
name: test
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
types: [opened, reopened, synchronize]
|
||||||
|
branches: [ master, v3, v4 ]
|
||||||
|
push:
|
||||||
|
branches: [ master, v3, v4 ]
|
||||||
|
paths-ignore:
|
||||||
|
- '.github/**'
|
||||||
|
- '.gitea/**'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
filter: 'blob:none'
|
||||||
|
- name: checkout tests
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
ref: master
|
||||||
|
filter: 'blob:none'
|
||||||
|
repository: unistack-org/micro-tests
|
||||||
|
path: micro-tests
|
||||||
|
- name: setup go
|
||||||
|
uses: actions/setup-go@v5
|
||||||
|
with:
|
||||||
|
cache-dependency-path: "**/*.sum"
|
||||||
|
go-version: 'stable'
|
||||||
|
- name: setup go work
|
||||||
|
env:
|
||||||
|
GOWORK: ${{ github.workspace }}/go.work
|
||||||
|
run: |
|
||||||
|
go work init
|
||||||
|
go work use .
|
||||||
|
go work use micro-tests
|
||||||
|
- name: setup deps
|
||||||
|
env:
|
||||||
|
GOWORK: ${{ github.workspace }}/go.work
|
||||||
|
run: go get -v ./...
|
||||||
|
- name: run tests
|
||||||
|
env:
|
||||||
|
INTEGRATION_TESTS: yes
|
||||||
|
GOWORK: ${{ github.workspace }}/go.work
|
||||||
|
run: |
|
||||||
|
cd micro-tests
|
||||||
|
go test -mod readonly -v ./... || true
|
46
.github/workflows/pr.yml
vendored
46
.github/workflows/pr.yml
vendored
@@ -1,46 +0,0 @@
|
|||||||
name: prbuild
|
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
jobs:
|
|
||||||
test:
|
|
||||||
name: test
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: setup
|
|
||||||
uses: actions/setup-go@v2
|
|
||||||
with:
|
|
||||||
go-version: 1.16
|
|
||||||
- name: checkout
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
- name: cache
|
|
||||||
uses: actions/cache@v2
|
|
||||||
with:
|
|
||||||
path: ~/go/pkg/mod
|
|
||||||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
|
||||||
restore-keys: ${{ runner.os }}-go-
|
|
||||||
- name: deps
|
|
||||||
run: go get -v -t -d ./...
|
|
||||||
- name: test
|
|
||||||
env:
|
|
||||||
INTEGRATION_TESTS: yes
|
|
||||||
run: go test -mod readonly -v ./...
|
|
||||||
lint:
|
|
||||||
name: lint
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: checkout
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
- name: lint
|
|
||||||
uses: golangci/golangci-lint-action@v2
|
|
||||||
continue-on-error: true
|
|
||||||
with:
|
|
||||||
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
|
|
||||||
version: v1.30
|
|
||||||
# Optional: working directory, useful for monorepos
|
|
||||||
# working-directory: somedir
|
|
||||||
# Optional: golangci-lint command line arguments.
|
|
||||||
# args: --issues-exit-code=0
|
|
||||||
# Optional: show only new issues if it's a pull request. The default value is `false`.
|
|
||||||
# only-new-issues: true
|
|
24
.gitignore
vendored
Normal file
24
.gitignore
vendored
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
# Binaries for programs and plugins
|
||||||
|
*.exe
|
||||||
|
*.exe~
|
||||||
|
*.dll
|
||||||
|
*.so
|
||||||
|
*.dylib
|
||||||
|
bin
|
||||||
|
|
||||||
|
# Test binary, built with `go test -c`
|
||||||
|
*.test
|
||||||
|
|
||||||
|
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||||
|
*.out
|
||||||
|
|
||||||
|
# Dependency directories (remove the comment below to include it)
|
||||||
|
# vendor/
|
||||||
|
|
||||||
|
# Go workspace file
|
||||||
|
go.work
|
||||||
|
|
||||||
|
# General
|
||||||
|
.DS_Store
|
||||||
|
.idea
|
||||||
|
.vscode
|
5
.golangci.yml
Normal file
5
.golangci.yml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
run:
|
||||||
|
concurrency: 8
|
||||||
|
timeout: 5m
|
||||||
|
issues-exit-code: 1
|
||||||
|
tests: true
|
4
README.md
Normal file
4
README.md
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# GRPC Client
|
||||||
|

|
||||||
|
|
||||||
|
This plugin is a grpc client for micro.
|
90
codec.go
90
codec.go
@@ -1,13 +1,16 @@
|
|||||||
package grpc
|
package grpc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"go.unistack.org/micro/v4/codec"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/codec"
|
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
"google.golang.org/grpc/encoding"
|
"google.golang.org/grpc/encoding"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
_ encoding.Codec = &wrapMicroCodec{}
|
||||||
|
_ codec.Codec = &wrapGrpcCodec{}
|
||||||
|
)
|
||||||
|
|
||||||
type wrapStream struct{ grpc.ClientStream }
|
type wrapStream struct{ grpc.ClientStream }
|
||||||
|
|
||||||
func (w *wrapStream) Write(d []byte) (int, error) {
|
func (w *wrapStream) Write(d []byte) (int, error) {
|
||||||
@@ -19,7 +22,7 @@ func (w *wrapStream) Write(d []byte) (int, error) {
|
|||||||
func (w *wrapStream) Read(d []byte) (int, error) {
|
func (w *wrapStream) Read(d []byte) (int, error) {
|
||||||
m := &codec.Frame{}
|
m := &codec.Frame{}
|
||||||
err := w.ClientStream.RecvMsg(m)
|
err := w.ClientStream.RecvMsg(m)
|
||||||
d = m.Data
|
copy(d, m.Data)
|
||||||
return len(d), err
|
return len(d), err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,89 +32,34 @@ func (w *wrapMicroCodec) Name() string {
|
|||||||
return w.Codec.String()
|
return w.Codec.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *wrapMicroCodec) Marshal(v interface{}) ([]byte, error) {
|
||||||
|
return w.Codec.Marshal(v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *wrapMicroCodec) Unmarshal(d []byte, v interface{}) error {
|
||||||
|
return w.Codec.Unmarshal(d, v)
|
||||||
|
}
|
||||||
|
|
||||||
type wrapGrpcCodec struct{ encoding.Codec }
|
type wrapGrpcCodec struct{ encoding.Codec }
|
||||||
|
|
||||||
func (w *wrapGrpcCodec) String() string {
|
func (w *wrapGrpcCodec) String() string {
|
||||||
return w.Codec.Name()
|
return w.Codec.Name()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *wrapGrpcCodec) Marshal(v interface{}) ([]byte, error) {
|
func (w *wrapGrpcCodec) Marshal(v interface{}, opts ...codec.Option) ([]byte, error) {
|
||||||
switch m := v.(type) {
|
if m, ok := v.(*codec.Frame); ok {
|
||||||
case *codec.Frame:
|
|
||||||
return m.Data, nil
|
return m.Data, nil
|
||||||
}
|
}
|
||||||
return w.Codec.Marshal(v)
|
return w.Codec.Marshal(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w wrapGrpcCodec) Unmarshal(d []byte, v interface{}) error {
|
func (w *wrapGrpcCodec) Unmarshal(d []byte, v interface{}, opts ...codec.Option) error {
|
||||||
if d == nil || v == nil {
|
if d == nil || v == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
switch m := v.(type) {
|
if m, ok := v.(*codec.Frame); ok {
|
||||||
case *codec.Frame:
|
|
||||||
m.Data = d
|
m.Data = d
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return w.Codec.Unmarshal(d, v)
|
return w.Codec.Unmarshal(d, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
type grpcCodec struct {
|
|
||||||
grpc.ServerStream
|
|
||||||
// headers
|
|
||||||
id string
|
|
||||||
target string
|
|
||||||
method string
|
|
||||||
endpoint string
|
|
||||||
|
|
||||||
c encoding.Codec
|
|
||||||
}
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
func (g *wrapGrpcCodec) ReadHeader(conn io.Reader, m *codec.Message, mt codec.MessageType) error {
|
|
||||||
/*
|
|
||||||
if m == nil {
|
|
||||||
m = codec.NewMessage(codec.Request)
|
|
||||||
}
|
|
||||||
|
|
||||||
if md, ok := metadata.FromIncomingContext(g.ServerStream.Context()); ok {
|
|
||||||
if m.Header == nil {
|
|
||||||
m.Header = meta.New(len(md))
|
|
||||||
}
|
|
||||||
for k, v := range md {
|
|
||||||
m.Header[k] = strings.Join(v, ",")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
m.Id = g.id
|
|
||||||
m.Target = g.target
|
|
||||||
m.Method = g.method
|
|
||||||
m.Endpoint = g.endpoint
|
|
||||||
*/
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *wrapGrpcCodec) ReadBody(conn io.Reader, v interface{}) error {
|
|
||||||
// caller has requested a frame
|
|
||||||
switch m := v.(type) {
|
|
||||||
case *codec.Frame:
|
|
||||||
_, err := conn.Read(m.Data)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return codec.ErrInvalidMessage
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *wrapGrpcCodec) Write(conn io.Writer, m *codec.Message, v interface{}) error {
|
|
||||||
// if we don't have a body
|
|
||||||
if v != nil {
|
|
||||||
b, err := g.Marshal(v)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
m.Body = b
|
|
||||||
}
|
|
||||||
// write the body using the framing codec
|
|
||||||
_, err := conn.Write(m.Body)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
67
codec_test.go
Normal file
67
codec_test.go
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
package grpc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"go.unistack.org/micro/v4/codec"
|
||||||
|
gmetadata "google.golang.org/grpc/metadata"
|
||||||
|
)
|
||||||
|
|
||||||
|
type mockStream struct {
|
||||||
|
msg any
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m mockStream) Header() (gmetadata.MD, error) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m mockStream) Trailer() gmetadata.MD {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m mockStream) CloseSend() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m mockStream) Context() context.Context {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mockStream) SendMsg(msg any) error {
|
||||||
|
m.msg = msg
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mockStream) RecvMsg(msg any) error {
|
||||||
|
|
||||||
|
c := msg.(*codec.Frame)
|
||||||
|
c.Data = m.msg.(*codec.Frame).Data
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_ReadWrap(t *testing.T) {
|
||||||
|
|
||||||
|
wp := wrapStream{
|
||||||
|
&mockStream{},
|
||||||
|
}
|
||||||
|
|
||||||
|
write, err := wp.Write([]byte("test_data"))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if write != 9 {
|
||||||
|
t.Error("uncorrected number wrote bytes")
|
||||||
|
}
|
||||||
|
|
||||||
|
b := make([]byte, write)
|
||||||
|
read, err := wp.Read(b)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if read != 9 || string(b) != "test_data" {
|
||||||
|
t.Error("uncorrected number wrote bytes or data")
|
||||||
|
}
|
||||||
|
}
|
35
error.go
35
error.go
@@ -1,7 +1,7 @@
|
|||||||
package grpc
|
package grpc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/unistack-org/micro/v3/errors"
|
"go.unistack.org/micro/v4/errors"
|
||||||
"google.golang.org/grpc/status"
|
"google.golang.org/grpc/status"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -9,31 +9,46 @@ func microError(err error) error {
|
|||||||
// no error
|
// no error
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
// nothing to do
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if verr, ok := err.(*errors.Error); ok {
|
if verr, ok := err.(*errors.Error); ok {
|
||||||
|
// micro error
|
||||||
return verr
|
return verr
|
||||||
}
|
}
|
||||||
|
|
||||||
// grpc error
|
// grpc error
|
||||||
s, ok := status.FromError(err)
|
s, ok := status.FromError(err)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
// can't get status detals from grpc error, return base error
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// return first error from details
|
details := s.Details()
|
||||||
if details := s.Details(); len(details) > 0 {
|
switch len(details) {
|
||||||
if verr, ok := details[0].(error); ok {
|
case 0:
|
||||||
return microError(verr)
|
if verr := errors.Parse(s.Message()); verr.Code > 0 {
|
||||||
|
// return micro error
|
||||||
|
return verr
|
||||||
}
|
}
|
||||||
|
// return base error as it not micro error
|
||||||
|
return err
|
||||||
|
case 1:
|
||||||
|
if verr, ok := details[0].(*errors.Error); ok {
|
||||||
|
// return nested micro error
|
||||||
|
return verr
|
||||||
|
}
|
||||||
|
// return base error as it not holds micro error
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// try to decode micro *errors.Error
|
// attached messages in details more then 1, try to fallback to micro error
|
||||||
if e := errors.Parse(s.Message()); e.Code > 0 {
|
if verr := errors.Parse(s.Message()); verr.Code > 0 {
|
||||||
return e // actually a micro error
|
// return micro error
|
||||||
|
return verr
|
||||||
}
|
}
|
||||||
|
|
||||||
// fallback
|
// not micro error return base error
|
||||||
return errors.InternalServerError("go.micro.client", s.Message())
|
return err
|
||||||
}
|
}
|
||||||
|
27
go.mod
27
go.mod
@@ -1,13 +1,24 @@
|
|||||||
module github.com/unistack-org/micro-client-grpc/v3
|
module go.unistack.org/micro-client-grpc/v4
|
||||||
|
|
||||||
go 1.16
|
go 1.23.0
|
||||||
|
|
||||||
|
toolchain go1.23.3
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/google/go-cmp v0.5.1 // indirect
|
go.unistack.org/micro/v4 v4.1.7
|
||||||
github.com/unistack-org/micro/v3 v3.3.15
|
google.golang.org/grpc v1.72.0
|
||||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
|
|
||||||
google.golang.org/genproto v0.0.0-20200904004341-0bd0a958aa1d // indirect
|
|
||||||
google.golang.org/grpc v1.37.0
|
|
||||||
)
|
)
|
||||||
|
|
||||||
//replace github.com/unistack-org/micro/v3 => ../../micro
|
require (
|
||||||
|
github.com/ash3in/uuidv8 v1.2.0 // indirect
|
||||||
|
github.com/google/uuid v1.6.0 // indirect
|
||||||
|
github.com/matoous/go-nanoid v1.5.1 // indirect
|
||||||
|
github.com/spf13/cast v1.7.1 // indirect
|
||||||
|
go.unistack.org/micro-proto/v4 v4.1.0 // indirect
|
||||||
|
golang.org/x/net v0.39.0 // indirect
|
||||||
|
golang.org/x/sys v0.32.0 // indirect
|
||||||
|
golang.org/x/text v0.24.0 // indirect
|
||||||
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20250425173222-7b384671a197 // indirect
|
||||||
|
google.golang.org/protobuf v1.36.6 // indirect
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
|
)
|
||||||
|
200
go.sum
200
go.sum
@@ -1,143 +1,59 @@
|
|||||||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
github.com/DATA-DOG/go-sqlmock v1.5.2 h1:OcvFkGmslmlZibjAjaHm3L//6LiuBgolP7OputlJIzU=
|
||||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
github.com/DATA-DOG/go-sqlmock v1.5.2/go.mod h1:88MAG/4G7SMwSE3CeA0ZKzrT5CiOU3OJ+JlNzwDqpNU=
|
||||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
github.com/ash3in/uuidv8 v1.2.0 h1:2oogGdtCPwaVtyvPPGin4TfZLtOGE5F+W++E880G6SI=
|
||||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
github.com/ash3in/uuidv8 v1.2.0/go.mod h1:BnU0wJBxnzdEKmVg4xckBkD+VZuecTFTUP3M0dWgyY4=
|
||||||
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
|
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
|
||||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
|
||||||
github.com/ef-ds/deque v1.0.4/go.mod h1:gXDnTC3yqvBcHbq2lcExjtAcVrOnJCbMcZXmuj8Z4tg=
|
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||||
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||||
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||||
github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
|
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
|
||||||
github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
|
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
|
||||||
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||||
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||||
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
|
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||||
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
|
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||||
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
|
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||||
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
|
github.com/matoous/go-nanoid v1.5.1 h1:aCjdvTyO9LLnTIi0fgdXhOPPvOHjpXN6Ik9DaNjIct4=
|
||||||
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
|
github.com/matoous/go-nanoid v1.5.1/go.mod h1:zyD2a71IubI24efhpvkJz+ZwfwagzgSO6UNiFsZKN7U=
|
||||||
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
|
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
|
||||||
github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0=
|
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
|
||||||
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
github.com/spf13/cast v1.7.1 h1:cuNEagBQEHWN1FnbGEjCXL2szYEXqfJPbP2HNUaca9Y=
|
||||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
github.com/spf13/cast v1.7.1/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
|
||||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
|
||||||
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=
|
||||||
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
go.opentelemetry.io/otel v1.34.0 h1:zRLXxLCgL1WyKsPVrgbSdMN4c0FMkDAskSTQP+0hdUY=
|
||||||
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
go.opentelemetry.io/otel v1.34.0/go.mod h1:OWFPOQ+h4G8xpyjgqo4SxJYdDQ/qmRH+wivy7zzx9oI=
|
||||||
github.com/google/go-cmp v0.5.1 h1:JFrFEBb2xKufg6XkJsJr+WbKb4FQlURi5RUcBveYu9k=
|
go.opentelemetry.io/otel/metric v1.34.0 h1:+eTR3U0MyfWjRDhmFMxe2SsW64QrZ84AOhvqS7Y+PoQ=
|
||||||
github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
go.opentelemetry.io/otel/metric v1.34.0/go.mod h1:CEDrp0fy2D0MvkXE+dPV7cMi8tWZwX3dmaIhwPOaqHE=
|
||||||
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
go.opentelemetry.io/otel/sdk v1.34.0 h1:95zS4k/2GOy069d321O8jWgYsW3MzVV+KuSPKp7Wr1A=
|
||||||
github.com/google/uuid v1.2.0 h1:qJYtXnJRWmpe7m/3XlyhrsLrEURqHRM2kxzoxXqyUDs=
|
go.opentelemetry.io/otel/sdk v1.34.0/go.mod h1:0e/pNiaMAqaykJGKbi+tSjWfNNHMTxoC9qANsCzbyxU=
|
||||||
github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
go.opentelemetry.io/otel/sdk/metric v1.34.0 h1:5CeK9ujjbFVL5c1PhLuStg1wxA7vQv7ce1EK0Gyvahk=
|
||||||
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
|
go.opentelemetry.io/otel/sdk/metric v1.34.0/go.mod h1:jQ/r8Ze28zRKoNRdkjCZxfs6YvBTG1+YIqyFVFYec5w=
|
||||||
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
|
go.opentelemetry.io/otel/trace v1.34.0 h1:+ouXS2V8Rd4hp4580a8q23bg0azF2nI8cqLYnC8mh/k=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
go.opentelemetry.io/otel/trace v1.34.0/go.mod h1:Svm7lSjQD7kG7KJ/MUHPVXSDGz2OX4h0M2jHBhmSfRE=
|
||||||
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
go.unistack.org/micro-proto/v4 v4.1.0 h1:qPwL2n/oqh9RE3RTTDgt28XK3QzV597VugQPaw9lKUk=
|
||||||
github.com/silas/dag v0.0.0-20210121180416-41cf55125c34/go.mod h1:7RTUFBdIRC9nZ7/3RyRNH1bdqIShrDejd1YbLwgPS+I=
|
go.unistack.org/micro-proto/v4 v4.1.0/go.mod h1:ArmK7o+uFvxSY3dbJhKBBX4Pm1rhWdLEFf3LxBrMtec=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
go.unistack.org/micro/v4 v4.1.7 h1:4/dSEMTqxYoHimn/8wKDohfTXi2zDy6eWXYBCnBaZdc=
|
||||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
go.unistack.org/micro/v4 v4.1.7/go.mod h1:lr3oYED8Ay1vjK68QqRw30QOtdk/ffpZqMFDasOUhKw=
|
||||||
github.com/unistack-org/micro/v3 v3.3.0 h1:pEj/8QVFzMlNMEL//q/Te8qgG+XI6LTYIQrb6hMymgk=
|
golang.org/x/net v0.39.0 h1:ZCu7HMWDxpXpaiKdhzIfaltL9Lp31x/3fCP11bc6/fY=
|
||||||
github.com/unistack-org/micro/v3 v3.3.0/go.mod h1:iJwCWq2PECMxigfqe6TPC5GLWvj6P94Kk+PTVZGL3w8=
|
golang.org/x/net v0.39.0/go.mod h1:X7NRbYVEA+ewNkCNyJ513WmMdQ3BineSwVtN2zD/d+E=
|
||||||
github.com/unistack-org/micro/v3 v3.3.1 h1:2KUgb5THy5GUjYgMcOf3TXYIJ0h2RbJHb2j6eeWdRx0=
|
golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20=
|
||||||
github.com/unistack-org/micro/v3 v3.3.1/go.mod h1:iJwCWq2PECMxigfqe6TPC5GLWvj6P94Kk+PTVZGL3w8=
|
golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||||
github.com/unistack-org/micro/v3 v3.3.2 h1:1r7fmaobJVZBKDhIewSBy8R4H/6YazQFetsDgULV6Mw=
|
golang.org/x/text v0.24.0 h1:dd5Bzh4yt5KYA8f9CJHCP4FB4D51c2c6JvN37xJJkJ0=
|
||||||
github.com/unistack-org/micro/v3 v3.3.2/go.mod h1:tX95c0Qx4w6oqU7qKThs9lya9P507BdZ29MsTVDmU6w=
|
golang.org/x/text v0.24.0/go.mod h1:L8rBsPeo2pSS+xqN0d5u2ikmjtmoJbDBT1b7nHvFCdU=
|
||||||
github.com/unistack-org/micro/v3 v3.3.4 h1:wSYjL1sfrqtMmgFfYKylrKpAepMHrPcOpe10hvQAKuo=
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20250425173222-7b384671a197 h1:29cjnHVylHwTzH66WfFZqgSQgnxzvWE+jvBwpZCLRxY=
|
||||||
github.com/unistack-org/micro/v3 v3.3.4/go.mod h1:tX95c0Qx4w6oqU7qKThs9lya9P507BdZ29MsTVDmU6w=
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20250425173222-7b384671a197/go.mod h1:qQ0YXyHHx3XkvlzUtpXDkS29lDSafHMZBAZDc03LQ3A=
|
||||||
github.com/unistack-org/micro/v3 v3.3.8/go.mod h1:M3RGgKZX1OlTn0QB+3R1tlSoGwmEg6rb/Isr0lLYmjQ=
|
google.golang.org/grpc v1.72.0 h1:S7UkcVa60b5AAQTaO6ZKamFp1zMZSU0fGDK2WZLbBnM=
|
||||||
github.com/unistack-org/micro/v3 v3.3.9 h1:NFF4wymDDxgYeZU++04BxvETrrAnd0iNzVyfm/ssQI4=
|
google.golang.org/grpc v1.72.0/go.mod h1:wH5Aktxcg25y1I3w7H69nHfXdOG3UiadoBtjh3izSDM=
|
||||||
github.com/unistack-org/micro/v3 v3.3.9/go.mod h1:M3RGgKZX1OlTn0QB+3R1tlSoGwmEg6rb/Isr0lLYmjQ=
|
google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY=
|
||||||
github.com/unistack-org/micro/v3 v3.3.10 h1:yMSiyplupFQ7xy/kNXL/zqSnqGSjrlNa2GTCwea5BVg=
|
google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
|
||||||
github.com/unistack-org/micro/v3 v3.3.10/go.mod h1:5ragE2E8ER5d4FZQJG9pB6qdfOoLXLfKW89l77Dy3jQ=
|
|
||||||
github.com/unistack-org/micro/v3 v3.3.11 h1:Jr0gAw5lLqgddiHKQeWUOUeP6ZqgRhz52EA9zJ5MJ3U=
|
|
||||||
github.com/unistack-org/micro/v3 v3.3.11/go.mod h1:PPCt675o3HPcODFbJ4iRWPmQFAk1WQ+asQSOb/syq6U=
|
|
||||||
github.com/unistack-org/micro/v3 v3.3.13 h1:y4bDDkbwnjgOckrhFkC6D/o42tr75X33UbrB+Ko0M68=
|
|
||||||
github.com/unistack-org/micro/v3 v3.3.13/go.mod h1:98hNcMXp/WyWJwLwCuwrhN1Jm7aCWaRNsMfRjK8Fq+Y=
|
|
||||||
github.com/unistack-org/micro/v3 v3.3.14 h1:CAkDMjHZT8/D6GGF5h3gK84m6tlWZC17IGPb2GkAn/4=
|
|
||||||
github.com/unistack-org/micro/v3 v3.3.14/go.mod h1:ETGcQQUcjxGaD44LUMX+0fgo8Loh7ExldfIPLvfUmDo=
|
|
||||||
github.com/unistack-org/micro/v3 v3.3.15 h1:rj+spzhezCg4gmj1nuF0FRGixC51/7xFACOchB/23/E=
|
|
||||||
github.com/unistack-org/micro/v3 v3.3.15/go.mod h1:ETGcQQUcjxGaD44LUMX+0fgo8Loh7ExldfIPLvfUmDo=
|
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
|
||||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
|
||||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
|
||||||
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
|
||||||
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
|
||||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
|
||||||
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
|
||||||
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
|
||||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
|
||||||
golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4 h1:b0LrWgu8+q7z4J+0Y3Umo5q1dL7NXBkKBWkaVkAq17E=
|
|
||||||
golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc=
|
|
||||||
golang.org/x/net v0.0.0-20210324205630-d1beb07c2056 h1:sANdAef76Ioam9aQUUdcAqricwY/WUaMc4+7LY4eGg8=
|
|
||||||
golang.org/x/net v0.0.0-20210324205630-d1beb07c2056/go.mod h1:uSPa2vr4CLtc/ILN5odXGNXS6mhrKVzTaCXzk9m6W3k=
|
|
||||||
golang.org/x/net v0.0.0-20210326220855-61e056675ecf/go.mod h1:uSPa2vr4CLtc/ILN5odXGNXS6mhrKVzTaCXzk9m6W3k=
|
|
||||||
golang.org/x/net v0.0.0-20210331060903-cb1fcc7394e5/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
|
||||||
golang.org/x/net v0.0.0-20210331212208-0fccb6fa2b5c h1:KHUzaHIpjWVlVVNh65G3hhuj3KB1HnjY6Cq5cTvRQT8=
|
|
||||||
golang.org/x/net v0.0.0-20210331212208-0fccb6fa2b5c/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
|
||||||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4 h1:4nGaVu0QrbjT/AK2PRLuQfQuh6DJve+pELhqTdAj3x0=
|
|
||||||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
|
||||||
golang.org/x/net v0.0.0-20210415231046-e915ea6b2b7d h1:BgJvlyh+UqCUaPlscHJ+PN8GcpfrFdr7NHjd1JL0+Gs=
|
|
||||||
golang.org/x/net v0.0.0-20210415231046-e915ea6b2b7d/go.mod h1:9tjilg8BloeKEkVJvy7fQ90B1CfIiPueXVOjqfkSzI8=
|
|
||||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
|
||||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
|
||||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005 h1:pDMpM2zh2MT0kHy037cKlSby2nEhD50SYqwQk76Nm40=
|
|
||||||
golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20210324051608-47abb6519492/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44 h1:Bli41pIlzTzf3KEY06n+xnzK/BESIg2ze4Pgfh/aI8c=
|
|
||||||
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
|
||||||
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
|
|
||||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
|
||||||
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
|
|
||||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
|
||||||
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
|
||||||
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
|
|
||||||
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
|
||||||
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
|
||||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
|
||||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
|
|
||||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
|
||||||
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
|
||||||
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
|
||||||
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
|
||||||
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
|
|
||||||
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
|
|
||||||
google.golang.org/genproto v0.0.0-20200904004341-0bd0a958aa1d h1:92D1fum1bJLKSdr11OJ+54YeCMCGYIygTA7R/YZxH5M=
|
|
||||||
google.golang.org/genproto v0.0.0-20200904004341-0bd0a958aa1d/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
|
|
||||||
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
|
||||||
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
|
|
||||||
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
|
|
||||||
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
|
|
||||||
google.golang.org/grpc v1.36.0 h1:o1bcQ6imQMIOpdrO3SWf2z5RV72WbDwdXuK0MDlc8As=
|
|
||||||
google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
|
|
||||||
google.golang.org/grpc v1.36.1 h1:cmUfbeGKnz9+2DD/UYsMQXeqbHZqZDs4eQwW0sFOpBY=
|
|
||||||
google.golang.org/grpc v1.36.1/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
|
|
||||||
google.golang.org/grpc v1.37.0 h1:uSZWeQJX5j11bIQ4AJoj+McDBo29cY1MCoC1wO3ts+c=
|
|
||||||
google.golang.org/grpc v1.37.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM=
|
|
||||||
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-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
|
|
||||||
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
|
|
||||||
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
|
|
||||||
google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
|
||||||
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
|
||||||
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
|
||||||
google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4=
|
|
||||||
google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c=
|
|
||||||
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
|
|
||||||
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/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||||
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
479
grpc.go
479
grpc.go
@@ -1,4 +1,4 @@
|
|||||||
// Package grpc provides a gRPC client
|
// Package grpc provides a gRPC client for micro framework
|
||||||
package grpc
|
package grpc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@@ -7,45 +7,52 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/broker"
|
"go.unistack.org/micro/v4/client"
|
||||||
"github.com/unistack-org/micro/v3/client"
|
"go.unistack.org/micro/v4/codec"
|
||||||
"github.com/unistack-org/micro/v3/codec"
|
"go.unistack.org/micro/v4/errors"
|
||||||
"github.com/unistack-org/micro/v3/errors"
|
"go.unistack.org/micro/v4/metadata"
|
||||||
"github.com/unistack-org/micro/v3/metadata"
|
"go.unistack.org/micro/v4/options"
|
||||||
|
"go.unistack.org/micro/v4/selector"
|
||||||
|
"go.unistack.org/micro/v4/semconv"
|
||||||
|
"go.unistack.org/micro/v4/tracer"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
|
"google.golang.org/grpc/codes"
|
||||||
"google.golang.org/grpc/credentials"
|
"google.golang.org/grpc/credentials"
|
||||||
|
"google.golang.org/grpc/credentials/insecure"
|
||||||
"google.golang.org/grpc/encoding"
|
"google.golang.org/grpc/encoding"
|
||||||
gmetadata "google.golang.org/grpc/metadata"
|
gmetadata "google.golang.org/grpc/metadata"
|
||||||
|
"google.golang.org/grpc/status"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
DefaultContentType = "application/grpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
type grpcClient struct {
|
type grpcClient struct {
|
||||||
opts client.Options
|
funcCall client.FuncCall
|
||||||
codecs map[string]encoding.Codec
|
funcStream client.FuncStream
|
||||||
pool *pool
|
pool *ConnPool
|
||||||
once atomic.Value
|
opts client.Options
|
||||||
init bool
|
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
|
init bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// secure returns the dial option for whether its a secure or insecure connection
|
// secure returns the dial option for whether its a secure or insecure connection
|
||||||
func (g *grpcClient) secure(addr string) grpc.DialOption {
|
func (g *grpcClient) secure(addr string) grpc.DialOption {
|
||||||
// first we check if theres'a tls config
|
// first we check if theres'a tls config
|
||||||
if g.opts.Context != nil {
|
if g.opts.TLSConfig != nil {
|
||||||
if v := g.opts.Context.Value(tlsAuth{}); v != nil {
|
creds := credentials.NewTLS(g.opts.TLSConfig)
|
||||||
tls := v.(*tls.Config)
|
// return tls config if it exists
|
||||||
creds := credentials.NewTLS(tls)
|
return grpc.WithTransportCredentials(creds)
|
||||||
// return tls config if it exists
|
|
||||||
return grpc.WithTransportCredentials(creds)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// default config
|
// default config
|
||||||
tlsConfig := &tls.Config{}
|
tlsConfig := &tls.Config{MinVersion: tls.VersionTLS12}
|
||||||
defaultCreds := grpc.WithTransportCredentials(credentials.NewTLS(tlsConfig))
|
defaultCreds := grpc.WithTransportCredentials(credentials.NewTLS(tlsConfig))
|
||||||
|
|
||||||
// check if the address is prepended with https
|
// check if the address is prepended with https
|
||||||
@@ -63,36 +70,39 @@ func (g *grpcClient) secure(addr string) grpc.DialOption {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// other fallback to insecure
|
// other fallback to insecure
|
||||||
return grpc.WithInsecure()
|
return grpc.WithTransportCredentials(insecure.NewCredentials())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *grpcClient) call(ctx context.Context, addr string, req client.Request, rsp interface{}, opts client.CallOptions) error {
|
func (g *grpcClient) call(ctx context.Context, addr string, req client.Request, rsp interface{}, opts client.CallOptions) error {
|
||||||
var header map[string]string
|
var header gmetadata.MD
|
||||||
|
|
||||||
if md, ok := metadata.FromOutgoingContext(ctx); ok {
|
if md, ok := metadata.FromOutgoingContext(ctx); ok {
|
||||||
header = make(map[string]string, len(md))
|
header = metadata.Copy(md).AsHTTP2()
|
||||||
for k, v := range md {
|
} else {
|
||||||
|
header = make(gmetadata.MD, 4)
|
||||||
|
}
|
||||||
|
if opts.RequestMetadata != nil {
|
||||||
|
for k, v := range opts.RequestMetadata {
|
||||||
header[strings.ToLower(k)] = v
|
header[strings.ToLower(k)] = v
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
header = make(map[string]string, 2)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// set timeout in nanoseconds
|
// set timeout in nanoseconds
|
||||||
header["timeout"] = fmt.Sprintf("%d", opts.RequestTimeout)
|
if opts.RequestTimeout > time.Duration(0) {
|
||||||
// set the content type for the request
|
header.Set("grpc-timeout", fmt.Sprintf("%dn", opts.RequestTimeout))
|
||||||
header["x-content-type"] = req.ContentType()
|
header.Set("timeout", fmt.Sprintf("%dn", opts.RequestTimeout))
|
||||||
|
}
|
||||||
|
header.Set("content-type", req.ContentType())
|
||||||
|
|
||||||
md := gmetadata.New(header)
|
ctx = gmetadata.NewOutgoingContext(ctx, header)
|
||||||
ctx = gmetadata.NewOutgoingContext(ctx, md)
|
|
||||||
|
|
||||||
cf, err := g.newCodec(req.ContentType())
|
cf, err := g.newCodec(req.ContentType())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.InternalServerError("go.micro.client", err.Error())
|
return errors.InternalServerError("go.micro.client", "%+v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
maxRecvMsgSize := g.maxRecvMsgSizeValue()
|
maxRecvMsgSize := g.maxRecvMsgSizeValue()
|
||||||
maxSendMsgSize := g.maxSendMsgSizeValue()
|
maxSendMsgSize := g.maxSendMsgSizeValue()
|
||||||
|
cfgService := g.serviceConfig()
|
||||||
|
|
||||||
var grr error
|
var grr error
|
||||||
|
|
||||||
@@ -111,30 +121,50 @@ func (g *grpcClient) call(ctx context.Context, addr string, req client.Request,
|
|||||||
grpc.MaxCallRecvMsgSize(maxRecvMsgSize),
|
grpc.MaxCallRecvMsgSize(maxRecvMsgSize),
|
||||||
grpc.MaxCallSendMsgSize(maxSendMsgSize),
|
grpc.MaxCallSendMsgSize(maxSendMsgSize),
|
||||||
),
|
),
|
||||||
|
grpc.WithDefaultServiceConfig(cfgService),
|
||||||
}
|
}
|
||||||
|
|
||||||
if opts := g.getGrpcDialOptions(); opts != nil {
|
if opts := g.getGrpcDialOptions(g.opts.Context); opts != nil {
|
||||||
|
grpcDialOptions = append(grpcDialOptions, opts...)
|
||||||
|
}
|
||||||
|
if opts := g.getGrpcDialOptions(opts.Context); opts != nil {
|
||||||
grpcDialOptions = append(grpcDialOptions, opts...)
|
grpcDialOptions = append(grpcDialOptions, opts...)
|
||||||
}
|
}
|
||||||
|
|
||||||
cc, err := g.pool.getConn(dialCtx, addr, grpcDialOptions...)
|
contextDialer := g.opts.ContextDialer
|
||||||
|
if opts.ContextDialer != nil {
|
||||||
|
contextDialer = opts.ContextDialer
|
||||||
|
}
|
||||||
|
if contextDialer != nil {
|
||||||
|
grpcDialOptions = append(grpcDialOptions, grpc.WithContextDialer(contextDialer))
|
||||||
|
}
|
||||||
|
|
||||||
|
cc, err := g.pool.Get(dialCtx, addr, grpcDialOptions...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.InternalServerError("go.micro.client", fmt.Sprintf("Error sending request: %v", err))
|
return errors.InternalServerError("go.micro.client", "Error sending request: %v", err)
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
// defer execution of release
|
// defer execution of release
|
||||||
g.pool.release(addr, cc, grr)
|
g.pool.Put(cc, grr)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
ch := make(chan error, 1)
|
ch := make(chan error, 1)
|
||||||
|
var gmd gmetadata.MD
|
||||||
|
|
||||||
|
grpcCallOptions := []grpc.CallOption{
|
||||||
|
grpc.CallContentSubtype((&wrapMicroCodec{cf}).Name()),
|
||||||
|
}
|
||||||
|
|
||||||
|
if opts := g.getGrpcCallOptions(opts.Context); opts != nil {
|
||||||
|
grpcCallOptions = append(grpcCallOptions, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
if opts.ResponseMetadata != nil {
|
||||||
|
gmd = gmetadata.MD{}
|
||||||
|
grpcCallOptions = append(grpcCallOptions, grpc.Header(&gmd))
|
||||||
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
grpcCallOptions := []grpc.CallOption{
|
|
||||||
grpc.ForceCodec(&wrapMicroCodec{cf}),
|
|
||||||
grpc.CallContentSubtype((&wrapMicroCodec{cf}).Name())}
|
|
||||||
if opts := g.getGrpcCallOptions(); opts != nil {
|
|
||||||
grpcCallOptions = append(grpcCallOptions, opts...)
|
|
||||||
}
|
|
||||||
err := cc.Invoke(ctx, methodToGRPC(req.Service(), req.Endpoint()), req.Body(), rsp, grpcCallOptions...)
|
err := cc.Invoke(ctx, methodToGRPC(req.Service(), req.Endpoint()), req.Body(), rsp, grpcCallOptions...)
|
||||||
ch <- microError(err)
|
ch <- microError(err)
|
||||||
}()
|
}()
|
||||||
@@ -146,34 +176,36 @@ func (g *grpcClient) call(ctx context.Context, addr string, req client.Request,
|
|||||||
grr = errors.Timeout("go.micro.client", "%v", ctx.Err())
|
grr = errors.Timeout("go.micro.client", "%v", ctx.Err())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if opts.ResponseMetadata != nil {
|
||||||
|
*opts.ResponseMetadata = metadata.New(gmd.Len())
|
||||||
|
for k, v := range gmd {
|
||||||
|
opts.ResponseMetadata.Append(k, v...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return grr
|
return grr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *grpcClient) stream(ctx context.Context, addr string, req client.Request, rsp interface{}, opts client.CallOptions) error {
|
func (g *grpcClient) stream(ctx context.Context, addr string, req client.Request, rsp interface{}, opts client.CallOptions) error {
|
||||||
var header map[string]string
|
var header gmetadata.MD
|
||||||
|
|
||||||
if md, ok := metadata.FromOutgoingContext(ctx); ok {
|
if md, ok := metadata.FromOutgoingContext(ctx); ok {
|
||||||
header = make(map[string]string, len(md))
|
header = metadata.Copy(md).AsHTTP2()
|
||||||
for k, v := range md {
|
|
||||||
header[k] = v
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
header = make(map[string]string)
|
header = make(gmetadata.MD, 4)
|
||||||
}
|
}
|
||||||
|
|
||||||
// set timeout in nanoseconds
|
if opts.RequestTimeout > time.Duration(0) {
|
||||||
if opts.StreamTimeout > time.Duration(0) {
|
header.Set("grpc-timeout", fmt.Sprintf("%dn", opts.RequestTimeout))
|
||||||
header["timeout"] = fmt.Sprintf("%d", opts.StreamTimeout)
|
header.Set("timeout", fmt.Sprintf("%dn", opts.RequestTimeout))
|
||||||
}
|
}
|
||||||
// set the content type for the request
|
header.Set("content-type", req.ContentType())
|
||||||
header["x-content-type"] = req.ContentType()
|
|
||||||
|
|
||||||
md := gmetadata.New(header)
|
ctx = gmetadata.NewOutgoingContext(ctx, header)
|
||||||
ctx = gmetadata.NewOutgoingContext(ctx, md)
|
|
||||||
|
|
||||||
cf, err := g.newCodec(req.ContentType())
|
cf, err := g.newCodec(req.ContentType())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.InternalServerError("go.micro.client", err.Error())
|
return errors.InternalServerError("go.micro.client", "%+v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var dialCtx context.Context
|
var dialCtx context.Context
|
||||||
@@ -187,17 +219,34 @@ func (g *grpcClient) stream(ctx context.Context, addr string, req client.Request
|
|||||||
|
|
||||||
wc := &wrapMicroCodec{cf}
|
wc := &wrapMicroCodec{cf}
|
||||||
|
|
||||||
|
maxRecvMsgSize := g.maxRecvMsgSizeValue()
|
||||||
|
maxSendMsgSize := g.maxSendMsgSizeValue()
|
||||||
|
cfgService := g.serviceConfig()
|
||||||
|
|
||||||
grpcDialOptions := []grpc.DialOption{
|
grpcDialOptions := []grpc.DialOption{
|
||||||
g.secure(addr),
|
g.secure(addr),
|
||||||
|
grpc.WithDefaultCallOptions(
|
||||||
|
grpc.MaxCallRecvMsgSize(maxRecvMsgSize),
|
||||||
|
grpc.MaxCallSendMsgSize(maxSendMsgSize),
|
||||||
|
),
|
||||||
|
grpc.WithDefaultServiceConfig(cfgService),
|
||||||
}
|
}
|
||||||
|
|
||||||
if opts := g.getGrpcDialOptions(); opts != nil {
|
if opts := g.getGrpcDialOptions(opts.Context); opts != nil {
|
||||||
grpcDialOptions = append(grpcDialOptions, opts...)
|
grpcDialOptions = append(grpcDialOptions, opts...)
|
||||||
}
|
}
|
||||||
|
|
||||||
cc, err := g.pool.getConn(dialCtx, addr, grpcDialOptions...)
|
contextDialer := g.opts.ContextDialer
|
||||||
|
if opts.ContextDialer != nil {
|
||||||
|
contextDialer = opts.ContextDialer
|
||||||
|
}
|
||||||
|
if contextDialer != nil {
|
||||||
|
grpcDialOptions = append(grpcDialOptions, grpc.WithContextDialer(contextDialer))
|
||||||
|
}
|
||||||
|
|
||||||
|
cc, err := g.pool.Get(dialCtx, addr, grpcDialOptions...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.InternalServerError("go.micro.client", fmt.Sprintf("Error sending request: %v", err))
|
return errors.InternalServerError("go.micro.client", "Error sending request: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
desc := &grpc.StreamDesc{
|
desc := &grpc.StreamDesc{
|
||||||
@@ -207,12 +256,17 @@ func (g *grpcClient) stream(ctx context.Context, addr string, req client.Request
|
|||||||
}
|
}
|
||||||
|
|
||||||
grpcCallOptions := []grpc.CallOption{
|
grpcCallOptions := []grpc.CallOption{
|
||||||
grpc.ForceCodec(wc),
|
// grpc.ForceCodec(wc),
|
||||||
grpc.CallContentSubtype(wc.Name()),
|
grpc.CallContentSubtype(wc.Name()),
|
||||||
}
|
}
|
||||||
if opts := g.getGrpcCallOptions(); opts != nil {
|
if opts := g.getGrpcCallOptions(opts.Context); opts != nil {
|
||||||
grpcCallOptions = append(grpcCallOptions, opts...)
|
grpcCallOptions = append(grpcCallOptions, opts...)
|
||||||
}
|
}
|
||||||
|
var gmd gmetadata.MD
|
||||||
|
if opts.ResponseMetadata != nil {
|
||||||
|
gmd = gmetadata.MD{}
|
||||||
|
grpcCallOptions = append(grpcCallOptions, grpc.Header(&gmd))
|
||||||
|
}
|
||||||
|
|
||||||
// create a new cancelling context
|
// create a new cancelling context
|
||||||
newCtx, cancel := context.WithCancel(ctx)
|
newCtx, cancel := context.WithCancel(ctx)
|
||||||
@@ -223,9 +277,9 @@ func (g *grpcClient) stream(ctx context.Context, addr string, req client.Request
|
|||||||
// cancel the context
|
// cancel the context
|
||||||
cancel()
|
cancel()
|
||||||
// release the connection
|
// release the connection
|
||||||
g.pool.release(addr, cc, err)
|
g.pool.Put(cc, err)
|
||||||
// now return the error
|
// now return the error
|
||||||
return errors.InternalServerError("go.micro.client", fmt.Sprintf("Error creating stream: %v", err))
|
return errors.InternalServerError("go.micro.client", "Error creating stream: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// set request codec
|
// set request codec
|
||||||
@@ -245,19 +299,20 @@ func (g *grpcClient) stream(ctx context.Context, addr string, req client.Request
|
|||||||
},
|
},
|
||||||
conn: cc,
|
conn: cc,
|
||||||
close: func(err error) {
|
close: func(err error) {
|
||||||
// cancel the context if an error occured
|
// cancel the context if an error occurred
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cancel()
|
cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
// defer execution of release
|
// defer execution of release
|
||||||
g.pool.release(addr, cc, err)
|
g.pool.Put(cc, err)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// set the stream as the response
|
// set the stream as the response
|
||||||
val := reflect.ValueOf(rsp).Elem()
|
val := reflect.ValueOf(rsp).Elem()
|
||||||
val.Set(reflect.ValueOf(stream).Elem())
|
val.Set(reflect.ValueOf(stream).Elem())
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -319,6 +374,17 @@ func (g *grpcClient) newCodec(ct string) (codec.Codec, error) {
|
|||||||
return nil, codec.ErrUnknownContentType
|
return nil, codec.ErrUnknownContentType
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *grpcClient) serviceConfig() string {
|
||||||
|
if g.opts.Context == nil {
|
||||||
|
return DefaultServiceConfig
|
||||||
|
}
|
||||||
|
v := g.opts.Context.Value(serviceConfigKey{})
|
||||||
|
if v == nil {
|
||||||
|
return DefaultServiceConfig
|
||||||
|
}
|
||||||
|
return v.(string)
|
||||||
|
}
|
||||||
|
|
||||||
func (g *grpcClient) Init(opts ...client.Option) error {
|
func (g *grpcClient) Init(opts ...client.Option) error {
|
||||||
if len(opts) == 0 && g.init {
|
if len(opts) == 0 && g.init {
|
||||||
return nil
|
return nil
|
||||||
@@ -338,25 +404,17 @@ func (g *grpcClient) Init(opts ...client.Option) error {
|
|||||||
g.pool.Unlock()
|
g.pool.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := g.opts.Broker.Init(); err != nil {
|
g.funcCall = g.fnCall
|
||||||
return err
|
g.funcStream = g.fnStream
|
||||||
}
|
|
||||||
if err := g.opts.Tracer.Init(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := g.opts.Router.Init(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := g.opts.Logger.Init(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := g.opts.Meter.Init(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := g.opts.Transport.Init(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
|
g.opts.Hooks.EachPrev(func(hook options.Hook) {
|
||||||
|
switch h := hook.(type) {
|
||||||
|
case client.HookCall:
|
||||||
|
g.funcCall = h(g.funcCall)
|
||||||
|
case client.HookStream:
|
||||||
|
g.funcStream = h(g.funcStream)
|
||||||
|
}
|
||||||
|
})
|
||||||
g.init = true
|
g.init = true
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -366,10 +424,6 @@ func (g *grpcClient) Options() client.Options {
|
|||||||
return g.opts
|
return g.opts
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *grpcClient) NewMessage(topic string, msg interface{}, opts ...client.MessageOption) client.Message {
|
|
||||||
return newGRPCEvent(topic, msg, g.opts.ContentType, opts...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *grpcClient) NewRequest(service, method string, req interface{}, reqOpts ...client.RequestOption) client.Request {
|
func (g *grpcClient) NewRequest(service, method string, req interface{}, reqOpts ...client.RequestOption) client.Request {
|
||||||
return newGRPCRequest(service, method, req, g.opts.ContentType, reqOpts...)
|
return newGRPCRequest(service, method, req, g.opts.ContentType, reqOpts...)
|
||||||
}
|
}
|
||||||
@@ -380,8 +434,35 @@ func (g *grpcClient) Call(ctx context.Context, req client.Request, rsp interface
|
|||||||
} else if rsp == nil {
|
} else if rsp == nil {
|
||||||
return errors.InternalServerError("go.micro.client", "rsp is nil")
|
return errors.InternalServerError("go.micro.client", "rsp is nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ts := time.Now()
|
||||||
|
g.opts.Meter.Counter(semconv.ClientRequestInflight, "endpoint", req.Endpoint()).Inc()
|
||||||
|
var sp tracer.Span
|
||||||
|
ctx, sp = g.opts.Tracer.Start(ctx, req.Endpoint()+" rpc-client",
|
||||||
|
tracer.WithSpanKind(tracer.SpanKindClient),
|
||||||
|
tracer.WithSpanLabels("endpoint", req.Endpoint()),
|
||||||
|
)
|
||||||
|
err := g.funcCall(ctx, req, rsp, opts...)
|
||||||
|
g.opts.Meter.Counter(semconv.ClientRequestInflight, "endpoint", req.Endpoint()).Dec()
|
||||||
|
te := time.Since(ts)
|
||||||
|
g.opts.Meter.Summary(semconv.ClientRequestLatencyMicroseconds, "endpoint", req.Endpoint()).Update(te.Seconds())
|
||||||
|
g.opts.Meter.Histogram(semconv.ClientRequestDurationSeconds, "endpoint", req.Endpoint()).Update(te.Seconds())
|
||||||
|
|
||||||
|
if me := errors.FromError(err); me == nil {
|
||||||
|
sp.Finish()
|
||||||
|
g.opts.Meter.Counter(semconv.ClientRequestTotal, "endpoint", req.Endpoint(), "status", "success", "code", strconv.Itoa(int(200))).Inc()
|
||||||
|
} else {
|
||||||
|
sp.SetStatus(tracer.SpanStatusError, err.Error())
|
||||||
|
g.opts.Meter.Counter(semconv.ClientRequestTotal, "endpoint", req.Endpoint(), "status", "failure", "code", strconv.Itoa(int(me.Code))).Inc()
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *grpcClient) fnCall(ctx context.Context, req client.Request, rsp interface{}, opts ...client.CallOption) error {
|
||||||
// make a copy of call opts
|
// make a copy of call opts
|
||||||
callOpts := g.opts.CallOptions
|
callOpts := g.opts.CallOptions
|
||||||
|
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
opt(&callOpts)
|
opt(&callOpts)
|
||||||
}
|
}
|
||||||
@@ -410,11 +491,6 @@ func (g *grpcClient) Call(ctx context.Context, req client.Request, rsp interface
|
|||||||
// make copy of call method
|
// make copy of call method
|
||||||
gcall := g.call
|
gcall := g.call
|
||||||
|
|
||||||
// wrap the call in reverse
|
|
||||||
for i := len(callOpts.CallWrappers); i > 0; i-- {
|
|
||||||
gcall = callOpts.CallWrappers[i-1](gcall)
|
|
||||||
}
|
|
||||||
|
|
||||||
// use the router passed as a call option, or fallback to the rpc clients router
|
// use the router passed as a call option, or fallback to the rpc clients router
|
||||||
if callOpts.Router == nil {
|
if callOpts.Router == nil {
|
||||||
callOpts.Router = g.opts.Router
|
callOpts.Router = g.opts.Router
|
||||||
@@ -430,25 +506,13 @@ func (g *grpcClient) Call(ctx context.Context, req client.Request, rsp interface
|
|||||||
callOpts.Address = []string{g.opts.Proxy}
|
callOpts.Address = []string{g.opts.Proxy}
|
||||||
}
|
}
|
||||||
|
|
||||||
// lookup the route to send the reques to
|
var next selector.Next
|
||||||
// TODO apply any filtering here
|
|
||||||
routes, err := g.opts.Lookup(ctx, req, callOpts)
|
|
||||||
if err != nil {
|
|
||||||
return errors.InternalServerError("go.micro.client", err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
// balance the list of nodes
|
|
||||||
next, err := callOpts.Selector.Select(routes)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// return errors.New("go.micro.client", "request timeout", 408)
|
|
||||||
call := func(i int) error {
|
call := func(i int) error {
|
||||||
// call backoff first. Someone may want an initial start delay
|
// call backoff first. Someone may want an initial start delay
|
||||||
t, err := callOpts.Backoff(ctx, req, i)
|
t, err := callOpts.Backoff(ctx, req, i)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.InternalServerError("go.micro.client", err.Error())
|
return errors.InternalServerError("go.micro.client", "%+v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// only sleep if greater than 0
|
// only sleep if greater than 0
|
||||||
@@ -456,6 +520,23 @@ func (g *grpcClient) Call(ctx context.Context, req client.Request, rsp interface
|
|||||||
time.Sleep(t)
|
time.Sleep(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if next == nil {
|
||||||
|
var routes []string
|
||||||
|
|
||||||
|
// lookup the route to send the reques to
|
||||||
|
// TODO apply any filtering here
|
||||||
|
routes, err = g.opts.Lookup(ctx, req, callOpts)
|
||||||
|
if err != nil {
|
||||||
|
return errors.InternalServerError("go.micro.client", "%+v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// balance the list of nodes
|
||||||
|
next, err = callOpts.Selector.Select(routes)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// get the next node
|
// get the next node
|
||||||
node := next()
|
node := next()
|
||||||
|
|
||||||
@@ -509,6 +590,31 @@ func (g *grpcClient) Call(ctx context.Context, req client.Request, rsp interface
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *grpcClient) Stream(ctx context.Context, req client.Request, opts ...client.CallOption) (client.Stream, error) {
|
func (g *grpcClient) Stream(ctx context.Context, req client.Request, opts ...client.CallOption) (client.Stream, error) {
|
||||||
|
ts := time.Now()
|
||||||
|
g.opts.Meter.Counter(semconv.ClientRequestInflight, "endpoint", req.Endpoint()).Inc()
|
||||||
|
var sp tracer.Span
|
||||||
|
ctx, sp = g.opts.Tracer.Start(ctx, req.Endpoint()+" rpc-client",
|
||||||
|
tracer.WithSpanKind(tracer.SpanKindClient),
|
||||||
|
tracer.WithSpanLabels("endpoint", req.Endpoint()),
|
||||||
|
)
|
||||||
|
stream, err := g.funcStream(ctx, req, opts...)
|
||||||
|
g.opts.Meter.Counter(semconv.ClientRequestInflight, "endpoint", req.Endpoint()).Dec()
|
||||||
|
te := time.Since(ts)
|
||||||
|
g.opts.Meter.Summary(semconv.ClientRequestLatencyMicroseconds, "endpoint", req.Endpoint()).Update(te.Seconds())
|
||||||
|
g.opts.Meter.Histogram(semconv.ClientRequestDurationSeconds, "endpoint", req.Endpoint()).Update(te.Seconds())
|
||||||
|
|
||||||
|
if me := status.Convert(err); me == nil {
|
||||||
|
sp.Finish()
|
||||||
|
g.opts.Meter.Counter(semconv.ClientRequestTotal, "endpoint", req.Endpoint(), "status", "success", "code", strconv.Itoa(int(codes.OK))).Inc()
|
||||||
|
} else {
|
||||||
|
sp.SetStatus(tracer.SpanStatusError, err.Error())
|
||||||
|
g.opts.Meter.Counter(semconv.ClientRequestTotal, "endpoint", req.Endpoint(), "status", "failure", "code", strconv.Itoa(int(me.Code()))).Inc()
|
||||||
|
}
|
||||||
|
|
||||||
|
return stream, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *grpcClient) fnStream(ctx context.Context, req client.Request, opts ...client.CallOption) (client.Stream, error) {
|
||||||
// make a copy of call opts
|
// make a copy of call opts
|
||||||
callOpts := g.opts.CallOptions
|
callOpts := g.opts.CallOptions
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
@@ -527,11 +633,6 @@ func (g *grpcClient) Stream(ctx context.Context, req client.Request, opts ...cli
|
|||||||
// make a copy of stream
|
// make a copy of stream
|
||||||
gstream := g.stream
|
gstream := g.stream
|
||||||
|
|
||||||
// wrap the call in reverse
|
|
||||||
for i := len(callOpts.CallWrappers); i > 0; i-- {
|
|
||||||
gstream = callOpts.CallWrappers[i-1](gstream)
|
|
||||||
}
|
|
||||||
|
|
||||||
// use the router passed as a call option, or fallback to the rpc clients router
|
// use the router passed as a call option, or fallback to the rpc clients router
|
||||||
if callOpts.Router == nil {
|
if callOpts.Router == nil {
|
||||||
callOpts.Router = g.opts.Router
|
callOpts.Router = g.opts.Router
|
||||||
@@ -547,24 +648,13 @@ func (g *grpcClient) Stream(ctx context.Context, req client.Request, opts ...cli
|
|||||||
callOpts.Address = []string{g.opts.Proxy}
|
callOpts.Address = []string{g.opts.Proxy}
|
||||||
}
|
}
|
||||||
|
|
||||||
// lookup the route to send the reques to
|
var next selector.Next
|
||||||
// TODO: move to internal lookup func
|
|
||||||
routes, err := g.opts.Lookup(ctx, req, callOpts)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.InternalServerError("go.micro.client", err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
// balance the list of nodes
|
|
||||||
next, err := callOpts.Selector.Select(routes)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
call := func(i int) (client.Stream, error) {
|
call := func(i int) (client.Stream, error) {
|
||||||
// call backoff first. Someone may want an initial start delay
|
// call backoff first. Someone may want an initial start delay
|
||||||
t, err := callOpts.Backoff(ctx, req, i)
|
t, err := callOpts.Backoff(ctx, req, i)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.InternalServerError("go.micro.client", err.Error())
|
return nil, errors.InternalServerError("go.micro.client", "%+v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// only sleep if greater than 0
|
// only sleep if greater than 0
|
||||||
@@ -572,6 +662,23 @@ func (g *grpcClient) Stream(ctx context.Context, req client.Request, opts ...cli
|
|||||||
time.Sleep(t)
|
time.Sleep(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if next == nil {
|
||||||
|
var routes []string
|
||||||
|
|
||||||
|
// lookup the route to send the reques to
|
||||||
|
// TODO apply any filtering here
|
||||||
|
routes, err = g.opts.Lookup(ctx, req, callOpts)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.InternalServerError("go.micro.client", "%+v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// balance the list of nodes
|
||||||
|
next, err = callOpts.Selector.Select(routes)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// get the next node
|
// get the next node
|
||||||
node := next()
|
node := next()
|
||||||
|
|
||||||
@@ -635,48 +742,6 @@ func (g *grpcClient) Stream(ctx context.Context, req client.Request, opts ...cli
|
|||||||
return nil, grr
|
return nil, grr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *grpcClient) Publish(ctx context.Context, p client.Message, opts ...client.PublishOption) error {
|
|
||||||
var body []byte
|
|
||||||
|
|
||||||
options := client.NewPublishOptions(opts...)
|
|
||||||
|
|
||||||
md, ok := metadata.FromOutgoingContext(ctx)
|
|
||||||
if !ok {
|
|
||||||
md = metadata.New(2)
|
|
||||||
}
|
|
||||||
md["Content-Type"] = p.ContentType()
|
|
||||||
md["Micro-Topic"] = p.Topic()
|
|
||||||
|
|
||||||
// passed in raw data
|
|
||||||
if d, ok := p.Payload().(*codec.Frame); ok {
|
|
||||||
body = d.Data
|
|
||||||
} else {
|
|
||||||
// use codec for payload
|
|
||||||
cf, err := g.newCodec(p.ContentType())
|
|
||||||
if err != nil {
|
|
||||||
return errors.InternalServerError("go.micro.client", err.Error())
|
|
||||||
}
|
|
||||||
// set the body
|
|
||||||
b, err := cf.Marshal(p.Payload())
|
|
||||||
if err != nil {
|
|
||||||
return errors.InternalServerError("go.micro.client", err.Error())
|
|
||||||
}
|
|
||||||
body = b
|
|
||||||
}
|
|
||||||
|
|
||||||
topic := p.Topic()
|
|
||||||
|
|
||||||
// get the exchange
|
|
||||||
if len(options.Exchange) > 0 {
|
|
||||||
topic = options.Exchange
|
|
||||||
}
|
|
||||||
|
|
||||||
return g.opts.Broker.Publish(metadata.NewOutgoingContext(ctx, md), topic, &broker.Message{
|
|
||||||
Header: md,
|
|
||||||
Body: body,
|
|
||||||
}, broker.PublishContext(options.Context))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *grpcClient) String() string {
|
func (g *grpcClient) String() string {
|
||||||
return "grpc"
|
return "grpc"
|
||||||
}
|
}
|
||||||
@@ -685,41 +750,45 @@ func (g *grpcClient) Name() string {
|
|||||||
return g.opts.Name
|
return g.opts.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *grpcClient) getGrpcDialOptions() []grpc.DialOption {
|
func (g *grpcClient) getGrpcDialOptions(ctx context.Context) []grpc.DialOption {
|
||||||
if g.opts.CallOptions.Context == nil {
|
var opts []grpc.DialOption
|
||||||
return nil
|
|
||||||
|
if g.opts.CallOptions.Context != nil {
|
||||||
|
if v := g.opts.CallOptions.Context.Value(grpcDialOptions{}); v != nil {
|
||||||
|
if vopts, ok := v.([]grpc.DialOption); ok {
|
||||||
|
opts = append(opts, vopts...)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
v := g.opts.CallOptions.Context.Value(grpcDialOptions{})
|
if ctx != nil {
|
||||||
|
if v := ctx.Value(grpcDialOptions{}); v != nil {
|
||||||
if v == nil {
|
if vopts, ok := v.([]grpc.DialOption); ok {
|
||||||
return nil
|
opts = append(opts, vopts...)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
opts, ok := v.([]grpc.DialOption)
|
|
||||||
|
|
||||||
if !ok {
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return opts
|
return opts
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *grpcClient) getGrpcCallOptions() []grpc.CallOption {
|
func (g *grpcClient) getGrpcCallOptions(ctx context.Context) []grpc.CallOption {
|
||||||
if g.opts.CallOptions.Context == nil {
|
var opts []grpc.CallOption
|
||||||
return nil
|
|
||||||
|
if g.opts.CallOptions.Context != nil {
|
||||||
|
if v := g.opts.CallOptions.Context.Value(grpcCallOptions{}); v != nil {
|
||||||
|
if vopts, ok := v.([]grpc.CallOption); ok {
|
||||||
|
opts = append(opts, vopts...)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
v := g.opts.CallOptions.Context.Value(grpcCallOptions{})
|
if ctx != nil {
|
||||||
|
if v := ctx.Value(grpcCallOptions{}); v != nil {
|
||||||
if v == nil {
|
if vopts, ok := v.([]grpc.CallOption); ok {
|
||||||
return nil
|
opts = append(opts, vopts...)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
opts, ok := v.([]grpc.CallOption)
|
|
||||||
|
|
||||||
if !ok {
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return opts
|
return opts
|
||||||
@@ -728,25 +797,20 @@ func (g *grpcClient) getGrpcCallOptions() []grpc.CallOption {
|
|||||||
func NewClient(opts ...client.Option) client.Client {
|
func NewClient(opts ...client.Option) client.Client {
|
||||||
options := client.NewOptions(opts...)
|
options := client.NewOptions(opts...)
|
||||||
// default content type for grpc
|
// default content type for grpc
|
||||||
options.ContentType = "application/grpc+proto"
|
if options.ContentType == "" {
|
||||||
|
options.ContentType = DefaultContentType
|
||||||
|
}
|
||||||
|
|
||||||
rc := &grpcClient{
|
c := &grpcClient{
|
||||||
opts: options,
|
opts: options,
|
||||||
}
|
}
|
||||||
|
|
||||||
rc.pool = newPool(options.PoolSize, options.PoolTTL, rc.poolMaxIdle(), rc.poolMaxStreams())
|
c.pool = NewConnPool(options.PoolSize, options.PoolTTL, c.poolMaxIdle(), c.poolMaxStreams())
|
||||||
|
|
||||||
c := client.Client(rc)
|
if c.opts.Context != nil {
|
||||||
|
if codecs, ok := c.opts.Context.Value(codecsKey{}).(map[string]encoding.Codec); ok && codecs != nil {
|
||||||
// wrap in reverse
|
|
||||||
for i := len(options.Wrappers); i > 0; i-- {
|
|
||||||
c = options.Wrappers[i-1](c)
|
|
||||||
}
|
|
||||||
|
|
||||||
if rc.opts.Context != nil {
|
|
||||||
if codecs, ok := rc.opts.Context.Value(codecsKey{}).(map[string]encoding.Codec); ok && codecs != nil {
|
|
||||||
for k, v := range codecs {
|
for k, v := range codecs {
|
||||||
rc.opts.Codecs[k] = &wrapGrpcCodec{v}
|
c.opts.Codecs[k] = &wrapGrpcCodec{v}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -755,5 +819,8 @@ func NewClient(opts ...client.Option) client.Client {
|
|||||||
encoding.RegisterCodec(&wrapMicroCodec{k})
|
encoding.RegisterCodec(&wrapMicroCodec{k})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c.funcCall = c.fnCall
|
||||||
|
c.funcStream = c.fnStream
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
63
grpc_pool.go
63
grpc_pool.go
@@ -2,6 +2,7 @@ package grpc
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -9,56 +10,47 @@ import (
|
|||||||
"google.golang.org/grpc/connectivity"
|
"google.golang.org/grpc/connectivity"
|
||||||
)
|
)
|
||||||
|
|
||||||
type pool struct {
|
type ConnPool struct {
|
||||||
size int
|
conns map[string]*streamsPool
|
||||||
ttl int64
|
size int
|
||||||
|
ttl int64
|
||||||
// max streams on a *poolConn
|
|
||||||
maxStreams int
|
maxStreams int
|
||||||
// max idle conns
|
maxIdle int
|
||||||
maxIdle int
|
|
||||||
|
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
conns map[string]*streamsPool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type streamsPool struct {
|
type streamsPool struct {
|
||||||
// head of list
|
// head of list
|
||||||
head *poolConn
|
head *PoolConn
|
||||||
// busy conns list
|
// busy conns list
|
||||||
busy *poolConn
|
busy *PoolConn
|
||||||
// the siza of list
|
// the siza of list
|
||||||
count int
|
count int
|
||||||
// idle conn
|
// idle conn
|
||||||
idle int
|
idle int
|
||||||
}
|
}
|
||||||
|
|
||||||
type poolConn struct {
|
type PoolConn struct {
|
||||||
// grpc conn
|
err error
|
||||||
*grpc.ClientConn
|
*grpc.ClientConn
|
||||||
err error
|
next *PoolConn
|
||||||
addr string
|
pool *ConnPool
|
||||||
|
|
||||||
// pool and streams pool
|
|
||||||
pool *pool
|
|
||||||
sp *streamsPool
|
sp *streamsPool
|
||||||
|
pre *PoolConn
|
||||||
|
addr string
|
||||||
streams int
|
streams int
|
||||||
created int64
|
created int64
|
||||||
|
in bool
|
||||||
// list
|
|
||||||
pre *poolConn
|
|
||||||
next *poolConn
|
|
||||||
in bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newPool(size int, ttl time.Duration, idle int, ms int) *pool {
|
func NewConnPool(size int, ttl time.Duration, idle int, ms int) *ConnPool {
|
||||||
if ms <= 0 {
|
if ms <= 0 {
|
||||||
ms = 1
|
ms = 1
|
||||||
}
|
}
|
||||||
if idle < 0 {
|
if idle < 0 {
|
||||||
idle = 0
|
idle = 0
|
||||||
}
|
}
|
||||||
return &pool{
|
return &ConnPool{
|
||||||
size: size,
|
size: size,
|
||||||
ttl: int64(ttl.Seconds()),
|
ttl: int64(ttl.Seconds()),
|
||||||
maxStreams: ms,
|
maxStreams: ms,
|
||||||
@@ -67,12 +59,15 @@ func newPool(size int, ttl time.Duration, idle int, ms int) *pool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *pool) getConn(ctx context.Context, addr string, opts ...grpc.DialOption) (*poolConn, error) {
|
func (p *ConnPool) Get(ctx context.Context, addr string, opts ...grpc.DialOption) (*PoolConn, error) {
|
||||||
|
if strings.HasPrefix(addr, "http") {
|
||||||
|
addr = addr[strings.Index(addr, ":")+3:]
|
||||||
|
}
|
||||||
now := time.Now().Unix()
|
now := time.Now().Unix()
|
||||||
p.Lock()
|
p.Lock()
|
||||||
sp, ok := p.conns[addr]
|
sp, ok := p.conns[addr]
|
||||||
if !ok {
|
if !ok {
|
||||||
sp = &streamsPool{head: &poolConn{}, busy: &poolConn{}, count: 0, idle: 0}
|
sp = &streamsPool{head: &PoolConn{}, busy: &PoolConn{}, count: 0, idle: 0}
|
||||||
p.conns[addr] = sp
|
p.conns[addr] = sp
|
||||||
}
|
}
|
||||||
// while we have conns check streams and then return one
|
// while we have conns check streams and then return one
|
||||||
@@ -135,12 +130,12 @@ func (p *pool) getConn(ctx context.Context, addr string, opts ...grpc.DialOption
|
|||||||
}
|
}
|
||||||
p.Unlock()
|
p.Unlock()
|
||||||
|
|
||||||
// create new conn
|
// nolint (TODO need fix) create new conn)
|
||||||
cc, err := grpc.DialContext(ctx, addr, opts...)
|
cc, err := grpc.DialContext(ctx, addr, opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
conn = &poolConn{cc, nil, addr, p, sp, 1, time.Now().Unix(), nil, nil, false}
|
conn = &PoolConn{ClientConn: cc, err: nil, addr: addr, pool: p, sp: sp, streams: 1, created: time.Now().Unix(), pre: nil, next: nil, in: false}
|
||||||
|
|
||||||
// add conn to streams pool
|
// add conn to streams pool
|
||||||
p.Lock()
|
p.Lock()
|
||||||
@@ -152,7 +147,7 @@ func (p *pool) getConn(ctx context.Context, addr string, opts ...grpc.DialOption
|
|||||||
return conn, nil
|
return conn, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *pool) release(addr string, conn *poolConn, err error) {
|
func (p *ConnPool) Put(conn *PoolConn, err error) {
|
||||||
p.Lock()
|
p.Lock()
|
||||||
p, sp, created := conn.pool, conn.sp, conn.created
|
p, sp, created := conn.pool, conn.sp, conn.created
|
||||||
// try to add conn
|
// try to add conn
|
||||||
@@ -187,11 +182,11 @@ func (p *pool) release(addr string, conn *poolConn, err error) {
|
|||||||
p.Unlock()
|
p.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (conn *poolConn) Close() {
|
func (conn *PoolConn) Close() {
|
||||||
conn.pool.release(conn.addr, conn, conn.err)
|
conn.pool.Put(conn, conn.err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func removeConn(conn *poolConn) {
|
func removeConn(conn *PoolConn) {
|
||||||
if conn.pre != nil {
|
if conn.pre != nil {
|
||||||
conn.pre.next = conn.next
|
conn.pre.next = conn.next
|
||||||
}
|
}
|
||||||
@@ -204,7 +199,7 @@ func removeConn(conn *poolConn) {
|
|||||||
conn.sp.count--
|
conn.sp.count--
|
||||||
}
|
}
|
||||||
|
|
||||||
func addConnAfter(conn *poolConn, after *poolConn) {
|
func addConnAfter(conn *PoolConn, after *PoolConn) {
|
||||||
conn.next = after.next
|
conn.next = after.next
|
||||||
conn.pre = after
|
conn.pre = after
|
||||||
if after.next != nil {
|
if after.next != nil {
|
||||||
|
40
message.go
40
message.go
@@ -1,40 +0,0 @@
|
|||||||
package grpc
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/unistack-org/micro/v3/client"
|
|
||||||
)
|
|
||||||
|
|
||||||
type grpcEvent struct {
|
|
||||||
topic string
|
|
||||||
contentType string
|
|
||||||
payload interface{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func newGRPCEvent(topic string, payload interface{}, contentType string, opts ...client.MessageOption) client.Message {
|
|
||||||
var options client.MessageOptions
|
|
||||||
for _, o := range opts {
|
|
||||||
o(&options)
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(options.ContentType) > 0 {
|
|
||||||
contentType = options.ContentType
|
|
||||||
}
|
|
||||||
|
|
||||||
return &grpcEvent{
|
|
||||||
payload: payload,
|
|
||||||
topic: topic,
|
|
||||||
contentType: contentType,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *grpcEvent) ContentType() string {
|
|
||||||
return g.contentType
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *grpcEvent) Topic() string {
|
|
||||||
return g.topic
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *grpcEvent) Payload() interface{} {
|
|
||||||
return g.payload
|
|
||||||
}
|
|
58
options.go
58
options.go
@@ -3,15 +3,14 @@ package grpc
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/tls"
|
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/client"
|
"go.unistack.org/micro/v4/client"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
"google.golang.org/grpc/encoding"
|
"google.golang.org/grpc/encoding"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// DefaultPoolMaxStreams maximum streams on a connectioin
|
// DefaultPoolMaxStreams maximum streams on a connection
|
||||||
// (20)
|
// (20)
|
||||||
DefaultPoolMaxStreams = 20
|
DefaultPoolMaxStreams = 20
|
||||||
|
|
||||||
@@ -26,16 +25,12 @@ var (
|
|||||||
// DefaultMaxSendMsgSize maximum message that client can send
|
// DefaultMaxSendMsgSize maximum message that client can send
|
||||||
// (4 MB).
|
// (4 MB).
|
||||||
DefaultMaxSendMsgSize = 1024 * 1024 * 4
|
DefaultMaxSendMsgSize = 1024 * 1024 * 4
|
||||||
|
|
||||||
|
// DefaultServiceConfig enable load balancing
|
||||||
|
DefaultServiceConfig = `{"loadBalancingPolicy":"round_robin"}`
|
||||||
)
|
)
|
||||||
|
|
||||||
type poolMaxStreams struct{}
|
type poolMaxStreams struct{}
|
||||||
type poolMaxIdle struct{}
|
|
||||||
type codecsKey struct{}
|
|
||||||
type tlsAuth struct{}
|
|
||||||
type maxRecvMsgSizeKey struct{}
|
|
||||||
type maxSendMsgSizeKey struct{}
|
|
||||||
type grpcDialOptions struct{}
|
|
||||||
type grpcCallOptions struct{}
|
|
||||||
|
|
||||||
// maximum streams on a connectioin
|
// maximum streams on a connectioin
|
||||||
func PoolMaxStreams(n int) client.Option {
|
func PoolMaxStreams(n int) client.Option {
|
||||||
@@ -47,6 +42,8 @@ func PoolMaxStreams(n int) client.Option {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type poolMaxIdle struct{}
|
||||||
|
|
||||||
// maximum idle conns of a pool
|
// maximum idle conns of a pool
|
||||||
func PoolMaxIdle(d int) client.Option {
|
func PoolMaxIdle(d int) client.Option {
|
||||||
return func(o *client.Options) {
|
return func(o *client.Options) {
|
||||||
@@ -57,6 +54,8 @@ func PoolMaxIdle(d int) client.Option {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type codecsKey struct{}
|
||||||
|
|
||||||
// gRPC Codec to be used to encode/decode requests for a given content type
|
// gRPC Codec to be used to encode/decode requests for a given content type
|
||||||
func Codec(contentType string, c encoding.Codec) client.Option {
|
func Codec(contentType string, c encoding.Codec) client.Option {
|
||||||
return func(o *client.Options) {
|
return func(o *client.Options) {
|
||||||
@@ -72,19 +71,9 @@ func Codec(contentType string, c encoding.Codec) client.Option {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// AuthTLS should be used to setup a secure authentication using TLS
|
type maxRecvMsgSizeKey struct{}
|
||||||
func AuthTLS(t *tls.Config) client.Option {
|
|
||||||
return func(o *client.Options) {
|
|
||||||
if o.Context == nil {
|
|
||||||
o.Context = context.Background()
|
|
||||||
}
|
|
||||||
o.Context = context.WithValue(o.Context, tlsAuth{}, t)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// MaxRecvMsgSize set the maximum size of message that client can receive.
|
// MaxRecvMsgSize set the maximum size of message that client can receive.
|
||||||
//
|
|
||||||
func MaxRecvMsgSize(s int) client.Option {
|
func MaxRecvMsgSize(s int) client.Option {
|
||||||
return func(o *client.Options) {
|
return func(o *client.Options) {
|
||||||
if o.Context == nil {
|
if o.Context == nil {
|
||||||
@@ -94,9 +83,9 @@ func MaxRecvMsgSize(s int) client.Option {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
type maxSendMsgSizeKey struct{}
|
||||||
|
|
||||||
// MaxSendMsgSize set the maximum size of message that client can send.
|
// MaxSendMsgSize set the maximum size of message that client can send.
|
||||||
//
|
|
||||||
func MaxSendMsgSize(s int) client.Option {
|
func MaxSendMsgSize(s int) client.Option {
|
||||||
return func(o *client.Options) {
|
return func(o *client.Options) {
|
||||||
if o.Context == nil {
|
if o.Context == nil {
|
||||||
@@ -106,11 +95,11 @@ func MaxSendMsgSize(s int) client.Option {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
type grpcDialOptions struct{}
|
||||||
|
|
||||||
// DialOptions to be used to configure gRPC dial options
|
// DialOptions to be used to configure gRPC dial options
|
||||||
//
|
func DialOptions(opts ...grpc.DialOption) client.Option {
|
||||||
func DialOptions(opts ...grpc.DialOption) client.CallOption {
|
return func(o *client.Options) {
|
||||||
return func(o *client.CallOptions) {
|
|
||||||
if o.Context == nil {
|
if o.Context == nil {
|
||||||
o.Context = context.Background()
|
o.Context = context.Background()
|
||||||
}
|
}
|
||||||
@@ -118,9 +107,9 @@ func DialOptions(opts ...grpc.DialOption) client.CallOption {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
type grpcCallOptions struct{}
|
||||||
|
|
||||||
// CallOptions to be used to configure gRPC call options
|
// CallOptions to be used to configure gRPC call options
|
||||||
//
|
|
||||||
func CallOptions(opts ...grpc.CallOption) client.CallOption {
|
func CallOptions(opts ...grpc.CallOption) client.CallOption {
|
||||||
return func(o *client.CallOptions) {
|
return func(o *client.CallOptions) {
|
||||||
if o.Context == nil {
|
if o.Context == nil {
|
||||||
@@ -129,3 +118,14 @@ func CallOptions(opts ...grpc.CallOption) client.CallOption {
|
|||||||
o.Context = context.WithValue(o.Context, grpcCallOptions{}, opts)
|
o.Context = context.WithValue(o.Context, grpcCallOptions{}, opts)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type serviceConfigKey struct{}
|
||||||
|
|
||||||
|
func ServiceConfig(str string) client.CallOption {
|
||||||
|
return func(options *client.CallOptions) {
|
||||||
|
if options.Context == nil {
|
||||||
|
options.Context = context.Background()
|
||||||
|
}
|
||||||
|
options.Context = context.WithValue(options.Context, serviceConfigKey{}, str)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
21
request.go
21
request.go
@@ -4,17 +4,17 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/client"
|
"go.unistack.org/micro/v4/client"
|
||||||
"github.com/unistack-org/micro/v3/codec"
|
"go.unistack.org/micro/v4/codec"
|
||||||
)
|
)
|
||||||
|
|
||||||
type grpcRequest struct {
|
type grpcRequest struct {
|
||||||
|
request interface{}
|
||||||
|
codec codec.Codec
|
||||||
service string
|
service string
|
||||||
method string
|
method string
|
||||||
contentType string
|
contentType string
|
||||||
request interface{}
|
|
||||||
opts client.RequestOptions
|
opts client.RequestOptions
|
||||||
codec codec.Codec
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// service Struct.Method /service.Struct/Method
|
// service Struct.Method /service.Struct/Method
|
||||||
@@ -38,15 +38,12 @@ func methodToGRPC(service, method string) string {
|
|||||||
return fmt.Sprintf("/%s.%s/%s", service, mParts[0], mParts[1])
|
return fmt.Sprintf("/%s.%s/%s", service, mParts[0], mParts[1])
|
||||||
}
|
}
|
||||||
|
|
||||||
func newGRPCRequest(service, method string, request interface{}, contentType string, reqOpts ...client.RequestOption) client.Request {
|
func newGRPCRequest(service, method string, request interface{}, contentType string, opts ...client.RequestOption) client.Request {
|
||||||
var opts client.RequestOptions
|
options := client.NewRequestOptions(opts...)
|
||||||
for _, o := range reqOpts {
|
|
||||||
o(&opts)
|
|
||||||
}
|
|
||||||
|
|
||||||
// set the content-type specified
|
// set the content-type specified
|
||||||
if len(opts.ContentType) > 0 {
|
if len(options.ContentType) > 0 {
|
||||||
contentType = opts.ContentType
|
contentType = options.ContentType
|
||||||
}
|
}
|
||||||
|
|
||||||
return &grpcRequest{
|
return &grpcRequest{
|
||||||
@@ -54,7 +51,7 @@ func newGRPCRequest(service, method string, request interface{}, contentType str
|
|||||||
method: method,
|
method: method,
|
||||||
request: request,
|
request: request,
|
||||||
contentType: contentType,
|
contentType: contentType,
|
||||||
opts: opts,
|
opts: options,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
23
response.go
23
response.go
@@ -1,15 +1,13 @@
|
|||||||
package grpc
|
package grpc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
"go.unistack.org/micro/v4/codec"
|
||||||
|
"go.unistack.org/micro/v4/metadata"
|
||||||
"github.com/unistack-org/micro/v3/codec"
|
|
||||||
"github.com/unistack-org/micro/v3/metadata"
|
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
type response struct {
|
type response struct {
|
||||||
conn *poolConn
|
conn *PoolConn
|
||||||
stream grpc.ClientStream
|
stream grpc.ClientStream
|
||||||
codec codec.Codec
|
codec codec.Codec
|
||||||
}
|
}
|
||||||
@@ -23,20 +21,21 @@ func (r *response) Codec() codec.Codec {
|
|||||||
func (r *response) Header() metadata.Metadata {
|
func (r *response) Header() metadata.Metadata {
|
||||||
meta, err := r.stream.Header()
|
meta, err := r.stream.Header()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return metadata.New(0)
|
return nil
|
||||||
}
|
}
|
||||||
md := metadata.New(len(meta))
|
|
||||||
for k, v := range meta {
|
return metadata.Metadata(meta.Copy())
|
||||||
md.Set(k, strings.Join(v, ","))
|
|
||||||
}
|
|
||||||
return md
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read the undecoded response
|
// Read the undecoded response
|
||||||
func (r *response) Read() ([]byte, error) {
|
func (r *response) Read() ([]byte, error) {
|
||||||
f := &codec.Frame{}
|
f := &codec.Frame{}
|
||||||
if err := r.codec.ReadBody(&wrapStream{r.stream}, f); err != nil {
|
wrap := &wrapStream{r.stream}
|
||||||
|
|
||||||
|
_, err := wrap.Read(f.Data)
|
||||||
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return f.Data, nil
|
return f.Data, nil
|
||||||
}
|
}
|
||||||
|
59
stream.go
59
stream.go
@@ -5,23 +5,22 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/client"
|
"go.unistack.org/micro/v4/client"
|
||||||
|
"go.unistack.org/micro/v4/tracer"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Implements the streamer interface
|
// Implements the streamer interface
|
||||||
type grpcStream struct {
|
type grpcStream struct {
|
||||||
// embed so we can access if need be
|
|
||||||
grpc.ClientStream
|
grpc.ClientStream
|
||||||
|
context context.Context
|
||||||
sync.RWMutex
|
|
||||||
closed bool
|
|
||||||
err error
|
err error
|
||||||
conn *poolConn
|
|
||||||
request client.Request
|
request client.Request
|
||||||
response client.Response
|
response client.Response
|
||||||
context context.Context
|
|
||||||
close func(err error)
|
close func(err error)
|
||||||
|
conn *PoolConn
|
||||||
|
sync.RWMutex
|
||||||
|
closed bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *grpcStream) Context() context.Context {
|
func (g *grpcStream) Context() context.Context {
|
||||||
@@ -44,6 +43,14 @@ func (g *grpcStream) Send(msg interface{}) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *grpcStream) SendMsg(msg interface{}) error {
|
||||||
|
if err := g.ClientStream.SendMsg(msg); err != nil {
|
||||||
|
g.setError(err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (g *grpcStream) Recv(msg interface{}) (err error) {
|
func (g *grpcStream) Recv(msg interface{}) (err error) {
|
||||||
defer g.setError(err)
|
defer g.setError(err)
|
||||||
|
|
||||||
@@ -62,6 +69,24 @@ func (g *grpcStream) Recv(msg interface{}) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *grpcStream) RecvMsg(msg interface{}) (err error) {
|
||||||
|
defer g.setError(err)
|
||||||
|
|
||||||
|
if err = g.ClientStream.RecvMsg(msg); err != nil {
|
||||||
|
// #202 - inconsistent gRPC stream behavior
|
||||||
|
// the only way to tell if the stream is done is when we get a EOF on the Recv
|
||||||
|
// here we should close the underlying gRPC ClientConn
|
||||||
|
closeErr := g.Close()
|
||||||
|
if err == io.EOF && closeErr != nil {
|
||||||
|
err = closeErr
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (g *grpcStream) Error() error {
|
func (g *grpcStream) Error() error {
|
||||||
g.RLock()
|
g.RLock()
|
||||||
defer g.RUnlock()
|
defer g.RUnlock()
|
||||||
@@ -87,6 +112,26 @@ func (g *grpcStream) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if sp, ok := tracer.SpanFromContext(g.context); ok && sp != nil {
|
||||||
|
if g.err != nil {
|
||||||
|
sp.SetStatus(tracer.SpanStatusError, g.err.Error())
|
||||||
|
}
|
||||||
|
sp.Finish()
|
||||||
|
}
|
||||||
|
// close the connection
|
||||||
|
g.closed = true
|
||||||
|
g.close(g.err)
|
||||||
|
return g.ClientStream.CloseSend()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *grpcStream) CloseSend() error {
|
||||||
|
g.Lock()
|
||||||
|
defer g.Unlock()
|
||||||
|
|
||||||
|
if g.closed {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// close the connection
|
// close the connection
|
||||||
g.closed = true
|
g.closed = true
|
||||||
g.close(g.err)
|
g.close(g.err)
|
||||||
|
Reference in New Issue
Block a user