Compare commits

...

12 Commits

Author SHA1 Message Date
dependabot[bot]
28257eac2e Bump golang.org/x/tools from 0.28.0 to 0.33.0 (#98)
Some checks failed
coverage / build (push) Failing after 46s
test / test (push) Successful in 3m33s
Bumps [golang.org/x/tools](https://github.com/golang/tools) from 0.28.0 to 0.33.0.
- [Release notes](https://github.com/golang/tools/releases)
- [Commits](https://github.com/golang/tools/compare/v0.28.0...v0.33.0)

---
updated-dependencies:
- dependency-name: golang.org/x/tools
  dependency-version: 0.33.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-05-12 18:20:45 +03:00
dependabot[bot]
8bd8adbd27 Bump github.com/vektah/gqlparser/v2 from 2.5.20 to 2.5.27 (#99)
Bumps [github.com/vektah/gqlparser/v2](https://github.com/vektah/gqlparser) from 2.5.20 to 2.5.27.
- [Release notes](https://github.com/vektah/gqlparser/releases)
- [Commits](https://github.com/vektah/gqlparser/compare/v2.5.20...v2.5.27)

---
updated-dependencies:
- dependency-name: github.com/vektah/gqlparser/v2
  dependency-version: 2.5.27
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-05-12 18:20:45 +03:00
fb2a59d2f2 sync github stuff
Some checks failed
sync / sync (push) Failing after 8s
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2025-05-12 18:17:24 +03:00
091e964bd4 resurrect old standalone detection
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2025-05-06 17:45:22 +03:00
25bf4f9483 move backward for v3 => v4 gen
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2025-04-24 12:09:00 +03:00
3d92ee0003 standalone checks
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2025-03-01 13:36:44 +03:00
750c949723 fix codegen for streams
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2025-01-09 18:00:13 +03:00
4633928da5 update deps
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2024-12-13 16:13:51 +03:00
5ecd91182f Merge pull request 'graphql' (#91) from graphql into v3
Reviewed-on: #91
2024-06-11 20:46:55 +03:00
a8b52d800d Merge branch 'v3' into graphql 2024-06-11 20:46:45 +03:00
9c05b6b646 Merge pull request 'fix gen' (#89) from fixu into v3
Reviewed-on: #89
2023-12-26 00:56:08 +03:00
675ca27dbf fix gen
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2023-12-26 00:55:09 +03:00
32 changed files with 1762 additions and 380 deletions

View File

@@ -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
```

View File

@@ -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.

View File

@@ -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
View 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 }}

View File

@@ -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"

View File

@@ -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 }}

View File

@@ -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}}

View File

@@ -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

View File

@@ -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

View File

@@ -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
View 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
View 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
View 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
View 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
View 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

View File

@@ -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

View File

@@ -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`

2
ast.go
View File

@@ -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/v4/tag"
"google.golang.org/protobuf/compiler/protogen"
"google.golang.org/protobuf/proto"
)

View File

@@ -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 = "github.com/unistack-org/protoc-gen-go-micro/v4/example;examplepb";
import "tag/tag.proto";
import "api/annotations.proto";

View File

@@ -1,3 +1,3 @@
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/v4) --go-micro_out=components=graphqls,graphql_file=./schema.graphql:./example example/example.proto"

36
go.mod
View File

@@ -1,24 +1,30 @@
module go.unistack.org/protoc-gen-go-micro/v3
module go.unistack.org/protoc-gen-go-micro/v4
go 1.20
go 1.22.0
toolchain go1.24.1
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.17.0
github.com/vektah/gqlparser/v2 v2.5.27
go.unistack.org/micro-proto/v4 v4.1.0
golang.org/x/tools v0.33.0
google.golang.org/protobuf v1.35.2
)
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/bufbuild/protocompile v0.14.1 // 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.0 // indirect
github.com/google/gnostic-models v0.6.9 // 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.13.1 // indirect
golang.org/x/mod v0.24.0 // indirect
golang.org/x/sync v0.14.0 // indirect
golang.org/x/text v0.21.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241209162323-e6fa225c2576 // indirect
google.golang.org/grpc v1.68.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

1441
go.sum

File diff suppressed because it is too large Load Diff

View File

@@ -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 (

View File

@@ -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 {

View File

@@ -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/v4/graphql"
"google.golang.org/protobuf/compiler/protogen"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/pluginpb"

View File

@@ -41,7 +41,7 @@ func (g *Generator) httpGenerate(component string, plugin *protogen.Plugin, genC
g.generateServiceEndpoints(gfile, service, component)
if genClient {
g.generateServiceClient(gfile, file, service)
g.generateServiceClientMethods(gfile, service, component)
g.generateServiceClientMethods(gfile, file, service, component)
}
if genServer {
g.generateServiceServer(gfile, file, service)

View File

@@ -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/v4/api"
v3 "go.unistack.org/micro-proto/v4/openapiv3"
"google.golang.org/protobuf/compiler/protogen"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protoreflect"

View File

@@ -1,6 +1,6 @@
package main
import v3 "go.unistack.org/micro-proto/v3/openapiv3"
import v3 "go.unistack.org/micro-proto/v4/openapiv3"
func getMediaType(eopt interface{}) string {
ctype := "application/json"

2
rpc.go
View File

@@ -38,7 +38,7 @@ func (g *Generator) rpcGenerate(component string, plugin *protogen.Plugin, genCl
for _, service := range file.Services {
if genClient {
g.generateServiceClient(gfile, file, service)
g.generateServiceClientMethods(gfile, service, component)
g.generateServiceClientMethods(gfile, file, service, component)
}
if genServer {
g.generateServiceServer(gfile, file, service)

View File

@@ -3,5 +3,5 @@
package tools
import (
_ "go.unistack.org/micro-proto/v3/graphql"
_ "go.unistack.org/micro-proto/v4/graphql"
)

59
util.go
View File

@@ -8,9 +8,9 @@ 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"
api_options "go.unistack.org/micro-proto/v4/api"
v2 "go.unistack.org/micro-proto/v4/openapiv2"
v3 "go.unistack.org/micro-proto/v4/openapiv3"
"google.golang.org/protobuf/compiler/protogen"
"google.golang.org/protobuf/proto"
)
@@ -51,14 +51,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) {
@@ -262,7 +262,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)")
@@ -432,7 +432,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 {")
@@ -493,23 +493,24 @@ func (g *Generator) generateServiceRegister(gfile *protogen.GeneratedFile, file
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 +558,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 +573,9 @@ 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")
// TODO
// args = append(args, gfile.QualifiedGoIdent(protogen.GoIdent{GoName: serviceName + "_" + method.GoName + "Client", GoImportPath: method.Output.GoIdent.GoImportPath}))
args = append(args, serviceName+"_"+method.GoName+"Client")
}
args = append(args, ", error) {")
gfile.P(args...)
@@ -627,7 +630,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 +658,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() {
@@ -888,14 +891,18 @@ func (g *Generator) generateServiceEndpoints(gfile *protogen.GeneratedFile, serv
if component != "http" {
return
}
serviceName := service.GoName
gfile.P("var (")
gfile.P(serviceName, "ServerEndpoints = []", microServerHttpPackage.Ident("EndpointMetadata"), "{")
var generate bool
serviceName := service.GoName
for _, method := range service.Methods {
if proto.HasExtension(method.Desc.Options(), api_options.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 +917,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 {

View File

@@ -13,13 +13,13 @@ 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")