Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 586c53efa7 | |||
|
|
dac811aa09 | ||
|
|
545af44de7 | ||
| 2f67df5079 | |||
|
|
2f0ae395d1 | ||
|
|
28257eac2e | ||
|
|
8bd8adbd27 | ||
| fb2a59d2f2 | |||
| 091e964bd4 | |||
| 25bf4f9483 | |||
| 3d92ee0003 | |||
| 750c949723 | |||
| 4633928da5 | |||
| 5ecd91182f | |||
| a8b52d800d | |||
| 9c05b6b646 | |||
| 675ca27dbf |
8
.github/ISSUE_TEMPLATE/bug_report.md
vendored
8
.github/ISSUE_TEMPLATE/bug_report.md
vendored
@@ -1,6 +1,6 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: For reporting bugs in go-micro
|
||||
about: For reporting bugs in micro
|
||||
title: "[BUG]"
|
||||
labels: ''
|
||||
assignees: ''
|
||||
@@ -16,9 +16,3 @@ assignees: ''
|
||||
**How to reproduce the bug:**
|
||||
|
||||
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
|
||||
about: If you have a need not served by go-micro
|
||||
about: If you have a need not served by micro
|
||||
title: "[FEATURE]"
|
||||
labels: ''
|
||||
assignees: ''
|
||||
@@ -14,4 +14,4 @@ A clear and concise description of what the problem is. Ex. I'm always frustrate
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
||||
Add any other context or screenshots about the feature request here.
|
||||
10
.github/ISSUE_TEMPLATE/question.md
vendored
10
.github/ISSUE_TEMPLATE/question.md
vendored
@@ -1,14 +1,8 @@
|
||||
---
|
||||
name: Question
|
||||
about: Ask a question about go-micro
|
||||
about: Ask a question about micro
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
Before asking, please check if your question has already been answered:
|
||||
|
||||
1. Check the documentation - https://micro.mu/docs/
|
||||
2. Check the examples and plugins - https://github.com/micro/examples & https://github.com/micro/go-plugins
|
||||
3. Search existing issues
|
||||
---
|
||||
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/dependabot.yml
vendored
19
.github/dependabot.yml
vendored
@@ -1,19 +0,0 @@
|
||||
# To get started with Dependabot version updates, you'll need to specify which
|
||||
# package ecosystems to update and where the package manifests are located.
|
||||
# Please see the documentation for all configuration options:
|
||||
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
|
||||
|
||||
version: 2
|
||||
updates:
|
||||
|
||||
# Maintain dependencies for GitHub Actions
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "daily"
|
||||
|
||||
# Maintain dependencies for Golang
|
||||
- package-ecosystem: "gomod"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "daily"
|
||||
20
.github/workflows/autoapprove.yml
vendored
20
.github/workflows/autoapprove.yml
vendored
@@ -1,20 +0,0 @@
|
||||
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@v3
|
||||
if: github.actor == 'vtolstov' || github.actor == 'dependabot[bot]'
|
||||
id: approve
|
||||
with:
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
21
.github/workflows/automerge.yml
vendored
21
.github/workflows/automerge.yml
vendored
@@ -1,21 +0,0 @@
|
||||
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}}
|
||||
47
.github/workflows/build.yml
vendored
47
.github/workflows/build.yml
vendored
@@ -1,47 +0,0 @@
|
||||
name: build
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- v3
|
||||
jobs:
|
||||
test:
|
||||
name: test
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: setup
|
||||
uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: 1.17
|
||||
- name: checkout
|
||||
uses: actions/checkout@v3
|
||||
- name: cache
|
||||
uses: actions/cache@v3
|
||||
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@v3
|
||||
- name: lint
|
||||
uses: golangci/golangci-lint-action@v3.4.0
|
||||
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
|
||||
78
.github/workflows/codeql-analysis.yml
vendored
78
.github/workflows/codeql-analysis.yml
vendored
@@ -1,78 +0,0 @@
|
||||
# For most projects, this workflow file will not need changing; you simply need
|
||||
# to commit it to your repository.
|
||||
#
|
||||
# You may wish to alter this file to override the set of languages analyzed,
|
||||
# or to provide custom queries or build logic.
|
||||
#
|
||||
# ******** NOTE ********
|
||||
# We have attempted to detect the languages in your repository. Please check
|
||||
# the `language` matrix defined below to confirm you have the correct set of
|
||||
# supported CodeQL languages.
|
||||
#
|
||||
name: "codeql"
|
||||
|
||||
on:
|
||||
workflow_run:
|
||||
workflows: ["prbuild"]
|
||||
types:
|
||||
- completed
|
||||
push:
|
||||
branches: [ master, v3 ]
|
||||
pull_request:
|
||||
# The branches below must be a subset of the branches above
|
||||
branches: [ master, v3 ]
|
||||
schedule:
|
||||
- cron: '34 1 * * 0'
|
||||
|
||||
jobs:
|
||||
analyze:
|
||||
name: analyze
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
actions: read
|
||||
contents: read
|
||||
security-events: write
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
language: [ 'go' ]
|
||||
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
|
||||
# Learn more:
|
||||
# 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:
|
||||
- name: checkout
|
||||
uses: actions/checkout@v3
|
||||
- name: setup
|
||||
uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: 1.17
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: init
|
||||
uses: github/codeql-action/init@v2
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||
# By default, queries listed here will override any specified in a config file.
|
||||
# Prefix the list here with "+" to use these queries and those in the config file.
|
||||
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
||||
|
||||
# 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)
|
||||
- name: autobuild
|
||||
uses: github/codeql-action/autobuild@v2
|
||||
|
||||
# ℹ️ Command-line programs to run using the OS shell.
|
||||
# 📚 https://git.io/JvXDl
|
||||
|
||||
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
||||
# and modify them (or add more) to build your code if your project
|
||||
# uses a compiled language
|
||||
|
||||
#- run: |
|
||||
# make bootstrap
|
||||
# make release
|
||||
|
||||
- name: analyze
|
||||
uses: github/codeql-action/analyze@v2
|
||||
27
.github/workflows/dependabot-automerge.yml
vendored
27
.github/workflows/dependabot-automerge.yml
vendored
@@ -1,27 +0,0 @@
|
||||
name: "dependabot-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 == 'dependabot[bot]'
|
||||
steps:
|
||||
- name: metadata
|
||||
id: metadata
|
||||
uses: dependabot/fetch-metadata@v1.3.6
|
||||
with:
|
||||
github-token: "${{ secrets.TOKEN }}"
|
||||
- name: merge
|
||||
id: merge
|
||||
if: ${{contains(steps.metadata.outputs.dependency-names, 'go.unistack.org')}}
|
||||
run: gh pr merge --auto --merge "$PR_URL"
|
||||
env:
|
||||
PR_URL: ${{github.event.pull_request.html_url}}
|
||||
GITHUB_TOKEN: ${{secrets.TOKEN}}
|
||||
53
.github/workflows/job_coverage.yml
vendored
Normal file
53
.github/workflows/job_coverage.yml
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
name: coverage
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ main, v3, v4 ]
|
||||
paths-ignore:
|
||||
- '.github/**'
|
||||
- '.gitea/**'
|
||||
pull_request:
|
||||
branches: [ main, v3, v4 ]
|
||||
|
||||
jobs:
|
||||
|
||||
build:
|
||||
if: github.server_url != 'https://github.com'
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: checkout code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
filter: 'blob:none'
|
||||
|
||||
- name: setup go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
cache-dependency-path: "**/*.sum"
|
||||
go-version: 'stable'
|
||||
|
||||
- name: test coverage
|
||||
run: |
|
||||
go test -v -cover ./... -covermode=count -coverprofile coverage.out -coverpkg ./...
|
||||
go tool cover -func coverage.out -o coverage.out
|
||||
|
||||
- name: coverage badge
|
||||
uses: tj-actions/coverage-badge-go@v2
|
||||
with:
|
||||
green: 80
|
||||
filename: coverage.out
|
||||
|
||||
- uses: stefanzweifel/git-auto-commit-action@v4
|
||||
name: autocommit
|
||||
with:
|
||||
commit_message: Apply Code Coverage Badge
|
||||
skip_fetch: false
|
||||
skip_checkout: false
|
||||
file_pattern: ./README.md
|
||||
|
||||
- name: push
|
||||
if: steps.auto-commit-action.outputs.changes_detected == 'true'
|
||||
uses: ad-m/github-push-action@master
|
||||
with:
|
||||
github_token: ${{ github.token }}
|
||||
branch: ${{ github.ref }}
|
||||
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
|
||||
47
.github/workflows/pr.yml
vendored
47
.github/workflows/pr.yml
vendored
@@ -1,47 +0,0 @@
|
||||
name: prbuild
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
- v3
|
||||
jobs:
|
||||
test:
|
||||
name: test
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: setup
|
||||
uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: 1.17
|
||||
- name: checkout
|
||||
uses: actions/checkout@v3
|
||||
- name: cache
|
||||
uses: actions/cache@v3
|
||||
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@v3
|
||||
- name: lint
|
||||
uses: golangci/golangci-lint-action@v3.4.0
|
||||
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
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -36,3 +36,4 @@ _cgo_export.*
|
||||
*.swo
|
||||
/protoc-gen-go-micro
|
||||
|
||||
/example/out
|
||||
@@ -23,4 +23,4 @@ $> protoc --go_micro_out=debug=true,components="micro|http":. input.proto
|
||||
|
||||
* Install the **go** compiler and tools from https://golang.org/doc/install
|
||||
* Install **protoc-gen-go**: `go install google.golang.org/protobuf/cmd/protoc-gen-go`
|
||||
* Install **protoc-gen-go-micro**: `go install go.unistack.org/protoc-gen-go-micro/v3`
|
||||
* Install **protoc-gen-go-micro**: `go install go.unistack.org/protoc-gen-go-micro/v4`
|
||||
|
||||
4
ast.go
4
ast.go
@@ -10,7 +10,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/fatih/structtag"
|
||||
tag_options "go.unistack.org/micro-proto/v3/tag"
|
||||
tag_options "go.unistack.org/micro-proto/v5/tag"
|
||||
"google.golang.org/protobuf/compiler/protogen"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
@@ -98,7 +98,7 @@ func (g *Generator) astGenerate(plugin *protogen.Plugin) error {
|
||||
return err
|
||||
}
|
||||
|
||||
fp, err := os.OpenFile(file, os.O_WRONLY|os.O_TRUNC, os.FileMode(0644))
|
||||
fp, err := os.OpenFile(file, os.O_WRONLY|os.O_TRUNC, os.FileMode(0o644))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ syntax = "proto3";
|
||||
|
||||
package example;
|
||||
|
||||
option go_package = "github.com/unistack-org/protoc-gen-go-micro/v3/example;examplepb";
|
||||
option go_package = "go.unistack.org/protoc-gen-go-micro/v5/example;examplepb";
|
||||
|
||||
import "tag/tag.proto";
|
||||
import "api/annotations.proto";
|
||||
|
||||
17
example/stream_test.proto
Normal file
17
example/stream_test.proto
Normal file
@@ -0,0 +1,17 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package example;
|
||||
|
||||
option go_package = "go.unistack.org/protoc-gen-go-micro/v5/example/out/go;examplepb";
|
||||
|
||||
service StreamExample {
|
||||
// server-side streaming
|
||||
rpc ServerStream(StreamReq) returns (stream StreamRsp) {};
|
||||
// client-side streaming
|
||||
rpc ClientStream(stream StreamReq) returns (StreamRsp) {};
|
||||
// bidirectional streaming
|
||||
rpc BidiStream(stream StreamReq) returns (stream StreamRsp) {};
|
||||
}
|
||||
|
||||
message StreamReq { string name = 1; }
|
||||
message StreamRsp { string data = 1; }
|
||||
@@ -1,24 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"golang.org/x/tools/go/analysis/passes/fieldalignment"
|
||||
"golang.org/x/tools/go/analysis/singlechecker"
|
||||
"google.golang.org/protobuf/compiler/protogen"
|
||||
)
|
||||
|
||||
func (g *Generator) fieldAlign(plugin *protogen.Plugin) error {
|
||||
if !g.fieldaligment {
|
||||
return nil
|
||||
}
|
||||
|
||||
log.Printf("%v\n", []string{"fieldalignment", "-fix", g.tagPath})
|
||||
origArgs := os.Args
|
||||
os.Args = []string{"fieldalignment", "-fix", g.tagPath}
|
||||
singlechecker.Main(fieldalignment.Analyzer)
|
||||
os.Args = origArgs
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -1,3 +1,10 @@
|
||||
package main
|
||||
|
||||
//go:generate sh -xc "protoc -I./example -I. -I$(go list -f '{{ .Dir }}' -m go.unistack.org/micro-proto/v3) --go-micro_out=components=graphqls,graphql_file=./schema.graphql:./example example/example.proto"
|
||||
//go:generate sh -xc "protoc -I./example -I. -I$(go list -f '{{ .Dir }}' -m go.unistack.org/micro-proto/v5) --go-micro_out=components=graphqls,graphql_file=./schema.graphql:./example example/example.proto"
|
||||
|
||||
//go:generate go build -o $GOPATH/bin/protoc-gen-go-micro .
|
||||
//go:generate mkdir -p ./example/out/go/grpc ./example/out/align
|
||||
|
||||
// stream_test: micro + grpc
|
||||
//go:generate sh -xc "protoc -I./example -I$(go list -f '{{ .Dir }}' -m go.unistack.org/micro-proto/v5) --go_out=paths=source_relative:./example/out/go --go-micro_out=components=micro,standalone=false,paths=source_relative:./example/out/go ./example/stream_test.proto"
|
||||
//go:generate sh -xc "protoc -I./example -I$(go list -f '{{ .Dir }}' -m go.unistack.org/micro-proto/v5) --go-micro_out=components=grpc,standalone=true,paths=source_relative:./example/out/go/grpc ./example/stream_test.proto"
|
||||
|
||||
35
go.mod
35
go.mod
@@ -1,24 +1,29 @@
|
||||
module go.unistack.org/protoc-gen-go-micro/v3
|
||||
module go.unistack.org/protoc-gen-go-micro/v5
|
||||
|
||||
go 1.20
|
||||
go 1.24.6
|
||||
|
||||
require (
|
||||
github.com/danielvladco/go-proto-gql v0.10.0
|
||||
github.com/fatih/structtag v1.2.0
|
||||
github.com/jhump/protoreflect v1.7.1
|
||||
github.com/vektah/gqlparser/v2 v2.5.1
|
||||
go.unistack.org/micro-proto/v3 v3.4.1
|
||||
golang.org/x/tools v0.11.0
|
||||
google.golang.org/protobuf v1.28.1
|
||||
github.com/jhump/protoreflect v1.18.0
|
||||
github.com/vektah/gqlparser/v2 v2.5.33
|
||||
go.unistack.org/micro-proto/v4 v4.1.2
|
||||
golang.org/x/tools v0.42.0
|
||||
google.golang.org/protobuf v1.36.11
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/golang/protobuf v1.5.3 // indirect
|
||||
github.com/google/gnostic v0.6.9 // indirect
|
||||
github.com/google/go-cmp v0.5.9 // indirect
|
||||
github.com/kr/text v0.2.0 // indirect
|
||||
golang.org/x/mod v0.12.0 // indirect
|
||||
golang.org/x/sys v0.10.0 // indirect
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
|
||||
github.com/golang/protobuf v1.5.4 // indirect
|
||||
github.com/google/gnostic v0.7.1 // indirect
|
||||
github.com/google/gnostic-models v0.7.1 // indirect
|
||||
github.com/jhump/protoreflect/v2 v2.0.0-beta.2 // indirect
|
||||
github.com/kr/pretty v0.3.1 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
|
||||
github.com/rogpeppe/go-internal v1.14.1 // indirect
|
||||
github.com/stretchr/testify v1.11.1 // indirect
|
||||
golang.org/x/mod v0.33.0 // indirect
|
||||
golang.org/x/sync v0.19.0 // indirect
|
||||
golang.org/x/text v0.34.0 // indirect
|
||||
google.golang.org/grpc v1.79.3 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"google.golang.org/protobuf/compiler/protogen"
|
||||
descriptor "google.golang.org/protobuf/types/descriptorpb"
|
||||
|
||||
gqlpb "go.unistack.org/micro-proto/v3/graphql"
|
||||
gqlpb "go.unistack.org/micro-proto/v4/graphql"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
descriptor "google.golang.org/protobuf/types/descriptorpb"
|
||||
"google.golang.org/protobuf/types/pluginpb"
|
||||
|
||||
gqlpb "go.unistack.org/micro-proto/v3/graphql"
|
||||
gqlpb "go.unistack.org/micro-proto/v4/graphql"
|
||||
)
|
||||
|
||||
func GraphqlMethodOptions(opts proto.Message) *gqlpb.Rpc {
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/vektah/gqlparser/v2/formatter"
|
||||
generator "go.unistack.org/protoc-gen-go-micro/v3/graphql"
|
||||
generator "go.unistack.org/protoc-gen-go-micro/v5/graphql"
|
||||
"google.golang.org/protobuf/compiler/protogen"
|
||||
"google.golang.org/protobuf/proto"
|
||||
"google.golang.org/protobuf/types/pluginpb"
|
||||
|
||||
36
http.go
36
http.go
@@ -13,40 +13,18 @@ func (g *Generator) httpGenerate(component string, plugin *protogen.Plugin, genC
|
||||
continue
|
||||
}
|
||||
|
||||
gname := file.GeneratedFilenamePrefix + "_micro_" + component + ".pb.go"
|
||||
path := file.GoImportPath
|
||||
if g.standalone {
|
||||
path = "."
|
||||
}
|
||||
gfile := plugin.NewGeneratedFile(gname, path)
|
||||
|
||||
gfile.P("// Code generated by protoc-gen-go-micro. DO NOT EDIT.")
|
||||
gfile.P("// protoc-gen-go-micro version: " + versionComment)
|
||||
gfile.P("// source: ", file.Proto.GetName())
|
||||
gfile.P()
|
||||
gfile.P("package ", file.GoPackageName)
|
||||
gfile.P()
|
||||
|
||||
gfile.Import(contextPackage)
|
||||
|
||||
if genClient {
|
||||
gfile.Import(microClientPackage)
|
||||
gfile.Import(microClientHttpPackage)
|
||||
}
|
||||
if genServer {
|
||||
gfile.Import(microServerPackage)
|
||||
}
|
||||
gFile := g.newGeneratedFile(plugin, file, component, genClient, genServer)
|
||||
|
||||
for _, service := range file.Services {
|
||||
g.generateServiceEndpoints(gfile, service, component)
|
||||
g.generateServiceEndpoints(gFile, service, component)
|
||||
if genClient {
|
||||
g.generateServiceClient(gfile, file, service)
|
||||
g.generateServiceClientMethods(gfile, service, component)
|
||||
g.generateServiceClient(gFile, file, service)
|
||||
g.generateServiceClientMethods(gFile, file, service, component)
|
||||
}
|
||||
if genServer {
|
||||
g.generateServiceServer(gfile, file, service)
|
||||
g.generateServiceServerMethods(gfile, service)
|
||||
g.generateServiceRegister(gfile, file, service, component)
|
||||
g.generateServiceServer(gFile, file, service)
|
||||
g.generateServiceServerMethods(gFile, service)
|
||||
g.generateServiceRegister(gFile, file, service, component)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
15
main.go
15
main.go
@@ -24,12 +24,6 @@ var (
|
||||
)
|
||||
|
||||
func main() {
|
||||
opts := &protogen.Options{
|
||||
ParamFunc: flagSet.Set,
|
||||
}
|
||||
|
||||
_ = flagSet.Parse(os.Args[1:])
|
||||
|
||||
if *flagHelp {
|
||||
flagSet.PrintDefaults()
|
||||
return
|
||||
@@ -37,6 +31,10 @@ func main() {
|
||||
|
||||
g := &Generator{}
|
||||
|
||||
opts := &protogen.Options{
|
||||
ParamFunc: flagSet.Set,
|
||||
}
|
||||
|
||||
opts.Run(g.Generate)
|
||||
}
|
||||
|
||||
@@ -128,10 +126,5 @@ func (g *Generator) Generate(plugin *protogen.Plugin) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = g.fieldAlign(plugin); err != nil {
|
||||
plugin.Error(err)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -24,8 +24,8 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"go.unistack.org/micro-proto/v3/api"
|
||||
v3 "go.unistack.org/micro-proto/v3/openapiv3"
|
||||
"go.unistack.org/micro-proto/v5/api"
|
||||
v3 "go.unistack.org/micro-proto/v5/openapiv3"
|
||||
"google.golang.org/protobuf/compiler/protogen"
|
||||
"google.golang.org/protobuf/proto"
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package main
|
||||
|
||||
import v3 "go.unistack.org/micro-proto/v3/openapiv3"
|
||||
import v3 "go.unistack.org/micro-proto/v5/openapiv3"
|
||||
|
||||
func getMediaType(eopt interface{}) string {
|
||||
ctype := "application/json"
|
||||
|
||||
34
rpc.go
34
rpc.go
@@ -13,40 +13,20 @@ func (g *Generator) rpcGenerate(component string, plugin *protogen.Plugin, genCl
|
||||
continue
|
||||
}
|
||||
|
||||
gname := file.GeneratedFilenamePrefix + "_micro_" + component + ".pb.go"
|
||||
path := file.GoImportPath
|
||||
if g.standalone {
|
||||
path = "."
|
||||
}
|
||||
gfile := plugin.NewGeneratedFile(gname, path)
|
||||
gFile := g.newGeneratedFile(plugin, file, component, genClient, genServer)
|
||||
|
||||
gfile.P("// Code generated by protoc-gen-go-micro. DO NOT EDIT.")
|
||||
gfile.P("// protoc-gen-go-micro version: " + versionComment)
|
||||
gfile.P("// source: ", file.Proto.GetName())
|
||||
gfile.P()
|
||||
gfile.P("package ", file.GoPackageName)
|
||||
gfile.P()
|
||||
|
||||
gfile.Import(contextPackage)
|
||||
|
||||
if genClient {
|
||||
gfile.Import(microClientPackage)
|
||||
}
|
||||
if genServer {
|
||||
gfile.Import(microServerPackage)
|
||||
}
|
||||
for _, service := range file.Services {
|
||||
if genClient {
|
||||
g.generateServiceClient(gfile, file, service)
|
||||
g.generateServiceClientMethods(gfile, service, component)
|
||||
g.generateServiceClient(gFile, file, service)
|
||||
g.generateServiceClientMethods(gFile, file, service, component)
|
||||
}
|
||||
if genServer {
|
||||
g.generateServiceServer(gfile, file, service)
|
||||
g.generateServiceServerMethods(gfile, service)
|
||||
g.generateServiceRegister(gfile, file, service, component)
|
||||
g.generateServiceServer(gFile, file, service)
|
||||
g.generateServiceServerMethods(gFile, service)
|
||||
g.generateServiceRegister(gFile, file, service, component)
|
||||
}
|
||||
if component == "grpc" && g.reflection {
|
||||
g.generateServiceDesc(gfile, file, service)
|
||||
g.generateServiceDesc(gFile, file, service)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
2
tools.go
2
tools.go
@@ -3,5 +3,5 @@
|
||||
package tools
|
||||
|
||||
import (
|
||||
_ "go.unistack.org/micro-proto/v3/graphql"
|
||||
_ "go.unistack.org/micro-proto/v5/graphql"
|
||||
)
|
||||
|
||||
135
util.go
135
util.go
@@ -8,9 +8,10 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
api_options "go.unistack.org/micro-proto/v3/api"
|
||||
v2 "go.unistack.org/micro-proto/v3/openapiv2"
|
||||
v3 "go.unistack.org/micro-proto/v3/openapiv3"
|
||||
apioptions "go.unistack.org/micro-proto/v5/api"
|
||||
v2 "go.unistack.org/micro-proto/v5/openapiv2"
|
||||
v3 "go.unistack.org/micro-proto/v5/openapiv3"
|
||||
|
||||
"google.golang.org/protobuf/compiler/protogen"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
@@ -31,6 +32,33 @@ func unexport(s string) string {
|
||||
return strings.ToLower(s[:1]) + s[1:]
|
||||
}
|
||||
|
||||
func (g *Generator) newGeneratedFile(plugin *protogen.Plugin, file *protogen.File, component string, genClient bool, genServer bool) *protogen.GeneratedFile {
|
||||
gname := file.GeneratedFilenamePrefix + "_micro_" + component + ".pb.go"
|
||||
path := file.GoImportPath
|
||||
if g.standalone {
|
||||
path = protogen.GoImportPath(string(file.GoImportPath) + "/" + component)
|
||||
}
|
||||
|
||||
gFile := plugin.NewGeneratedFile(gname, path)
|
||||
|
||||
gFile.P("// Code generated by protoc-gen-go-micro. DO NOT EDIT.")
|
||||
gFile.P("// protoc-gen-go-micro version: " + versionComment)
|
||||
gFile.P("// source: ", file.Proto.GetName())
|
||||
gFile.P()
|
||||
gFile.P("package ", file.GoPackageName)
|
||||
gFile.P()
|
||||
|
||||
gFile.Import(contextPackage)
|
||||
if genClient {
|
||||
gFile.Import(microClientPackage)
|
||||
}
|
||||
if genServer {
|
||||
gFile.Import(microServerPackage)
|
||||
}
|
||||
|
||||
return gFile
|
||||
}
|
||||
|
||||
func (g *Generator) generateServiceClient(gfile *protogen.GeneratedFile, file *protogen.File, service *protogen.Service) {
|
||||
serviceName := service.GoName
|
||||
// if rule, ok := getMicroApiService(service); ok {
|
||||
@@ -42,7 +70,7 @@ func (g *Generator) generateServiceClient(gfile *protogen.GeneratedFile, file *p
|
||||
gfile.P("}")
|
||||
|
||||
if g.standalone {
|
||||
gfile.P("func New", serviceName, "Client(name string, c ", microClientPackage.Ident("Client"), ") ", file.GoImportPath.Ident(serviceName), "Client {")
|
||||
gfile.P("func New", serviceName, "Client(name string, c ", microClientPackage.Ident("Client"), ") ", gfile.QualifiedGoIdent(file.GoImportPath.Ident(serviceName+"Client")), " {")
|
||||
} else {
|
||||
gfile.P("func New", serviceName, "Client(name string, c ", microClientPackage.Ident("Client"), ") ", serviceName, "Client {")
|
||||
}
|
||||
@@ -51,14 +79,14 @@ func (g *Generator) generateServiceClient(gfile *protogen.GeneratedFile, file *p
|
||||
gfile.P()
|
||||
}
|
||||
|
||||
func (g *Generator) generateServiceClientMethods(gfile *protogen.GeneratedFile, service *protogen.Service, component string) {
|
||||
func (g *Generator) generateServiceClientMethods(gfile *protogen.GeneratedFile, file *protogen.File, service *protogen.Service, component string) {
|
||||
serviceName := service.GoName
|
||||
for _, method := range service.Methods {
|
||||
methodName := fmt.Sprintf("%s.%s", serviceName, method.GoName)
|
||||
if component == "drpc" {
|
||||
methodName = fmt.Sprintf("%s.%s", method.Parent.Desc.FullName(), method.Desc.Name())
|
||||
}
|
||||
g.generateClientFuncSignature(gfile, serviceName, method)
|
||||
g.generateClientFuncSignature(gfile, serviceName, file, method)
|
||||
|
||||
if component == "http" && method.Desc.Options() != nil {
|
||||
if proto.HasExtension(method.Desc.Options(), v2.E_Openapiv2Operation) {
|
||||
@@ -141,7 +169,7 @@ func (g *Generator) generateServiceClientMethods(gfile *protogen.GeneratedFile,
|
||||
}
|
||||
|
||||
labelMethod:
|
||||
if proto.HasExtension(method.Desc.Options(), api_options.E_Http) {
|
||||
if proto.HasExtension(method.Desc.Options(), apioptions.E_Http) {
|
||||
gfile.P("opts = append(opts,")
|
||||
endpoints, _ := generateEndpoints(method)
|
||||
path, method, body := getEndpoint(endpoints[0])
|
||||
@@ -262,7 +290,7 @@ func (g *Generator) generateServiceClientMethods(gfile *protogen.GeneratedFile,
|
||||
gfile.P("}")
|
||||
}
|
||||
|
||||
if method.Desc.IsStreamingClient() && !method.Desc.IsStreamingServer() {
|
||||
if method.Desc.IsStreamingClient() /*&& !method.Desc.IsStreamingServer()*/ {
|
||||
gfile.P("func (s *", unexport(serviceName), "Client", method.GoName, ") CloseAndRecv() (*", gfile.QualifiedGoIdent(method.Output.GoIdent), ", error) {")
|
||||
gfile.P("msg := &", gfile.QualifiedGoIdent(method.Output.GoIdent), "{}")
|
||||
gfile.P("err := s.RecvMsg(msg)")
|
||||
@@ -327,7 +355,7 @@ func (g *Generator) generateServiceServer(gfile *protogen.GeneratedFile, file *p
|
||||
serviceName := service.GoName
|
||||
gfile.P("type ", unexport(serviceName), "Server struct {")
|
||||
if g.standalone {
|
||||
gfile.P(file.GoImportPath.Ident(serviceName), "Server")
|
||||
gfile.P(gfile.QualifiedGoIdent(file.GoImportPath.Ident(serviceName + "Server")))
|
||||
} else {
|
||||
gfile.P(serviceName, "Server")
|
||||
}
|
||||
@@ -432,7 +460,7 @@ func (g *Generator) generateServiceServerMethods(gfile *protogen.GeneratedFile,
|
||||
gfile.P("}")
|
||||
}
|
||||
|
||||
if method.Desc.IsStreamingClient() && !method.Desc.IsStreamingServer() {
|
||||
if /*method.Desc.IsStreamingClient() && !*/ method.Desc.IsStreamingServer() {
|
||||
gfile.P("func (s *", unexport(serviceName), method.GoName, "Stream) SendAndClose(msg *", gfile.QualifiedGoIdent(method.Output.GoIdent), ") error {")
|
||||
gfile.P("err := s.SendMsg(msg)")
|
||||
gfile.P("if err == nil {")
|
||||
@@ -488,28 +516,29 @@ func (g *Generator) generateServiceServerMethods(gfile *protogen.GeneratedFile,
|
||||
func (g *Generator) generateServiceRegister(gfile *protogen.GeneratedFile, file *protogen.File, service *protogen.Service, component string) {
|
||||
serviceName := service.GoName
|
||||
if g.standalone {
|
||||
gfile.P("func Register", serviceName, "Server(s ", microServerPackage.Ident("Server"), ", sh ", file.GoImportPath.Ident(serviceName), "Server, opts ...", microServerPackage.Ident("HandlerOption"), ") error {")
|
||||
gfile.P("func Register", serviceName, "Server(s ", microServerPackage.Ident("Server"), ", sh ", gfile.QualifiedGoIdent(file.GoImportPath.Ident(serviceName+"Server")), ", opts ...", microServerPackage.Ident("HandlerOption"), ") error {")
|
||||
} else {
|
||||
gfile.P("func Register", serviceName, "Server(s ", microServerPackage.Ident("Server"), ", sh ", serviceName, "Server, opts ...", microServerPackage.Ident("HandlerOption"), ") error {")
|
||||
}
|
||||
gfile.P("type ", unexport(serviceName), " interface {")
|
||||
var generate bool
|
||||
for _, method := range service.Methods {
|
||||
generateServerSignature(gfile, serviceName, method, true)
|
||||
if endpoints, _ := generateEndpoints(method); endpoints != nil {
|
||||
generate = true
|
||||
}
|
||||
}
|
||||
gfile.P("}")
|
||||
gfile.P("type ", serviceName, " struct {")
|
||||
gfile.P(unexport(serviceName))
|
||||
gfile.P("}")
|
||||
gfile.P("h := &", unexport(serviceName), "Server{sh}")
|
||||
gfile.P("var nopts []", microServerPackage.Ident("HandlerOption"))
|
||||
if component == "http" {
|
||||
// if g.standalone {
|
||||
// gfile.P("nopts = append(nopts, ", microServerHttpPackage.Ident("HandlerEndpoints"), "(", file.GoImportPath.Ident(serviceName), "ServerEndpoints))")
|
||||
// } else {
|
||||
gfile.P("nopts = append(nopts, ", microServerHttpPackage.Ident("HandlerEndpoints"), "(", serviceName, "ServerEndpoints))")
|
||||
// }
|
||||
|
||||
if component == "http" && generate {
|
||||
gfile.P("opts = append(opts, ", microServerHttpPackage.Ident("HandlerEndpoints"), "(", serviceName, "ServerEndpoints))")
|
||||
}
|
||||
gfile.P("return s.Handle(s.NewHandler(&", serviceName, "{h}, append(nopts, opts...)...))")
|
||||
|
||||
gfile.P("return s.Handle(s.NewHandler(&", serviceName, "{h}, opts...))")
|
||||
gfile.P("}")
|
||||
}
|
||||
|
||||
@@ -557,7 +586,7 @@ func generateServerSignature(gfile *protogen.GeneratedFile, serviceName string,
|
||||
gfile.P(args...)
|
||||
}
|
||||
|
||||
func (g *Generator) generateClientFuncSignature(gfile *protogen.GeneratedFile, serviceName string, method *protogen.Method) {
|
||||
func (g *Generator) generateClientFuncSignature(gfile *protogen.GeneratedFile, serviceName string, file *protogen.File, method *protogen.Method) {
|
||||
args := append([]interface{}{},
|
||||
"func (c *",
|
||||
unexport(serviceName),
|
||||
@@ -572,7 +601,11 @@ func (g *Generator) generateClientFuncSignature(gfile *protogen.GeneratedFile, s
|
||||
if !method.Desc.IsStreamingClient() && !method.Desc.IsStreamingServer() {
|
||||
args = append(args, "*", gfile.QualifiedGoIdent(method.Output.GoIdent))
|
||||
} else {
|
||||
args = append(args, serviceName, "_", method.GoName, "Client")
|
||||
if g.standalone {
|
||||
args = append(args, gfile.QualifiedGoIdent(file.GoImportPath.Ident(serviceName+"_"+method.GoName+"Client")))
|
||||
} else {
|
||||
args = append(args, serviceName+"_"+method.GoName+"Client")
|
||||
}
|
||||
}
|
||||
args = append(args, ", error) {")
|
||||
gfile.P(args...)
|
||||
@@ -627,7 +660,7 @@ func (g *Generator) generateServiceClientStreamInterface(gfile *protogen.Generat
|
||||
gfile.P("Context() ", contextPackage.Ident("Context"))
|
||||
gfile.P("SendMsg(msg interface{}) error")
|
||||
gfile.P("RecvMsg(msg interface{}) error")
|
||||
if method.Desc.IsStreamingClient() && !method.Desc.IsStreamingServer() {
|
||||
if method.Desc.IsStreamingClient() /*&& !method.Desc.IsStreamingServer()*/ {
|
||||
gfile.P("CloseAndRecv() (*", gfile.QualifiedGoIdent(method.Output.GoIdent), ", error)")
|
||||
gfile.P("CloseSend() error")
|
||||
}
|
||||
@@ -655,9 +688,9 @@ func (g *Generator) generateServiceServerStreamInterface(gfile *protogen.Generat
|
||||
gfile.P("Context() ", contextPackage.Ident("Context"))
|
||||
gfile.P("SendMsg(msg interface{}) error")
|
||||
gfile.P("RecvMsg(msg interface{}) error")
|
||||
if method.Desc.IsStreamingClient() && !method.Desc.IsStreamingServer() {
|
||||
if /*method.Desc.IsStreamingClient() && !*/ method.Desc.IsStreamingServer() {
|
||||
gfile.P("SendAndClose(msg *", gfile.QualifiedGoIdent(method.Output.GoIdent), ") error")
|
||||
gfile.P("CloseSend() error")
|
||||
// gfile.P("CloseSend() error")
|
||||
}
|
||||
gfile.P("Close() error")
|
||||
if method.Desc.IsStreamingClient() {
|
||||
@@ -671,64 +704,64 @@ func (g *Generator) generateServiceServerStreamInterface(gfile *protogen.Generat
|
||||
}
|
||||
}
|
||||
|
||||
func generateEndpoints(method *protogen.Method) ([]*api_options.HttpRule, bool) {
|
||||
func generateEndpoints(method *protogen.Method) ([]*apioptions.HttpRule, bool) {
|
||||
if method.Desc.Options() == nil {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
if !proto.HasExtension(method.Desc.Options(), api_options.E_Http) {
|
||||
if !proto.HasExtension(method.Desc.Options(), apioptions.E_Http) {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
r := proto.GetExtension(method.Desc.Options(), api_options.E_Http)
|
||||
r := proto.GetExtension(method.Desc.Options(), apioptions.E_Http)
|
||||
if r == nil {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
rule := r.(*api_options.HttpRule)
|
||||
rules := []*api_options.HttpRule{rule}
|
||||
rule := r.(*apioptions.HttpRule)
|
||||
rules := []*apioptions.HttpRule{rule}
|
||||
rules = append(rules, rule.GetAdditionalBindings()...)
|
||||
|
||||
return rules, method.Desc.IsStreamingServer() || method.Desc.IsStreamingClient()
|
||||
}
|
||||
|
||||
func getMicroApiMethod(method *protogen.Method) (*api_options.MicroMethod, bool) {
|
||||
func getMicroApiMethod(method *protogen.Method) (*apioptions.MicroMethod, bool) {
|
||||
if method.Desc.Options() == nil {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
if !proto.HasExtension(method.Desc.Options(), api_options.E_MicroMethod) {
|
||||
if !proto.HasExtension(method.Desc.Options(), apioptions.E_MicroMethod) {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
r := proto.GetExtension(method.Desc.Options(), api_options.E_MicroMethod)
|
||||
r := proto.GetExtension(method.Desc.Options(), apioptions.E_MicroMethod)
|
||||
if r == nil {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
rule := r.(*api_options.MicroMethod)
|
||||
rule := r.(*apioptions.MicroMethod)
|
||||
return rule, true
|
||||
}
|
||||
|
||||
func getMicroApiService(service *protogen.Service) (*api_options.MicroService, bool) {
|
||||
func getMicroApiService(service *protogen.Service) (*apioptions.MicroService, bool) {
|
||||
if service.Desc.Options() == nil {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
if !proto.HasExtension(service.Desc.Options(), api_options.E_MicroService) {
|
||||
if !proto.HasExtension(service.Desc.Options(), apioptions.E_MicroService) {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
r := proto.GetExtension(service.Desc.Options(), api_options.E_MicroService)
|
||||
r := proto.GetExtension(service.Desc.Options(), apioptions.E_MicroService)
|
||||
if r == nil {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
rule := r.(*api_options.MicroService)
|
||||
rule := r.(*apioptions.MicroService)
|
||||
return rule, true
|
||||
}
|
||||
|
||||
func getEndpoint(rule *api_options.HttpRule) (string, string, string) {
|
||||
func getEndpoint(rule *apioptions.HttpRule) (string, string, string) {
|
||||
var meth string
|
||||
var path string
|
||||
var body string
|
||||
@@ -759,7 +792,7 @@ func getEndpoint(rule *api_options.HttpRule) (string, string, string) {
|
||||
return path, meth, body
|
||||
}
|
||||
|
||||
func generateEndpoint(gfile *protogen.GeneratedFile, serviceName string, methodName string, rule *api_options.HttpRule, streaming bool) {
|
||||
func generateEndpoint(gfile *protogen.GeneratedFile, serviceName string, methodName string, rule *apioptions.HttpRule, streaming bool) {
|
||||
path, meth, body := getEndpoint(rule)
|
||||
gfile.P("Name:", fmt.Sprintf(`"%s.%s",`, serviceName, methodName))
|
||||
gfile.P("Path:", fmt.Sprintf(`[]string{"%s"},`, path))
|
||||
@@ -843,7 +876,11 @@ func (g *Generator) generateServiceDesc(gfile *protogen.GeneratedFile, file *pro
|
||||
gfile.P("// and not to be introspected or modified (even as a copy)")
|
||||
gfile.P("var ", serviceName, "_ServiceDesc", " = ", grpcPackage.Ident("ServiceDesc"), " {")
|
||||
gfile.P("ServiceName: ", strconv.Quote(string(service.Desc.FullName())), ",")
|
||||
gfile.P("HandlerType: (*", serviceName, "Server)(nil),")
|
||||
if g.standalone {
|
||||
gfile.P("HandlerType: (*", gfile.QualifiedGoIdent(file.GoImportPath.Ident(serviceName+"Server")), ")(nil),")
|
||||
} else {
|
||||
gfile.P("HandlerType: (*", serviceName, "Server)(nil),")
|
||||
}
|
||||
gfile.P("Methods: []", grpcPackage.Ident("MethodDesc"), "{")
|
||||
for _, method := range service.Methods {
|
||||
if method.Desc.IsStreamingClient() || method.Desc.IsStreamingServer() {
|
||||
@@ -888,14 +925,18 @@ func (g *Generator) generateServiceEndpoints(gfile *protogen.GeneratedFile, serv
|
||||
if component != "http" {
|
||||
return
|
||||
}
|
||||
|
||||
var generate bool
|
||||
serviceName := service.GoName
|
||||
|
||||
gfile.P("var (")
|
||||
gfile.P(serviceName, "ServerEndpoints = []", microServerHttpPackage.Ident("EndpointMetadata"), "{")
|
||||
|
||||
for _, method := range service.Methods {
|
||||
if proto.HasExtension(method.Desc.Options(), api_options.E_Http) {
|
||||
if proto.HasExtension(method.Desc.Options(), apioptions.E_Http) {
|
||||
if endpoints, streaming := generateEndpoints(method); endpoints != nil {
|
||||
if !generate {
|
||||
gfile.P("var (")
|
||||
gfile.P(serviceName, "ServerEndpoints = []", microServerHttpPackage.Ident("EndpointMetadata"), "{")
|
||||
generate = true
|
||||
}
|
||||
for _, ep := range endpoints {
|
||||
epath, emethod, ebody := getEndpoint(ep)
|
||||
gfile.P("{")
|
||||
@@ -910,8 +951,10 @@ func (g *Generator) generateServiceEndpoints(gfile *protogen.GeneratedFile, serv
|
||||
}
|
||||
}
|
||||
|
||||
gfile.P("}")
|
||||
gfile.P(")")
|
||||
if generate {
|
||||
gfile.P("}")
|
||||
gfile.P(")")
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Generator) writeErrors(plugin *protogen.Plugin) error {
|
||||
|
||||
27
variables.go
27
variables.go
@@ -1,6 +1,10 @@
|
||||
package main
|
||||
|
||||
import "google.golang.org/protobuf/compiler/protogen"
|
||||
import (
|
||||
"runtime/debug"
|
||||
|
||||
"google.golang.org/protobuf/compiler/protogen"
|
||||
)
|
||||
|
||||
var (
|
||||
ioPackage = protogen.GoImportPath("io")
|
||||
@@ -13,16 +17,21 @@ var (
|
||||
gorillaMuxPackage = protogen.GoImportPath("github.com/gorilla/mux")
|
||||
chiPackage = protogen.GoImportPath("github.com/go-chi/chi/v5")
|
||||
chiMiddlewarePackage = protogen.GoImportPath("github.com/go-chi/chi/v5/middleware")
|
||||
microMetadataPackage = protogen.GoImportPath("go.unistack.org/micro/v3/metadata")
|
||||
microClientPackage = protogen.GoImportPath("go.unistack.org/micro/v3/client")
|
||||
microServerPackage = protogen.GoImportPath("go.unistack.org/micro/v3/server")
|
||||
microClientHttpPackage = protogen.GoImportPath("go.unistack.org/micro-client-http/v3")
|
||||
microServerHttpPackage = protogen.GoImportPath("go.unistack.org/micro-server-http/v3")
|
||||
microCodecPackage = protogen.GoImportPath("go.unistack.org/micro-proto/v3/codec")
|
||||
microErrorsPackage = protogen.GoImportPath("go.unistack.org/micro/v3/errors")
|
||||
microMetadataPackage = protogen.GoImportPath("go.unistack.org/micro/v4/metadata")
|
||||
microClientPackage = protogen.GoImportPath("go.unistack.org/micro/v4/client")
|
||||
microServerPackage = protogen.GoImportPath("go.unistack.org/micro/v4/server")
|
||||
microClientHttpPackage = protogen.GoImportPath("go.unistack.org/micro-client-http/v4")
|
||||
microServerHttpPackage = protogen.GoImportPath("go.unistack.org/micro-server-http/v4")
|
||||
microCodecPackage = protogen.GoImportPath("go.unistack.org/micro-proto/v4/codec")
|
||||
microErrorsPackage = protogen.GoImportPath("go.unistack.org/micro/v4/errors")
|
||||
grpcPackage = protogen.GoImportPath("google.golang.org/grpc")
|
||||
protojsonPackage = protogen.GoImportPath("google.golang.org/protobuf/encoding/protojson")
|
||||
timePackage = protogen.GoImportPath("time")
|
||||
deprecationComment = "// Deprecated: Do not use."
|
||||
versionComment = "v3.10.4"
|
||||
versionComment = func() string {
|
||||
if info, ok := debug.ReadBuildInfo(); ok && info.Main.Version != "" && info.Main.Version != "(devel)" {
|
||||
return info.Main.Version
|
||||
}
|
||||
return "(devel)"
|
||||
}()
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user