Compare commits
25 Commits
Author | SHA1 | Date | |
---|---|---|---|
03355d0d83 | |||
15e7f6bd16 | |||
a2da7d4ceb | |||
211999bb04 | |||
59ffe0f3ea | |||
378c00c16d | |||
|
4f0a7e0c93 | ||
8844f01558 | |||
7c25072247 | |||
65151b3e3e | |||
ad0fd42945 | |||
|
8ecb705550 | ||
|
225887fef8 | ||
41e32e36b3 | |||
e6b8324395 | |||
2da3760acb | |||
6e47e59542 | |||
fc716500c4 | |||
|
8d8d570880 | ||
ed7ae1c518 | |||
3e6e9eb469 | |||
26370e69f2 | |||
c996b37985 | |||
d63381e584 | |||
|
a231083367 |
20
.github/workflows/autoapprove.yml
vendored
Normal file
20
.github/workflows/autoapprove.yml
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
name: "autoapprove"
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request_target:
|
||||||
|
types: [assigned, opened, synchronize, reopened]
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
pull-requests: write
|
||||||
|
contents: write
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
autoapprove:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: approve
|
||||||
|
uses: hmarr/auto-approve-action@v2
|
||||||
|
if: github.actor == 'vtolstov' || github.actor == 'dependabot[bot]'
|
||||||
|
id: approve
|
||||||
|
with:
|
||||||
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
21
.github/workflows/automerge.yml
vendored
Normal file
21
.github/workflows/automerge.yml
vendored
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
name: "automerge"
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request_target:
|
||||||
|
types: [assigned, opened, synchronize, reopened]
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
pull-requests: write
|
||||||
|
contents: write
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
automerge:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
if: github.actor == 'vtolstov'
|
||||||
|
steps:
|
||||||
|
- name: merge
|
||||||
|
id: merge
|
||||||
|
run: gh pr merge --auto --merge "$PR_URL"
|
||||||
|
env:
|
||||||
|
PR_URL: ${{github.event.pull_request.html_url}}
|
||||||
|
GITHUB_TOKEN: ${{secrets.TOKEN}}
|
9
.github/workflows/build.yml
vendored
9
.github/workflows/build.yml
vendored
@@ -3,6 +3,7 @@ on:
|
|||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- master
|
- master
|
||||||
|
- v3
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
name: test
|
name: test
|
||||||
@@ -11,9 +12,9 @@ jobs:
|
|||||||
- name: setup
|
- name: setup
|
||||||
uses: actions/setup-go@v2
|
uses: actions/setup-go@v2
|
||||||
with:
|
with:
|
||||||
go-version: 1.16
|
go-version: 1.17
|
||||||
- name: checkout
|
- name: checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
- name: cache
|
- name: cache
|
||||||
uses: actions/cache@v2
|
uses: actions/cache@v2
|
||||||
with:
|
with:
|
||||||
@@ -31,9 +32,9 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: checkout
|
- name: checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
- name: lint
|
- name: lint
|
||||||
uses: golangci/golangci-lint-action@v2
|
uses: golangci/golangci-lint-action@v3.1.0
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
with:
|
with:
|
||||||
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
|
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
|
||||||
|
23
.github/workflows/codeql-analysis.yml
vendored
23
.github/workflows/codeql-analysis.yml
vendored
@@ -9,7 +9,7 @@
|
|||||||
# the `language` matrix defined below to confirm you have the correct set of
|
# the `language` matrix defined below to confirm you have the correct set of
|
||||||
# supported CodeQL languages.
|
# supported CodeQL languages.
|
||||||
#
|
#
|
||||||
name: "CodeQL"
|
name: "codeql"
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_run:
|
workflow_run:
|
||||||
@@ -17,16 +17,16 @@ on:
|
|||||||
types:
|
types:
|
||||||
- completed
|
- completed
|
||||||
push:
|
push:
|
||||||
branches: [ master ]
|
branches: [ master, v3 ]
|
||||||
pull_request:
|
pull_request:
|
||||||
# The branches below must be a subset of the branches above
|
# The branches below must be a subset of the branches above
|
||||||
branches: [ master ]
|
branches: [ master, v3 ]
|
||||||
schedule:
|
schedule:
|
||||||
- cron: '34 1 * * 0'
|
- cron: '34 1 * * 0'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
analyze:
|
analyze:
|
||||||
name: Analyze
|
name: analyze
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
permissions:
|
permissions:
|
||||||
actions: read
|
actions: read
|
||||||
@@ -42,11 +42,14 @@ jobs:
|
|||||||
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
|
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
|
- name: setup
|
||||||
|
uses: actions/setup-go@v2
|
||||||
|
with:
|
||||||
|
go-version: 1.17
|
||||||
# Initializes the CodeQL tools for scanning.
|
# Initializes the CodeQL tools for scanning.
|
||||||
- name: Initialize CodeQL
|
- name: init
|
||||||
uses: github/codeql-action/init@v1
|
uses: github/codeql-action/init@v1
|
||||||
with:
|
with:
|
||||||
languages: ${{ matrix.language }}
|
languages: ${{ matrix.language }}
|
||||||
@@ -57,7 +60,7 @@ jobs:
|
|||||||
|
|
||||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||||
# If this step fails, then you should remove it and run the build manually (see below)
|
# If this step fails, then you should remove it and run the build manually (see below)
|
||||||
- name: Autobuild
|
- name: autobuild
|
||||||
uses: github/codeql-action/autobuild@v1
|
uses: github/codeql-action/autobuild@v1
|
||||||
|
|
||||||
# ℹ️ Command-line programs to run using the OS shell.
|
# ℹ️ Command-line programs to run using the OS shell.
|
||||||
@@ -71,5 +74,5 @@ jobs:
|
|||||||
# make bootstrap
|
# make bootstrap
|
||||||
# make release
|
# make release
|
||||||
|
|
||||||
- name: Perform CodeQL Analysis
|
- name: analyze
|
||||||
uses: github/codeql-action/analyze@v1
|
uses: github/codeql-action/analyze@v1
|
||||||
|
73
.github/workflows/dependabot-automerge.yml
vendored
73
.github/workflows/dependabot-automerge.yml
vendored
@@ -1,66 +1,27 @@
|
|||||||
name: "prautomerge"
|
name: "dependabot-automerge"
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_run:
|
pull_request_target:
|
||||||
workflows: ["prbuild"]
|
types: [assigned, opened, synchronize, reopened]
|
||||||
types:
|
|
||||||
- completed
|
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: write
|
|
||||||
pull-requests: write
|
pull-requests: write
|
||||||
|
contents: write
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
Dependabot-Automerge:
|
automerge:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
# Contains workaround to execute if dependabot updates the PR by checking for the base branch in the linked PR
|
if: github.actor == 'dependabot[bot]'
|
||||||
# The the github.event.workflow_run.event value is 'push' and not 'pull_request'
|
|
||||||
# dont work with multiple workflows when last returns success
|
|
||||||
if: >-
|
|
||||||
github.event.workflow_run.conclusion == 'success'
|
|
||||||
&& github.actor == 'dependabot[bot]'
|
|
||||||
&& github.event.sender.login == 'dependabot[bot]'
|
|
||||||
&& github.event.sender.type == 'Bot'
|
|
||||||
&& (github.event.workflow_run.event == 'pull_request'
|
|
||||||
|| (github.event.workflow_run.event == 'push' && github.event.workflow_run.pull_requests[0].base.ref == github.event.repository.default_branch ))
|
|
||||||
steps:
|
steps:
|
||||||
- name: Approve Changes and Merge changes if label 'dependencies' is set
|
- name: metadata
|
||||||
uses: actions/github-script@v5
|
id: metadata
|
||||||
|
uses: dependabot/fetch-metadata@v1.3.0
|
||||||
with:
|
with:
|
||||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
github-token: "${{ secrets.TOKEN }}"
|
||||||
script: |
|
- name: merge
|
||||||
console.log(context.payload.workflow_run);
|
id: merge
|
||||||
|
if: ${{contains(steps.metadata.outputs.dependency-names, 'go.unistack.org')}}
|
||||||
var labelNames = await github.paginate(
|
run: gh pr merge --auto --merge "$PR_URL"
|
||||||
github.issues.listLabelsOnIssue,
|
env:
|
||||||
{
|
PR_URL: ${{github.event.pull_request.html_url}}
|
||||||
repo: context.repo.repo,
|
GITHUB_TOKEN: ${{secrets.TOKEN}}
|
||||||
owner: context.repo.owner,
|
|
||||||
issue_number: context.payload.workflow_run.pull_requests[0].number,
|
|
||||||
},
|
|
||||||
(response) => response.data.map(
|
|
||||||
(label) => label.name
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
console.log(labelNames);
|
|
||||||
|
|
||||||
if (labelNames.includes('dependencies')) {
|
|
||||||
console.log('Found label');
|
|
||||||
|
|
||||||
await github.pulls.createReview({
|
|
||||||
repo: context.repo.repo,
|
|
||||||
owner: context.repo.owner,
|
|
||||||
pull_number: context.payload.workflow_run.pull_requests[0].number,
|
|
||||||
event: 'APPROVE'
|
|
||||||
});
|
|
||||||
console.log('Approved PR');
|
|
||||||
|
|
||||||
await github.pulls.merge({
|
|
||||||
repo: context.repo.repo,
|
|
||||||
owner: context.repo.owner,
|
|
||||||
pull_number: context.payload.workflow_run.pull_requests[0].number,
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log('Merged PR');
|
|
||||||
}
|
|
||||||
|
9
.github/workflows/pr.yml
vendored
9
.github/workflows/pr.yml
vendored
@@ -3,6 +3,7 @@ on:
|
|||||||
pull_request:
|
pull_request:
|
||||||
branches:
|
branches:
|
||||||
- master
|
- master
|
||||||
|
- v3
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
name: test
|
name: test
|
||||||
@@ -11,9 +12,9 @@ jobs:
|
|||||||
- name: setup
|
- name: setup
|
||||||
uses: actions/setup-go@v2
|
uses: actions/setup-go@v2
|
||||||
with:
|
with:
|
||||||
go-version: 1.16
|
go-version: 1.17
|
||||||
- name: checkout
|
- name: checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
- name: cache
|
- name: cache
|
||||||
uses: actions/cache@v2
|
uses: actions/cache@v2
|
||||||
with:
|
with:
|
||||||
@@ -31,9 +32,9 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: checkout
|
- name: checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
- name: lint
|
- name: lint
|
||||||
uses: golangci/golangci-lint-action@v2
|
uses: golangci/golangci-lint-action@v3.1.0
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
with:
|
with:
|
||||||
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
|
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
|
||||||
|
4
go.mod
4
go.mod
@@ -4,7 +4,7 @@ go 1.16
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/fatih/structtag v1.2.0
|
github.com/fatih/structtag v1.2.0
|
||||||
go.unistack.org/micro-proto/v3 v3.2.3
|
go.unistack.org/micro-proto/v3 v3.2.7
|
||||||
golang.org/x/tools v0.1.9
|
golang.org/x/tools v0.1.10
|
||||||
google.golang.org/protobuf v1.27.1
|
google.golang.org/protobuf v1.27.1
|
||||||
)
|
)
|
||||||
|
16
go.sum
16
go.sum
@@ -68,17 +68,17 @@ github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:
|
|||||||
github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
|
github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
|
||||||
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||||
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
|
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
|
||||||
go.unistack.org/micro-proto/v3 v3.2.3 h1:vSRI6VoZrlv0pUdo69irHv6HbbnD+oZOGEUE/TS5XBQ=
|
go.unistack.org/micro-proto/v3 v3.2.7 h1:zG6d69kHc+oij2lwQ3AfrCgdjiEVRG2A7TlsxjusWs4=
|
||||||
go.unistack.org/micro-proto/v3 v3.2.3/go.mod h1:ZltVWNECD5yK+40+OCONzGw4OtmSdTpVi8/KFgo9dqM=
|
go.unistack.org/micro-proto/v3 v3.2.7/go.mod h1:ZltVWNECD5yK+40+OCONzGw4OtmSdTpVi8/KFgo9dqM=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
|
||||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
|
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
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-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-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
||||||
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||||
golang.org/x/mod v0.5.1 h1:OJxoQ/rynoF0dcCdI7cLPktw/hR2cueqYfjm43oqK38=
|
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 h1:kQgndtyPBW/JIYERgdxfwMYh3AVStj88WQTlNDi2a+o=
|
||||||
golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
|
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY=
|
||||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
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-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
@@ -87,6 +87,7 @@ golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn
|
|||||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||||
|
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
||||||
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||||
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||||
@@ -105,6 +106,7 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w
|
|||||||
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 h1:id054HUawV2/6IGm2IV8KZQjqtwAOo2CYlOToYqa0d0=
|
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 h1:id054HUawV2/6IGm2IV8KZQjqtwAOo2CYlOToYqa0d0=
|
||||||
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
@@ -119,8 +121,8 @@ golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3
|
|||||||
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
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/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
golang.org/x/tools v0.1.9 h1:j9KsMiaP1c3B0OTQGth0/k+miLGTgLsAFUCrF2vLcF8=
|
golang.org/x/tools v0.1.10 h1:QjFRCZxdOhBJ/UNgnBZLbNV13DlbnK0quyivTnXJM20=
|
||||||
golang.org/x/tools v0.1.9/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU=
|
golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E=
|
||||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
8
http.go
8
http.go
@@ -40,13 +40,13 @@ func (g *Generator) httpGenerate(component string, plugin *protogen.Plugin, genC
|
|||||||
|
|
||||||
for _, service := range file.Services {
|
for _, service := range file.Services {
|
||||||
if genClient {
|
if genClient {
|
||||||
generateServiceClient(gfile, service)
|
g.generateServiceClient(gfile, service)
|
||||||
generateServiceClientMethods(gfile, service, true)
|
g.generateServiceClientMethods(gfile, service, true)
|
||||||
}
|
}
|
||||||
if genServer {
|
if genServer {
|
||||||
generateServiceServer(gfile, service)
|
generateServiceServer(gfile, service)
|
||||||
generateServiceServerMethods(gfile, service)
|
g.generateServiceServerMethods(gfile, service)
|
||||||
generateServiceRegister(gfile, service)
|
g.generateServiceRegister(gfile, service)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
4
main.go
4
main.go
@@ -45,11 +45,13 @@ type Generator struct {
|
|||||||
fieldaligment bool
|
fieldaligment bool
|
||||||
tagPath string
|
tagPath string
|
||||||
openapiFile string
|
openapiFile string
|
||||||
|
plugin *protogen.Plugin
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Generator) Generate(plugin *protogen.Plugin) error {
|
func (g *Generator) Generate(plugin *protogen.Plugin) error {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
g.plugin = plugin
|
||||||
g.standalone = *flagStandalone
|
g.standalone = *flagStandalone
|
||||||
g.debug = *flagDebug
|
g.debug = *flagDebug
|
||||||
g.components = *flagComponents
|
g.components = *flagComponents
|
||||||
@@ -87,7 +89,7 @@ func (g *Generator) Generate(plugin *protogen.Plugin) error {
|
|||||||
err = g.microGenerate(component, plugin, genClient, genServer)
|
err = g.microGenerate(component, plugin, genClient, genServer)
|
||||||
case "http":
|
case "http":
|
||||||
err = g.httpGenerate(component, plugin, genClient, genServer)
|
err = g.httpGenerate(component, plugin, genClient, genServer)
|
||||||
case "grpc", "rpc":
|
case "grpc", "drpc", "rpc":
|
||||||
err = g.rpcGenerate("rpc", plugin, genClient, genServer)
|
err = g.rpcGenerate("rpc", plugin, genClient, genServer)
|
||||||
case "gorilla":
|
case "gorilla":
|
||||||
err = g.gorillaGenerate(component, plugin)
|
err = g.gorillaGenerate(component, plugin)
|
||||||
|
10
micro.go
10
micro.go
@@ -35,14 +35,14 @@ func (g *Generator) microGenerate(component string, plugin *protogen.Plugin, gen
|
|||||||
}
|
}
|
||||||
// generate services
|
// generate services
|
||||||
for _, service := range file.Services {
|
for _, service := range file.Services {
|
||||||
generateServiceEndpoints(gfile, service)
|
g.generateServiceEndpoints(gfile, service)
|
||||||
if genClient {
|
if genClient {
|
||||||
generateServiceClientInterface(gfile, service)
|
g.generateServiceClientInterface(gfile, service)
|
||||||
generateServiceClientStreamInterface(gfile, service)
|
g.generateServiceClientStreamInterface(gfile, service)
|
||||||
}
|
}
|
||||||
if genServer {
|
if genServer {
|
||||||
generateServiceServerInterface(gfile, service)
|
g.generateServiceServerInterface(gfile, service)
|
||||||
generateServiceServerStreamInterface(gfile, service)
|
g.generateServiceServerStreamInterface(gfile, service)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
122
openapiv3.go
122
openapiv3.go
@@ -22,13 +22,14 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"go.unistack.org/micro-proto/v3/api"
|
"go.unistack.org/micro-proto/v3/api"
|
||||||
v2 "go.unistack.org/micro-proto/v3/openapiv2"
|
|
||||||
v3 "go.unistack.org/micro-proto/v3/openapiv3"
|
v3 "go.unistack.org/micro-proto/v3/openapiv3"
|
||||||
"google.golang.org/protobuf/compiler/protogen"
|
"google.golang.org/protobuf/compiler/protogen"
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
"google.golang.org/protobuf/reflect/protoreflect"
|
"google.golang.org/protobuf/reflect/protoreflect"
|
||||||
|
"google.golang.org/protobuf/reflect/protoregistry"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -47,6 +48,19 @@ type openapiv3Generator struct {
|
|||||||
namedPathPattern *regexp.Regexp
|
namedPathPattern *regexp.Regexp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
once sync.Once
|
||||||
|
protofiles = &protoregistry.Files{}
|
||||||
|
)
|
||||||
|
|
||||||
|
func protofilesAdd(plugin *protogen.Plugin) {
|
||||||
|
for path, f := range plugin.FilesByPath {
|
||||||
|
if _, err := protofiles.FindFileByPath(path); err != nil {
|
||||||
|
protofiles.RegisterFile(f.Desc)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// openapiv3Generate creates a new generator for a protoc plugin invocation.
|
// openapiv3Generate creates a new generator for a protoc plugin invocation.
|
||||||
func (g *Generator) openapiv3Generate(component string, plugin *protogen.Plugin) error {
|
func (g *Generator) openapiv3Generate(component string, plugin *protogen.Plugin) error {
|
||||||
og := &openapiv3Generator{
|
og := &openapiv3Generator{
|
||||||
@@ -61,6 +75,8 @@ func (g *Generator) openapiv3Generate(component string, plugin *protogen.Plugin)
|
|||||||
namedPathPattern: regexp.MustCompile("{(.+)=(.+)}"),
|
namedPathPattern: regexp.MustCompile("{(.+)=(.+)}"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protofilesAdd(plugin)
|
||||||
|
|
||||||
d := og.buildDocumentV3(plugin)
|
d := og.buildDocumentV3(plugin)
|
||||||
bytes, err := d.YAMLValue("Generated with protoc-gen-go-micro\n")
|
bytes, err := d.YAMLValue("Generated with protoc-gen-go-micro\n")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -245,12 +261,6 @@ func (g *openapiv3Generator) addPathsToDocumentV3(d *v3.Document, file *protogen
|
|||||||
outputMessage := method.Output
|
outputMessage := method.Output
|
||||||
operationID := service.GoName + "_" + method.GoName
|
operationID := service.GoName + "_" + method.GoName
|
||||||
|
|
||||||
e2opt := proto.GetExtension(method.Desc.Options(), v2.E_Openapiv2Operation)
|
|
||||||
if e2opt != nil && e2opt != v2.E_Openapiv2Operation.InterfaceOf(v2.E_Openapiv2Operation.Zero()) {
|
|
||||||
if opt, ok := e2opt.(*v2.Operation); ok && opt.OperationId != "" {
|
|
||||||
operationID = opt.OperationId
|
|
||||||
}
|
|
||||||
}
|
|
||||||
e3opt := proto.GetExtension(method.Desc.Options(), v3.E_Openapiv3Operation)
|
e3opt := proto.GetExtension(method.Desc.Options(), v3.E_Openapiv3Operation)
|
||||||
if e3opt != nil && e3opt != v3.E_Openapiv3Operation.InterfaceOf(v3.E_Openapiv3Operation.Zero()) {
|
if e3opt != nil && e3opt != v3.E_Openapiv3Operation.InterfaceOf(v3.E_Openapiv3Operation.Zero()) {
|
||||||
if opt, ok := e3opt.(*v3.Operation); ok && opt.OperationId != "" {
|
if opt, ok := e3opt.(*v3.Operation); ok && opt.OperationId != "" {
|
||||||
@@ -520,6 +530,21 @@ func (g *openapiv3Generator) buildOperationV3(
|
|||||||
sparameters[parameter.Name] = struct{}{}
|
sparameters[parameter.Name] = struct{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if u, err := url.Parse(path); err == nil {
|
||||||
|
mp := u.Query()
|
||||||
|
path = u.Path
|
||||||
|
if mp != nil {
|
||||||
|
for _, field := range inputMessage.Fields {
|
||||||
|
fieldName := string(field.Desc.Name())
|
||||||
|
if _, ok := mp[fieldName]; ok && fieldName != bodyField {
|
||||||
|
fieldParams := g.buildQueryParamsV3(field)
|
||||||
|
parameters = append(parameters, fieldParams...)
|
||||||
|
coveredParameters = append(coveredParameters, fieldName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Find simple path parameters like {id}
|
// Find simple path parameters like {id}
|
||||||
if allMatches := g.pathPattern.FindAllStringSubmatch(path, -1); allMatches != nil {
|
if allMatches := g.pathPattern.FindAllStringSubmatch(path, -1); allMatches != nil {
|
||||||
for _, matches := range allMatches {
|
for _, matches := range allMatches {
|
||||||
@@ -623,22 +648,76 @@ func (g *openapiv3Generator) buildOperationV3(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var responses *v3.Responses
|
||||||
|
if eopt != nil && eopt != v3.E_Openapiv3Operation.InterfaceOf(v3.E_Openapiv3Operation.Zero()) {
|
||||||
|
opt := eopt.(*v3.Operation)
|
||||||
|
if r := opt.Responses; r != nil {
|
||||||
|
responses = r
|
||||||
|
|
||||||
|
rd := responses.Default
|
||||||
|
if rd != nil {
|
||||||
|
if ref := rd.GetReference(); ref != nil && ref.GetXRef() != "" {
|
||||||
|
xref := strings.TrimPrefix(ref.GetXRef(), ".")
|
||||||
|
description := "Default"
|
||||||
|
if strings.Contains(xref, "micro.errors.Error") {
|
||||||
|
description += " Error"
|
||||||
|
}
|
||||||
|
desc, err := protofiles.FindDescriptorByName(protoreflect.FullName(xref))
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("unknown ref type %s err %v", xref, err)
|
||||||
|
} else {
|
||||||
|
responses.Default.Oneof = &v3.ResponseOrReference_Response{
|
||||||
|
Response: &v3.Response{
|
||||||
|
Description: description,
|
||||||
|
Content: g.responseContentForMessage(&protogen.Message{
|
||||||
|
Desc: desc.(protoreflect.MessageDescriptor),
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, rref := range responses.GetResponseOrReference() {
|
||||||
|
if ref := rref.Value.GetReference(); ref != nil && ref.GetXRef() != "" {
|
||||||
|
xref := strings.TrimPrefix(ref.GetXRef(), ".")
|
||||||
|
description := "Default"
|
||||||
|
if strings.Contains(xref, "micro.errors.Error") {
|
||||||
|
description += " Error"
|
||||||
|
}
|
||||||
|
desc, err := protofiles.FindDescriptorByName(protoreflect.FullName(xref))
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("unknown ref type %s err %v", xref, err)
|
||||||
|
} else {
|
||||||
|
responses.Default.Oneof = &v3.ResponseOrReference_Response{
|
||||||
|
Response: &v3.Response{
|
||||||
|
Description: description,
|
||||||
|
Content: g.responseContentForMessage(&protogen.Message{
|
||||||
|
Desc: desc.(protoreflect.MessageDescriptor),
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
responses = &v3.Responses{}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
responses = &v3.Responses{}
|
||||||
|
}
|
||||||
|
|
||||||
// Create the response.
|
// Create the response.
|
||||||
responses := &v3.Responses{
|
responses.ResponseOrReference = append(responses.ResponseOrReference, &v3.NamedResponseOrReference{
|
||||||
ResponseOrReference: []*v3.NamedResponseOrReference{
|
Name: "200",
|
||||||
{
|
Value: &v3.ResponseOrReference{
|
||||||
Name: "200",
|
Oneof: &v3.ResponseOrReference_Response{
|
||||||
Value: &v3.ResponseOrReference{
|
Response: &v3.Response{
|
||||||
Oneof: &v3.ResponseOrReference_Response{
|
Description: "OK",
|
||||||
Response: &v3.Response{
|
Content: g.responseContentForMessage(outputMessage),
|
||||||
Description: "OK",
|
|
||||||
Content: g.responseContentForMessage(outputMessage),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
})
|
||||||
|
|
||||||
// Create the operation.
|
// Create the operation.
|
||||||
op := &v3.Operation{
|
op := &v3.Operation{
|
||||||
@@ -665,7 +744,6 @@ func (g *openapiv3Generator) buildOperationV3(
|
|||||||
// Pass the entire request message as the request body.
|
// Pass the entire request message as the request body.
|
||||||
typeName := g.fullMessageTypeName(inputMessage.Desc)
|
typeName := g.fullMessageTypeName(inputMessage.Desc)
|
||||||
requestSchema = g.schemaOrReferenceForType(typeName)
|
requestSchema = g.schemaOrReferenceForType(typeName)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// If body refers to a message field, use that type.
|
// If body refers to a message field, use that type.
|
||||||
for _, field := range inputMessage.Fields {
|
for _, field := range inputMessage.Fields {
|
||||||
@@ -692,6 +770,8 @@ func (g *openapiv3Generator) buildOperationV3(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ctype := getMediaType(eopt)
|
||||||
|
|
||||||
op.RequestBody = &v3.RequestBodyOrReference{
|
op.RequestBody = &v3.RequestBodyOrReference{
|
||||||
Oneof: &v3.RequestBodyOrReference_RequestBody{
|
Oneof: &v3.RequestBodyOrReference_RequestBody{
|
||||||
RequestBody: &v3.RequestBody{
|
RequestBody: &v3.RequestBody{
|
||||||
@@ -699,7 +779,7 @@ func (g *openapiv3Generator) buildOperationV3(
|
|||||||
Content: &v3.MediaTypes{
|
Content: &v3.MediaTypes{
|
||||||
AdditionalProperties: []*v3.NamedMediaType{
|
AdditionalProperties: []*v3.NamedMediaType{
|
||||||
{
|
{
|
||||||
Name: "application/json",
|
Name: ctype,
|
||||||
Value: &v3.MediaType{
|
Value: &v3.MediaType{
|
||||||
Schema: requestSchema,
|
Schema: requestSchema,
|
||||||
},
|
},
|
||||||
|
39
openapiv3_util.go
Normal file
39
openapiv3_util.go
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import v3 "go.unistack.org/micro-proto/v3/openapiv3"
|
||||||
|
|
||||||
|
func getMediaType(eopt interface{}) string {
|
||||||
|
ctype := "application/json"
|
||||||
|
|
||||||
|
if eopt == nil {
|
||||||
|
return ctype
|
||||||
|
}
|
||||||
|
|
||||||
|
if eopt == v3.E_Openapiv3Operation.InterfaceOf(v3.E_Openapiv3Operation.Zero()) {
|
||||||
|
return ctype
|
||||||
|
}
|
||||||
|
|
||||||
|
opt, ok := eopt.(*v3.Operation)
|
||||||
|
if !ok || opt.RequestBody == nil {
|
||||||
|
return ctype
|
||||||
|
}
|
||||||
|
|
||||||
|
if opt.GetRequestBody() == nil {
|
||||||
|
return ctype
|
||||||
|
}
|
||||||
|
|
||||||
|
if opt.GetRequestBody().GetRequestBody() == nil {
|
||||||
|
return ctype
|
||||||
|
}
|
||||||
|
|
||||||
|
c := opt.GetRequestBody().GetRequestBody().GetContent()
|
||||||
|
if c == nil {
|
||||||
|
return ctype
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, prop := range c.GetAdditionalProperties() {
|
||||||
|
ctype = prop.Name
|
||||||
|
}
|
||||||
|
|
||||||
|
return ctype
|
||||||
|
}
|
8
rpc.go
8
rpc.go
@@ -37,13 +37,13 @@ func (g *Generator) rpcGenerate(component string, plugin *protogen.Plugin, genCl
|
|||||||
}
|
}
|
||||||
for _, service := range file.Services {
|
for _, service := range file.Services {
|
||||||
if genClient {
|
if genClient {
|
||||||
generateServiceClient(gfile, service)
|
g.generateServiceClient(gfile, service)
|
||||||
generateServiceClientMethods(gfile, service, false)
|
g.generateServiceClientMethods(gfile, service, false)
|
||||||
}
|
}
|
||||||
if genServer {
|
if genServer {
|
||||||
generateServiceServer(gfile, service)
|
generateServiceServer(gfile, service)
|
||||||
generateServiceServerMethods(gfile, service)
|
g.generateServiceServerMethods(gfile, service)
|
||||||
generateServiceRegister(gfile, service)
|
g.generateServiceRegister(gfile, service)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
105
util.go
105
util.go
@@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -28,7 +29,7 @@ func unexport(s string) string {
|
|||||||
return strings.ToLower(s[:1]) + s[1:]
|
return strings.ToLower(s[:1]) + s[1:]
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateServiceClient(gfile *protogen.GeneratedFile, service *protogen.Service) {
|
func (g *Generator) generateServiceClient(gfile *protogen.GeneratedFile, service *protogen.Service) {
|
||||||
serviceName := service.GoName
|
serviceName := service.GoName
|
||||||
// if rule, ok := getMicroApiService(service); ok {
|
// if rule, ok := getMicroApiService(service); ok {
|
||||||
// gfile.P("// client wrappers ", strings.Join(rule.ClientWrappers, ", "))
|
// gfile.P("// client wrappers ", strings.Join(rule.ClientWrappers, ", "))
|
||||||
@@ -44,34 +45,42 @@ func generateServiceClient(gfile *protogen.GeneratedFile, service *protogen.Serv
|
|||||||
gfile.P()
|
gfile.P()
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateServiceClientMethods(gfile *protogen.GeneratedFile, service *protogen.Service, http bool) {
|
func (g *Generator) generateServiceClientMethods(gfile *protogen.GeneratedFile, service *protogen.Service, http bool) {
|
||||||
serviceName := service.GoName
|
serviceName := service.GoName
|
||||||
for _, method := range service.Methods {
|
for _, method := range service.Methods {
|
||||||
methodName := fmt.Sprintf("%s.%s", serviceName, method.GoName)
|
methodName := fmt.Sprintf("%s.%s", serviceName, method.GoName)
|
||||||
generateClientFuncSignature(gfile, serviceName, method)
|
g.generateClientFuncSignature(gfile, serviceName, method)
|
||||||
|
|
||||||
if http && method.Desc.Options() != nil {
|
if http && method.Desc.Options() != nil {
|
||||||
if proto.HasExtension(method.Desc.Options(), v2.E_Openapiv2Operation) {
|
if proto.HasExtension(method.Desc.Options(), v2.E_Openapiv2Operation) {
|
||||||
opts := proto.GetExtension(method.Desc.Options(), v2.E_Openapiv2Operation)
|
opts := proto.GetExtension(method.Desc.Options(), v2.E_Openapiv2Operation)
|
||||||
if opts != nil {
|
if opts != nil {
|
||||||
r := opts.(*v2.Operation)
|
r := opts.(*v2.Operation)
|
||||||
|
if r.Responses == nil {
|
||||||
|
goto labelMethod
|
||||||
|
}
|
||||||
gfile.P("errmap := make(map[string]interface{}, ", len(r.Responses.ResponseCode), ")")
|
gfile.P("errmap := make(map[string]interface{}, ", len(r.Responses.ResponseCode), ")")
|
||||||
for _, rsp := range r.Responses.ResponseCode {
|
for _, rsp := range r.Responses.ResponseCode {
|
||||||
if schema := rsp.Value.GetJsonReference(); schema != nil {
|
if schema := rsp.Value.GetJsonReference(); schema != nil {
|
||||||
ref := schema.XRef
|
xref := schema.XRef
|
||||||
if strings.HasPrefix(ref, "."+string(service.Desc.ParentFile().Package())+".") {
|
if strings.HasPrefix(xref, "."+string(service.Desc.ParentFile().Package())+".") {
|
||||||
ref = strings.TrimPrefix(ref, "."+string(service.Desc.ParentFile().Package())+".")
|
xref = strings.TrimPrefix(xref, "."+string(service.Desc.ParentFile().Package())+".")
|
||||||
}
|
}
|
||||||
if ref[0] == '.' {
|
if xref[0] == '.' {
|
||||||
ref = ref[1:]
|
xref = xref[1:]
|
||||||
}
|
}
|
||||||
switch ref {
|
switch xref {
|
||||||
case "micro.codec.Frame":
|
case "micro.codec.Frame":
|
||||||
gfile.P(`errmap["`, rsp.Name, `"] = &`, microCodecPackage.Ident("Frame"), "{}")
|
gfile.P(`errmap["`, rsp.Name, `"] = &`, microCodecPackage.Ident("Frame"), "{}")
|
||||||
case "micro.errors.Error":
|
case "micro.errors.Error":
|
||||||
gfile.P(`errmap["`, rsp.Name, `"] = &`, microErrorsPackage.Ident("Error"), "{}")
|
gfile.P(`errmap["`, rsp.Name, `"] = &`, microErrorsPackage.Ident("Error"), "{}")
|
||||||
default:
|
default:
|
||||||
gfile.P(`errmap["`, rsp.Name, `"] = &`, ref, "{}")
|
ident, err := g.getGoIdentByXref(strings.TrimPrefix(schema.XRef, "."))
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("cant find message by ref %s\n", schema.XRef)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
gfile.P(`errmap["`, rsp.Name, `"] = &`, gfile.QualifiedGoIdent(ident), "{}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -84,23 +93,35 @@ func generateServiceClientMethods(gfile *protogen.GeneratedFile, service *protog
|
|||||||
opts := proto.GetExtension(method.Desc.Options(), v3.E_Openapiv3Operation)
|
opts := proto.GetExtension(method.Desc.Options(), v3.E_Openapiv3Operation)
|
||||||
if opts != nil {
|
if opts != nil {
|
||||||
r := opts.(*v3.Operation)
|
r := opts.(*v3.Operation)
|
||||||
gfile.P("errmap := make(map[string]interface{}, ", len(r.Responses.ResponseOrReference), ")")
|
if r.Responses == nil {
|
||||||
for _, rsp := range r.Responses.ResponseOrReference {
|
goto labelMethod
|
||||||
|
}
|
||||||
|
resps := r.Responses.ResponseOrReference
|
||||||
|
if r.Responses.GetDefault() != nil {
|
||||||
|
resps = append(resps, &v3.NamedResponseOrReference{Name: "default", Value: r.Responses.GetDefault()})
|
||||||
|
}
|
||||||
|
gfile.P("errmap := make(map[string]interface{}, ", len(resps), ")")
|
||||||
|
for _, rsp := range resps {
|
||||||
if schema := rsp.Value.GetReference(); schema != nil {
|
if schema := rsp.Value.GetReference(); schema != nil {
|
||||||
ref := schema.XRef
|
xref := schema.XRef
|
||||||
if strings.HasPrefix(ref, "."+string(service.Desc.ParentFile().Package())+".") {
|
if strings.HasPrefix(xref, "."+string(service.Desc.ParentFile().Package())+".") {
|
||||||
ref = strings.TrimPrefix(ref, "."+string(service.Desc.ParentFile().Package())+".")
|
xref = strings.TrimPrefix(xref, "."+string(service.Desc.ParentFile().Package())+".")
|
||||||
}
|
}
|
||||||
if ref[0] == '.' {
|
if xref[0] == '.' {
|
||||||
ref = ref[1:]
|
xref = xref[1:]
|
||||||
}
|
}
|
||||||
switch ref {
|
switch xref {
|
||||||
case "micro.codec.Frame":
|
case "micro.codec.Frame":
|
||||||
gfile.P(`errmap["`, rsp.Name, `"] = &`, microCodecPackage.Ident("Frame"), "{}")
|
gfile.P(`errmap["`, rsp.Name, `"] = &`, microCodecPackage.Ident("Frame"), "{}")
|
||||||
case "micro.errors.Error":
|
case "micro.errors.Error":
|
||||||
gfile.P(`errmap["`, rsp.Name, `"] = &`, microErrorsPackage.Ident("Error"), "{}")
|
gfile.P(`errmap["`, rsp.Name, `"] = &`, microErrorsPackage.Ident("Error"), "{}")
|
||||||
default:
|
default:
|
||||||
gfile.P(`errmap["`, rsp.Name, `"] = &`, ref, "{}")
|
ident, err := g.getGoIdentByXref(strings.TrimPrefix(schema.XRef, "."))
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("cant find message by ref %s\n", schema.XRef)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
gfile.P(`errmap["`, rsp.Name, `"] = &`, gfile.QualifiedGoIdent(ident), "{}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -110,6 +131,7 @@ func generateServiceClientMethods(gfile *protogen.GeneratedFile, service *protog
|
|||||||
gfile.P(")")
|
gfile.P(")")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
labelMethod:
|
||||||
if proto.HasExtension(method.Desc.Options(), api_options.E_Http) {
|
if proto.HasExtension(method.Desc.Options(), api_options.E_Http) {
|
||||||
gfile.P("opts = append(opts,")
|
gfile.P("opts = append(opts,")
|
||||||
endpoints, _ := generateEndpoints(method)
|
endpoints, _ := generateEndpoints(method)
|
||||||
@@ -289,7 +311,7 @@ func generateServiceServer(gfile *protogen.GeneratedFile, service *protogen.Serv
|
|||||||
gfile.P()
|
gfile.P()
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateServiceServerMethods(gfile *protogen.GeneratedFile, service *protogen.Service) {
|
func (g *Generator) generateServiceServerMethods(gfile *protogen.GeneratedFile, service *protogen.Service) {
|
||||||
serviceName := service.GoName
|
serviceName := service.GoName
|
||||||
for _, method := range service.Methods {
|
for _, method := range service.Methods {
|
||||||
generateServerFuncSignature(gfile, serviceName, method, true)
|
generateServerFuncSignature(gfile, serviceName, method, true)
|
||||||
@@ -433,7 +455,7 @@ func generateServiceServerMethods(gfile *protogen.GeneratedFile, service *protog
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateServiceRegister(gfile *protogen.GeneratedFile, service *protogen.Service) {
|
func (g *Generator) generateServiceRegister(gfile *protogen.GeneratedFile, service *protogen.Service) {
|
||||||
serviceName := service.GoName
|
serviceName := service.GoName
|
||||||
gfile.P("func Register", serviceName, "Server(s ", microServerPackage.Ident("Server"), ", sh ", serviceName, "Server, opts ...", microServerPackage.Ident("HandlerOption"), ") error {")
|
gfile.P("func Register", serviceName, "Server(s ", microServerPackage.Ident("Server"), ", sh ", serviceName, "Server, opts ...", microServerPackage.Ident("HandlerOption"), ") error {")
|
||||||
gfile.P("type ", unexport(serviceName), " interface {")
|
gfile.P("type ", unexport(serviceName), " interface {")
|
||||||
@@ -497,7 +519,7 @@ func generateServerSignature(gfile *protogen.GeneratedFile, serviceName string,
|
|||||||
gfile.P(args...)
|
gfile.P(args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateClientFuncSignature(gfile *protogen.GeneratedFile, serviceName string, method *protogen.Method) {
|
func (g *Generator) generateClientFuncSignature(gfile *protogen.GeneratedFile, serviceName string, method *protogen.Method) {
|
||||||
args := append([]interface{}{},
|
args := append([]interface{}{},
|
||||||
"func (c *",
|
"func (c *",
|
||||||
unexport(serviceName),
|
unexport(serviceName),
|
||||||
@@ -536,7 +558,7 @@ func generateClientSignature(gfile *protogen.GeneratedFile, serviceName string,
|
|||||||
gfile.P(args...)
|
gfile.P(args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateServiceClientInterface(gfile *protogen.GeneratedFile, service *protogen.Service) {
|
func (g *Generator) generateServiceClientInterface(gfile *protogen.GeneratedFile, service *protogen.Service) {
|
||||||
serviceName := service.GoName
|
serviceName := service.GoName
|
||||||
gfile.P("type ", serviceName, "Client interface {")
|
gfile.P("type ", serviceName, "Client interface {")
|
||||||
for _, method := range service.Methods {
|
for _, method := range service.Methods {
|
||||||
@@ -546,7 +568,7 @@ func generateServiceClientInterface(gfile *protogen.GeneratedFile, service *prot
|
|||||||
gfile.P()
|
gfile.P()
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateServiceServerInterface(gfile *protogen.GeneratedFile, service *protogen.Service) {
|
func (g *Generator) generateServiceServerInterface(gfile *protogen.GeneratedFile, service *protogen.Service) {
|
||||||
serviceName := service.GoName
|
serviceName := service.GoName
|
||||||
gfile.P("type ", serviceName, "Server interface {")
|
gfile.P("type ", serviceName, "Server interface {")
|
||||||
for _, method := range service.Methods {
|
for _, method := range service.Methods {
|
||||||
@@ -556,7 +578,7 @@ func generateServiceServerInterface(gfile *protogen.GeneratedFile, service *prot
|
|||||||
gfile.P()
|
gfile.P()
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateServiceClientStreamInterface(gfile *protogen.GeneratedFile, service *protogen.Service) {
|
func (g *Generator) generateServiceClientStreamInterface(gfile *protogen.GeneratedFile, service *protogen.Service) {
|
||||||
serviceName := service.GoName
|
serviceName := service.GoName
|
||||||
for _, method := range service.Methods {
|
for _, method := range service.Methods {
|
||||||
if !method.Desc.IsStreamingClient() && !method.Desc.IsStreamingServer() {
|
if !method.Desc.IsStreamingClient() && !method.Desc.IsStreamingServer() {
|
||||||
@@ -583,7 +605,7 @@ func generateServiceClientStreamInterface(gfile *protogen.GeneratedFile, service
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateServiceServerStreamInterface(gfile *protogen.GeneratedFile, service *protogen.Service) {
|
func (g *Generator) generateServiceServerStreamInterface(gfile *protogen.GeneratedFile, service *protogen.Service) {
|
||||||
serviceName := service.GoName
|
serviceName := service.GoName
|
||||||
for _, method := range service.Methods {
|
for _, method := range service.Methods {
|
||||||
if !method.Desc.IsStreamingClient() && !method.Desc.IsStreamingServer() {
|
if !method.Desc.IsStreamingClient() && !method.Desc.IsStreamingServer() {
|
||||||
@@ -610,7 +632,7 @@ func generateServiceServerStreamInterface(gfile *protogen.GeneratedFile, service
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateServiceEndpoints(gfile *protogen.GeneratedFile, service *protogen.Service) {
|
func (g *Generator) generateServiceEndpoints(gfile *protogen.GeneratedFile, service *protogen.Service) {
|
||||||
serviceName := service.GoName
|
serviceName := service.GoName
|
||||||
gfile.P("var (")
|
gfile.P("var (")
|
||||||
gfile.P(serviceName, "Name", "=", `"`, serviceName, `"`)
|
gfile.P(serviceName, "Name", "=", `"`, serviceName, `"`)
|
||||||
@@ -744,3 +766,32 @@ func generateEndpoint(gfile *protogen.GeneratedFile, serviceName string, methodN
|
|||||||
}
|
}
|
||||||
gfile.P(`Handler: "rpc",`)
|
gfile.P(`Handler: "rpc",`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *Generator) getGoIdentByXref(xref string) (protogen.GoIdent, error) {
|
||||||
|
idx := strings.LastIndex(xref, ".")
|
||||||
|
pkg := xref[:idx]
|
||||||
|
msg := xref[idx+1:]
|
||||||
|
for _, file := range g.plugin.Files {
|
||||||
|
if strings.Compare(pkg, *(file.Proto.Package)) != 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if ident, err := getGoIdentByMessage(file.Messages, msg); err == nil {
|
||||||
|
return ident, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return protogen.GoIdent{}, fmt.Errorf("not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
func getGoIdentByMessage(messages []*protogen.Message, msg string) (protogen.GoIdent, error) {
|
||||||
|
for _, message := range messages {
|
||||||
|
if strings.Compare(msg, message.GoIdent.GoName) == 0 {
|
||||||
|
return message.GoIdent, nil
|
||||||
|
}
|
||||||
|
if len(message.Messages) > 0 {
|
||||||
|
if ident, err := getGoIdentByMessage(message.Messages, msg); err == nil {
|
||||||
|
return ident, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return protogen.GoIdent{}, fmt.Errorf("not found")
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user