Compare commits
104 Commits
Author | SHA1 | Date | |
---|---|---|---|
66d47cc824 | |||
5e9461f34d | |||
8233baf722 | |||
ce2227cb6f | |||
|
acffa04713 | ||
0715891c86 | |||
9e8cb4ad41 | |||
4a9eeecbf1 | |||
9f3f627434 | |||
86c6e2e006 | |||
185449b5b0 | |||
7b50d918cd | |||
|
d8179f0be1 | ||
76254c1ed3 | |||
|
854bcefd10 | ||
d1d9b4a326 | |||
|
c814d0d0f7 | ||
b6edce9800 | |||
|
95a31d6c40 | ||
84ee05886d | |||
|
7c276416b0 | ||
bdbc322132 | |||
|
5d1ea4a86f | ||
f119f97020 | |||
|
3e54b2c1ef | ||
|
7a64bedab4 | ||
|
4b5849ae5b | ||
8702cd6fd8 | |||
|
45ee75730c | ||
03cc0fa01f | |||
|
6f8b7d98a9 | ||
c4b74c301d | |||
|
6e774e5e9a | ||
298fb5e2b7 | |||
|
02041ee927 | ||
31e7fd2de0 | |||
|
b2f2c1ff67 | ||
b859dec684 | |||
|
07b176d757 | ||
bc4b60cf93 | |||
|
1524c4b5cc | ||
|
a8643e60bb | ||
399a408099 | |||
|
6457e00aa5 | ||
a7bc319f9e | |||
|
96d957afe1 | ||
|
11b962d6dd | ||
|
1f8fb20c2d | ||
|
96ae6cab79 | ||
|
8b92293d23 | ||
|
a109b5f091 | ||
57e65ad357 | |||
|
539c638b23 | ||
ec5d9018d3 | |||
|
168280923a | ||
|
e6a81fcd1c | ||
8a481a4807 | |||
|
534c481166 | ||
|
dea6a66f85 | ||
|
bdc01f3f97 | ||
512345ab76 | |||
|
5939dfe58e | ||
1ea4783e90 | |||
|
325f960bc3 | ||
b67e8c6678 | |||
|
6fc1caa836 | ||
8b89d788b6 | |||
|
5f8ebd3e63 | ||
ba4ff82b2e | |||
|
bb75aae8de | ||
fddcd6ed99 | |||
|
6aace39310 | ||
52a9c67634 | |||
|
7feab14caf | ||
d280f6c9cb | |||
5057e0193e | |||
e146cf31a7 | |||
|
a3966dadfa | ||
632be82ca3 | |||
|
4c7a46c69f | ||
ac08d033c7 | |||
|
a1294521f0 | ||
990f72a998 | |||
|
159205b5f3 | ||
7a252b48a4 | |||
|
0055a78179 | ||
823e5b5fbb | |||
|
daeff6e5bb | ||
2e63ea772b | |||
|
cc98e26597 | ||
0e8ccccfa1 | |||
|
616eb8f742 | ||
848e168897 | |||
|
61e541bba3 | ||
7b8e26998e | |||
|
3cb1b6672f | ||
a56c89647f | |||
|
e146cc590e | ||
a7e0059ba2 | |||
|
39be7d79f5 | ||
3ba5c31e66 | |||
|
ea135d1b0f | ||
639f687e7a | |||
27cc4bbec2 |
29
.gitea/workflows/job_lint.yml
Normal file
29
.gitea/workflows/job_lint.yml
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
name: lint
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
types: [opened, reopened, synchronize]
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
- v3
|
||||||
|
- v4
|
||||||
|
|
||||||
|
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: https://github.com/golangci/golangci-lint-action@v6
|
||||||
|
with:
|
||||||
|
version: 'latest'
|
34
.gitea/workflows/job_test.yml
Normal file
34
.gitea/workflows/job_test.yml
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
name: test
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
types: [opened, reopened, synchronize]
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
- v3
|
||||||
|
- v4
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
- v3
|
||||||
|
- v4
|
||||||
|
|
||||||
|
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 ./...
|
53
.gitea/workflows/job_tests.yml
Normal file
53
.gitea/workflows/job_tests.yml
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
name: test
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
types: [opened, reopened, synchronize]
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
- v3
|
||||||
|
- v4
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
- v3
|
||||||
|
- v4
|
||||||
|
|
||||||
|
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: /workspace/${{ github.repository_owner }}/go.work
|
||||||
|
run: |
|
||||||
|
go work init
|
||||||
|
go work use .
|
||||||
|
go work use micro-tests
|
||||||
|
- name: setup deps
|
||||||
|
env:
|
||||||
|
GOWORK: /workspace/${{ github.repository_owner }}/go.work
|
||||||
|
run: go get -v ./...
|
||||||
|
- name: run tests
|
||||||
|
env:
|
||||||
|
INTEGRATION_TESTS: yes
|
||||||
|
GOWORK: /workspace/${{ github.repository_owner }}/go.work
|
||||||
|
run: |
|
||||||
|
cd micro-tests
|
||||||
|
go test -mod readonly -v ./... || true
|
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"
|
|
46
.github/workflows/build.yml
vendored
46
.github/workflows/build.yml
vendored
@ -1,46 +0,0 @@
|
|||||||
name: build
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
jobs:
|
|
||||||
test:
|
|
||||||
name: test
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: setup
|
|
||||||
uses: actions/setup-go@v2
|
|
||||||
with:
|
|
||||||
go-version: 1.16
|
|
||||||
- name: checkout
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
- name: cache
|
|
||||||
uses: actions/cache@v2
|
|
||||||
with:
|
|
||||||
path: ~/go/pkg/mod
|
|
||||||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
|
||||||
restore-keys: ${{ runner.os }}-go-
|
|
||||||
- name: deps
|
|
||||||
run: go get -v -t -d ./...
|
|
||||||
- name: test
|
|
||||||
env:
|
|
||||||
INTEGRATION_TESTS: yes
|
|
||||||
run: go test -mod readonly -v ./...
|
|
||||||
lint:
|
|
||||||
name: lint
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: checkout
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
- name: lint
|
|
||||||
uses: golangci/golangci-lint-action@v2
|
|
||||||
continue-on-error: true
|
|
||||||
with:
|
|
||||||
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
|
|
||||||
version: v1.30
|
|
||||||
# Optional: working directory, useful for monorepos
|
|
||||||
# working-directory: somedir
|
|
||||||
# Optional: golangci-lint command line arguments.
|
|
||||||
# args: --issues-exit-code=0
|
|
||||||
# Optional: show only new issues if it's a pull request. The default value is `false`.
|
|
||||||
# only-new-issues: true
|
|
75
.github/workflows/codeql-analysis.yml
vendored
75
.github/workflows/codeql-analysis.yml
vendored
@ -1,75 +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 ]
|
|
||||||
pull_request:
|
|
||||||
# The branches below must be a subset of the branches above
|
|
||||||
branches: [ master ]
|
|
||||||
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 repository
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
|
|
||||||
# Initializes the CodeQL tools for scanning.
|
|
||||||
- name: Initialize CodeQL
|
|
||||||
uses: github/codeql-action/init@v1
|
|
||||||
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@v1
|
|
||||||
|
|
||||||
# ℹ️ 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: Perform CodeQL Analysis
|
|
||||||
uses: github/codeql-action/analyze@v1
|
|
66
.github/workflows/dependabot-automerge.yml
vendored
66
.github/workflows/dependabot-automerge.yml
vendored
@ -1,66 +0,0 @@
|
|||||||
name: "prautomerge"
|
|
||||||
|
|
||||||
on:
|
|
||||||
workflow_run:
|
|
||||||
workflows: ["prbuild"]
|
|
||||||
types:
|
|
||||||
- completed
|
|
||||||
|
|
||||||
permissions:
|
|
||||||
contents: write
|
|
||||||
pull-requests: write
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
Dependabot-Automerge:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
# Contains workaround to execute if dependabot updates the PR by checking for the base branch in the linked PR
|
|
||||||
# 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:
|
|
||||||
- name: Approve Changes and Merge changes if label 'dependencies' is set
|
|
||||||
uses: actions/github-script@v5
|
|
||||||
with:
|
|
||||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
script: |
|
|
||||||
console.log(context.payload.workflow_run);
|
|
||||||
|
|
||||||
var labelNames = await github.paginate(
|
|
||||||
github.issues.listLabelsOnIssue,
|
|
||||||
{
|
|
||||||
repo: context.repo.repo,
|
|
||||||
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');
|
|
||||||
}
|
|
46
.github/workflows/pr.yml
vendored
46
.github/workflows/pr.yml
vendored
@ -1,46 +0,0 @@
|
|||||||
name: prbuild
|
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
jobs:
|
|
||||||
test:
|
|
||||||
name: test
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: setup
|
|
||||||
uses: actions/setup-go@v2
|
|
||||||
with:
|
|
||||||
go-version: 1.16
|
|
||||||
- name: checkout
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
- name: cache
|
|
||||||
uses: actions/cache@v2
|
|
||||||
with:
|
|
||||||
path: ~/go/pkg/mod
|
|
||||||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
|
||||||
restore-keys: ${{ runner.os }}-go-
|
|
||||||
- name: deps
|
|
||||||
run: go get -v -t -d ./...
|
|
||||||
- name: test
|
|
||||||
env:
|
|
||||||
INTEGRATION_TESTS: yes
|
|
||||||
run: go test -mod readonly -v ./...
|
|
||||||
lint:
|
|
||||||
name: lint
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: checkout
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
- name: lint
|
|
||||||
uses: golangci/golangci-lint-action@v2
|
|
||||||
continue-on-error: true
|
|
||||||
with:
|
|
||||||
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
|
|
||||||
version: v1.30
|
|
||||||
# Optional: working directory, useful for monorepos
|
|
||||||
# working-directory: somedir
|
|
||||||
# Optional: golangci-lint command line arguments.
|
|
||||||
# args: --issues-exit-code=0
|
|
||||||
# Optional: show only new issues if it's a pull request. The default value is `false`.
|
|
||||||
# only-new-issues: true
|
|
5
.golangci.yml
Normal file
5
.golangci.yml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
run:
|
||||||
|
concurrency: 8
|
||||||
|
deadline: 5m
|
||||||
|
issues-exit-code: 1
|
||||||
|
tests: true
|
@ -28,7 +28,7 @@ func TestFrameFlatten(t *testing.T) {
|
|||||||
Name: &codec.Frame{Data: []byte("test")},
|
Name: &codec.Frame{Data: []byte("test")},
|
||||||
}
|
}
|
||||||
|
|
||||||
buf, err := NewCodec().Marshal(s)
|
buf, err := NewCodec(codec.Flatten(true)).Marshal(s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -36,16 +36,3 @@ func TestFrameFlatten(t *testing.T) {
|
|||||||
t.Fatalf("bytes not equal %s != %s", buf, `test`)
|
t.Fatalf("bytes not equal %s != %s", buf, `test`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestReadBody(t *testing.T) {
|
|
||||||
t.Skip("skip without proto message")
|
|
||||||
s := &struct {
|
|
||||||
Name string
|
|
||||||
}{}
|
|
||||||
c := NewCodec()
|
|
||||||
b := bytes.NewReader(nil)
|
|
||||||
err := c.ReadBody(b, s)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
11
go.mod
11
go.mod
@ -1,8 +1,13 @@
|
|||||||
module go.unistack.org/micro-codec-jsonpb/v3
|
module go.unistack.org/micro-codec-jsonpb/v3
|
||||||
|
|
||||||
go 1.16
|
go 1.21
|
||||||
|
|
||||||
|
toolchain go1.23.4
|
||||||
|
|
||||||
require (
|
require (
|
||||||
go.unistack.org/micro/v3 v3.8.4
|
go.unistack.org/micro-proto/v3 v3.4.1
|
||||||
google.golang.org/protobuf v1.27.1
|
go.unistack.org/micro/v3 v3.10.35
|
||||||
|
google.golang.org/protobuf v1.35.2
|
||||||
)
|
)
|
||||||
|
|
||||||
|
require github.com/google/go-cmp v0.6.0 // indirect
|
||||||
|
31
go.sum
31
go.sum
@ -1,26 +1,5 @@
|
|||||||
github.com/ef-ds/deque v1.0.4/go.mod h1:gXDnTC3yqvBcHbq2lcExjtAcVrOnJCbMcZXmuj8Z4tg=
|
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||||
github.com/golang-jwt/jwt/v4 v4.1.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg=
|
go.unistack.org/micro-proto/v3 v3.4.1 h1:UTjLSRz2YZuaHk9iSlVqqsA50JQNAEK2ZFboGqtEa9Q=
|
||||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
go.unistack.org/micro/v3 v3.10.35 h1:TPo0cTgrk+PAGh7u/7tge2faSiYA0mC1n4oflOYl3v8=
|
||||||
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
|
go.unistack.org/micro/v3 v3.10.35/go.mod h1:eUgtvbtiiz6te93m0ZdmoecbitWwjdBmmr84srmEIKA=
|
||||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
google.golang.org/protobuf v1.35.2 h1:8Ar7bF+apOIoThw1EdZl0p1oWvMqTHmpA2fRTyZO8io=
|
||||||
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
|
|
||||||
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
|
|
||||||
github.com/silas/dag v0.0.0-20210626123444-3804bac2d6d4/go.mod h1:7RTUFBdIRC9nZ7/3RyRNH1bdqIShrDejd1YbLwgPS+I=
|
|
||||||
go.unistack.org/micro-proto/v3 v3.1.0 h1:q39FwjFiRZn+Ux/tt+d3bJTmDtsQQWa+3SLYVo1vLfA=
|
|
||||||
go.unistack.org/micro-proto/v3 v3.1.0/go.mod h1:DpRhYCBXlmSJ/AAXTmntvlh7kQkYU6eFvlmYAx4BQS8=
|
|
||||||
go.unistack.org/micro/v3 v3.8.4 h1:Nny6JT7TlDS0e5bPVmbbpKXrisMQ6q9cvao5uyaa3eo=
|
|
||||||
go.unistack.org/micro/v3 v3.8.4/go.mod h1:KMMmOmbgo/D52/rCAbqeKbBsgEEbSKM69he54J3ZIuA=
|
|
||||||
golang.org/x/net v0.0.0-20210928044308-7d9f5e0b762b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
|
||||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
|
||||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
|
||||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
|
||||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
|
|
||||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
|
||||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
|
||||||
google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ=
|
|
||||||
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
|
||||||
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
|
||||||
|
183
jsonpb.go
183
jsonpb.go
@ -1,9 +1,8 @@
|
|||||||
// Package jsonpb provides a json codec
|
// Package jsonpb provides a json protobuf codec
|
||||||
package jsonpb
|
package jsonpb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
pb "go.unistack.org/micro-proto/v3/codec"
|
||||||
|
|
||||||
"go.unistack.org/micro/v3/codec"
|
"go.unistack.org/micro/v3/codec"
|
||||||
rutil "go.unistack.org/micro/v3/util/reflect"
|
rutil "go.unistack.org/micro/v3/util/reflect"
|
||||||
jsonpb "google.golang.org/protobuf/encoding/protojson"
|
jsonpb "google.golang.org/protobuf/encoding/protojson"
|
||||||
@ -14,7 +13,7 @@ var (
|
|||||||
DefaultMarshalOptions = jsonpb.MarshalOptions{
|
DefaultMarshalOptions = jsonpb.MarshalOptions{
|
||||||
UseEnumNumbers: false,
|
UseEnumNumbers: false,
|
||||||
EmitUnpopulated: false,
|
EmitUnpopulated: false,
|
||||||
UseProtoNames: true,
|
UseProtoNames: false,
|
||||||
AllowPartial: false,
|
AllowPartial: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,8 +27,13 @@ type jsonpbCodec struct {
|
|||||||
opts codec.Options
|
opts codec.Options
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
type jsonpbCodecV2 struct {
|
||||||
flattenTag = "flatten"
|
opts codec.Options
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
_ codec.Codec = (*jsonpbCodec)(nil)
|
||||||
|
_ codec.CodecV2 = (*jsonpbCodecV2)(nil)
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *jsonpbCodec) Marshal(v interface{}, opts ...codec.Option) ([]byte, error) {
|
func (c *jsonpbCodec) Marshal(v interface{}, opts ...codec.Option) ([]byte, error) {
|
||||||
@ -42,26 +46,32 @@ func (c *jsonpbCodec) Marshal(v interface{}, opts ...codec.Option) ([]byte, erro
|
|||||||
o(&options)
|
o(&options)
|
||||||
}
|
}
|
||||||
|
|
||||||
if nv, nerr := rutil.StructFieldByTag(v, options.TagName, flattenTag); nerr == nil {
|
if options.Flatten {
|
||||||
|
if nv, nerr := rutil.StructFieldByTag(v, options.TagName, "flatten"); nerr == nil {
|
||||||
v = nv
|
v = nv
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if m, ok := v.(*codec.Frame); ok {
|
switch m := v.(type) {
|
||||||
|
case *codec.Frame:
|
||||||
return m.Data, nil
|
return m.Data, nil
|
||||||
}
|
case *pb.Frame:
|
||||||
|
return m.Data, nil
|
||||||
if _, ok := v.(proto.Message); !ok {
|
case proto.Message:
|
||||||
return nil, codec.ErrInvalidMessage
|
|
||||||
}
|
|
||||||
|
|
||||||
marshalOptions := DefaultMarshalOptions
|
marshalOptions := DefaultMarshalOptions
|
||||||
if options.Context != nil {
|
if options.Context != nil {
|
||||||
if f, ok := options.Context.Value(marshalOptionsKey{}).(jsonpb.MarshalOptions); ok {
|
if f, ok := options.Context.Value(marshalOptionsKey{}).(jsonpb.MarshalOptions); ok {
|
||||||
marshalOptions = f
|
marshalOptions = f
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return marshalOptions.Marshal(m)
|
||||||
return marshalOptions.Marshal(v.(proto.Message))
|
case codec.RawMessage:
|
||||||
|
return []byte(m), nil
|
||||||
|
case *codec.RawMessage:
|
||||||
|
return []byte(*m), nil
|
||||||
|
default:
|
||||||
|
return nil, codec.ErrInvalidMessage
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *jsonpbCodec) Unmarshal(d []byte, v interface{}, opts ...codec.Option) error {
|
func (c *jsonpbCodec) Unmarshal(d []byte, v interface{}, opts ...codec.Option) error {
|
||||||
@ -74,59 +84,36 @@ func (c *jsonpbCodec) Unmarshal(d []byte, v interface{}, opts ...codec.Option) e
|
|||||||
o(&options)
|
o(&options)
|
||||||
}
|
}
|
||||||
|
|
||||||
if nv, nerr := rutil.StructFieldByTag(v, options.TagName, flattenTag); nerr == nil {
|
if options.Flatten {
|
||||||
|
if nv, nerr := rutil.StructFieldByTag(v, options.TagName, "flatten"); nerr == nil {
|
||||||
v = nv
|
v = nv
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if m, ok := v.(*codec.Frame); ok {
|
switch m := v.(type) {
|
||||||
|
case *codec.Frame:
|
||||||
m.Data = d
|
m.Data = d
|
||||||
return nil
|
return nil
|
||||||
}
|
case *pb.Frame:
|
||||||
|
m.Data = d
|
||||||
if _, ok := v.(proto.Message); !ok {
|
return nil
|
||||||
return codec.ErrInvalidMessage
|
case proto.Message:
|
||||||
}
|
|
||||||
|
|
||||||
unmarshalOptions := DefaultUnmarshalOptions
|
unmarshalOptions := DefaultUnmarshalOptions
|
||||||
if options.Context != nil {
|
if options.Context != nil {
|
||||||
if f, ok := options.Context.Value(unmarshalOptionsKey{}).(jsonpb.UnmarshalOptions); ok {
|
if f, ok := options.Context.Value(unmarshalOptionsKey{}).(jsonpb.UnmarshalOptions); ok {
|
||||||
unmarshalOptions = f
|
unmarshalOptions = f
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return unmarshalOptions.Unmarshal(d, m)
|
||||||
return unmarshalOptions.Unmarshal(d, v.(proto.Message))
|
case *codec.RawMessage:
|
||||||
}
|
*m = append((*m)[0:0], d...)
|
||||||
|
|
||||||
func (c *jsonpbCodec) ReadHeader(conn io.Reader, m *codec.Message, t codec.MessageType) error {
|
|
||||||
return nil
|
return nil
|
||||||
}
|
case codec.RawMessage:
|
||||||
|
copy(m, d)
|
||||||
func (c *jsonpbCodec) ReadBody(conn io.Reader, v interface{}) error {
|
|
||||||
if v == nil {
|
|
||||||
return nil
|
return nil
|
||||||
}
|
default:
|
||||||
buf, err := io.ReadAll(conn)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
} else if len(buf) == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return c.Unmarshal(buf, v)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *jsonpbCodec) Write(conn io.Writer, m *codec.Message, v interface{}) error {
|
|
||||||
if v == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
buf, err := c.Marshal(v)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
} else if len(buf) == 0 {
|
|
||||||
return codec.ErrInvalidMessage
|
return codec.ErrInvalidMessage
|
||||||
}
|
}
|
||||||
_, err = conn.Write(buf)
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *jsonpbCodec) String() string {
|
func (c *jsonpbCodec) String() string {
|
||||||
@ -136,3 +123,91 @@ func (c *jsonpbCodec) String() string {
|
|||||||
func NewCodec(opts ...codec.Option) codec.Codec {
|
func NewCodec(opts ...codec.Option) codec.Codec {
|
||||||
return &jsonpbCodec{opts: codec.NewOptions(opts...)}
|
return &jsonpbCodec{opts: codec.NewOptions(opts...)}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *jsonpbCodecV2) Marshal(d []byte, v interface{}, opts ...codec.Option) ([]byte, error) {
|
||||||
|
if v == nil {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
options := c.opts
|
||||||
|
for _, o := range opts {
|
||||||
|
o(&options)
|
||||||
|
}
|
||||||
|
|
||||||
|
if options.Flatten {
|
||||||
|
if nv, nerr := rutil.StructFieldByTag(v, options.TagName, "flatten"); nerr == nil {
|
||||||
|
v = nv
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch m := v.(type) {
|
||||||
|
case *codec.Frame:
|
||||||
|
return m.Data, nil
|
||||||
|
case *pb.Frame:
|
||||||
|
return m.Data, nil
|
||||||
|
case proto.Message:
|
||||||
|
marshalOptions := DefaultMarshalOptions
|
||||||
|
if options.Context != nil {
|
||||||
|
if f, ok := options.Context.Value(marshalOptionsKey{}).(jsonpb.MarshalOptions); ok {
|
||||||
|
marshalOptions = f
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return marshalOptions.MarshalAppend(d[:0], m)
|
||||||
|
case codec.RawMessage:
|
||||||
|
return []byte(m), nil
|
||||||
|
case *codec.RawMessage:
|
||||||
|
return []byte(*m), nil
|
||||||
|
default:
|
||||||
|
return nil, codec.ErrInvalidMessage
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *jsonpbCodecV2) Unmarshal(d []byte, v interface{}, opts ...codec.Option) error {
|
||||||
|
if v == nil || len(d) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
options := c.opts
|
||||||
|
for _, o := range opts {
|
||||||
|
o(&options)
|
||||||
|
}
|
||||||
|
|
||||||
|
if options.Flatten {
|
||||||
|
if nv, nerr := rutil.StructFieldByTag(v, options.TagName, "flatten"); nerr == nil {
|
||||||
|
v = nv
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch m := v.(type) {
|
||||||
|
case *codec.Frame:
|
||||||
|
m.Data = d
|
||||||
|
return nil
|
||||||
|
case *pb.Frame:
|
||||||
|
m.Data = d
|
||||||
|
return nil
|
||||||
|
case proto.Message:
|
||||||
|
unmarshalOptions := DefaultUnmarshalOptions
|
||||||
|
if options.Context != nil {
|
||||||
|
if f, ok := options.Context.Value(unmarshalOptionsKey{}).(jsonpb.UnmarshalOptions); ok {
|
||||||
|
unmarshalOptions = f
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return unmarshalOptions.Unmarshal(d, m)
|
||||||
|
case *codec.RawMessage:
|
||||||
|
*m = append((*m)[0:0], d...)
|
||||||
|
return nil
|
||||||
|
case codec.RawMessage:
|
||||||
|
copy(m, d)
|
||||||
|
return nil
|
||||||
|
default:
|
||||||
|
return codec.ErrInvalidMessage
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *jsonpbCodecV2) String() string {
|
||||||
|
return "jsonpb"
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewCodecV2(opts ...codec.Option) codec.CodecV2 {
|
||||||
|
return &jsonpbCodecV2{opts: codec.NewOptions(opts...)}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user