Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
bd3dcf3637 | |||
b2419514b7 |
@@ -1,29 +0,0 @@
|
|||||||
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'
|
|
@@ -1,34 +0,0 @@
|
|||||||
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 ./...
|
|
@@ -1,53 +0,0 @@
|
|||||||
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
Normal file
19
.github/dependabot.yml
vendored
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
# 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
Normal file
20
.github/workflows/autoapprove.yml
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
name: "autoapprove"
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request_target:
|
||||||
|
types: [assigned, opened, synchronize, reopened]
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
pull-requests: write
|
||||||
|
contents: write
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
autoapprove:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: approve
|
||||||
|
uses: hmarr/auto-approve-action@v3
|
||||||
|
if: github.actor == 'vtolstov' || github.actor == 'dependabot[bot]'
|
||||||
|
id: approve
|
||||||
|
with:
|
||||||
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
21
.github/workflows/automerge.yml
vendored
Normal file
21
.github/workflows/automerge.yml
vendored
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
name: "automerge"
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request_target:
|
||||||
|
types: [assigned, opened, synchronize, reopened]
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
pull-requests: write
|
||||||
|
contents: write
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
automerge:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
if: github.actor == 'vtolstov'
|
||||||
|
steps:
|
||||||
|
- name: merge
|
||||||
|
id: merge
|
||||||
|
run: gh pr merge --auto --merge "$PR_URL"
|
||||||
|
env:
|
||||||
|
PR_URL: ${{github.event.pull_request.html_url}}
|
||||||
|
GITHUB_TOKEN: ${{secrets.TOKEN}}
|
47
.github/workflows/build.yml
vendored
Normal file
47
.github/workflows/build.yml
vendored
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
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
Normal file
78
.github/workflows/codeql-analysis.yml
vendored
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
# 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
Normal file
27
.github/workflows/dependabot-automerge.yml
vendored
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
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}}
|
47
.github/workflows/pr.yml
vendored
Normal file
47
.github/workflows/pr.yml
vendored
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
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,9 +1,38 @@
|
|||||||
run:
|
run:
|
||||||
concurrency: 8
|
|
||||||
deadline: 5m
|
deadline: 5m
|
||||||
issues-exit-code: 1
|
|
||||||
tests: true
|
|
||||||
modules-download-mode: readonly
|
modules-download-mode: readonly
|
||||||
skip-files:
|
skip-files:
|
||||||
- ".*\\.pb\\.go$"
|
- ".*\\.pb\\.go$"
|
||||||
- ".*\\.pb\\.micro\\.go$"
|
- ".*\\.pb\\.micro\\.go$"
|
||||||
|
linters:
|
||||||
|
disable-all: false
|
||||||
|
enable-all: false
|
||||||
|
enable:
|
||||||
|
- megacheck
|
||||||
|
- staticcheck
|
||||||
|
- deadcode
|
||||||
|
- varcheck
|
||||||
|
- gosimple
|
||||||
|
- unused
|
||||||
|
- prealloc
|
||||||
|
- scopelint
|
||||||
|
- gocritic
|
||||||
|
- goimports
|
||||||
|
- unconvert
|
||||||
|
- govet
|
||||||
|
- nakedret
|
||||||
|
- structcheck
|
||||||
|
- gosec
|
||||||
|
disable:
|
||||||
|
- maligned
|
||||||
|
- interfacer
|
||||||
|
- typecheck
|
||||||
|
- dupl
|
||||||
|
output:
|
||||||
|
format: colored-line-number
|
||||||
|
# print lines of code with issue, default is true
|
||||||
|
print-issued-lines: true
|
||||||
|
# print linter name in the end of issue text, default is true
|
||||||
|
print-linter-name: true
|
||||||
|
# make issues output unique by line, default is true
|
||||||
|
uniq-by-line: true
|
||||||
|
18
go.mod
18
go.mod
@@ -1,18 +1,16 @@
|
|||||||
module go.unistack.org/micro-codec-segmentio/v3
|
module go.unistack.org/micro-codec-segmentio/v4
|
||||||
|
|
||||||
go 1.21
|
go 1.19
|
||||||
|
|
||||||
toolchain go1.23.4
|
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/segmentio/encoding v0.4.1
|
github.com/segmentio/encoding v0.3.6
|
||||||
go.unistack.org/micro-proto/v3 v3.4.1
|
go.unistack.org/micro-proto/v4 v4.0.0
|
||||||
go.unistack.org/micro/v3 v3.10.88
|
go.unistack.org/micro/v4 v4.0.1
|
||||||
google.golang.org/protobuf v1.35.2
|
google.golang.org/protobuf v1.28.1
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/google/go-cmp v0.6.0 // indirect
|
github.com/google/go-cmp v0.5.7 // indirect
|
||||||
github.com/segmentio/asm v1.2.0 // indirect
|
github.com/segmentio/asm v1.2.0 // indirect
|
||||||
golang.org/x/sys v0.28.0 // indirect
|
golang.org/x/sys v0.6.0 // indirect
|
||||||
)
|
)
|
||||||
|
27
go.sum
27
go.sum
@@ -1,10 +1,21 @@
|
|||||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||||
|
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
|
github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
|
||||||
|
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
|
||||||
|
github.com/segmentio/asm v1.1.3/go.mod h1:Ld3L4ZXGNcSLRg4JBsZ3//1+f/TjYl0Mzen/DQy1EJg=
|
||||||
github.com/segmentio/asm v1.2.0 h1:9BQrFxC+YOHJlTlHGkTrFWf59nbL3XnCoFLTwDCI7ys=
|
github.com/segmentio/asm v1.2.0 h1:9BQrFxC+YOHJlTlHGkTrFWf59nbL3XnCoFLTwDCI7ys=
|
||||||
github.com/segmentio/asm v1.2.0/go.mod h1:BqMnlJP91P8d+4ibuonYZw9mfnzI9HfxselHZr5aAcs=
|
github.com/segmentio/asm v1.2.0/go.mod h1:BqMnlJP91P8d+4ibuonYZw9mfnzI9HfxselHZr5aAcs=
|
||||||
github.com/segmentio/encoding v0.4.1 h1:KLGaLSW0jrmhB58Nn4+98spfvPvmo4Ci1P/WIQ9wn7w=
|
github.com/segmentio/encoding v0.3.6 h1:E6lVLyDPseWEulBmCmAKPanDd3jiyGDo5gMcugCRwZQ=
|
||||||
go.unistack.org/micro-proto/v3 v3.4.1 h1:UTjLSRz2YZuaHk9iSlVqqsA50JQNAEK2ZFboGqtEa9Q=
|
github.com/segmentio/encoding v0.3.6/go.mod h1:n0JeuIqEQrQoPDGsjo8UNd1iA0U8d8+oHAA4E3G3OxM=
|
||||||
go.unistack.org/micro-proto/v3 v3.4.1/go.mod h1:okx/cnOhzuCX0ggl/vToatbCupi0O44diiiLLsZ93Zo=
|
go.unistack.org/micro-proto/v4 v4.0.0 h1:+TAwKSlx48eLsNO2E2cO0JLE8we1KU2AuWe9Q310FuU=
|
||||||
go.unistack.org/micro/v3 v3.10.88 h1:MxlzP+77Y6Kphb3lzHxROL4XfE/WdCQMQpnPv4D9Z8U=
|
go.unistack.org/micro-proto/v4 v4.0.0/go.mod h1:ArmK7o+uFvxSY3dbJhKBBX4Pm1rhWdLEFf3LxBrMtec=
|
||||||
go.unistack.org/micro/v3 v3.10.88/go.mod h1:erMgt3Bl7vQQ0e9UpQyR5NlLiZ9pKeEJ9+1tfYFaqUg=
|
go.unistack.org/micro/v4 v4.0.1 h1:xo1IxbVfgh8i0eY0VeYa3cbb13u5n/Mxnp3FOgWD4Jo=
|
||||||
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
|
go.unistack.org/micro/v4 v4.0.1/go.mod h1:p/J5UcSJjfHsWGT31uKoghQ5rUQZzQJBAFy+Z4+ZVMs=
|
||||||
google.golang.org/protobuf v1.35.2 h1:8Ar7bF+apOIoThw1EdZl0p1oWvMqTHmpA2fRTyZO8io=
|
golang.org/x/sys v0.0.0-20211110154304-99a53858aa08/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
|
||||||
|
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
|
||||||
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/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.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
|
||||||
|
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||||
|
@@ -4,7 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"go.unistack.org/micro/v3/codec"
|
"go.unistack.org/micro/v4/codec"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestFrame(t *testing.T) {
|
func TestFrame(t *testing.T) {
|
||||||
@@ -28,7 +28,7 @@ func TestFrameFlatten(t *testing.T) {
|
|||||||
Name: &codec.Frame{Data: []byte("test")},
|
Name: &codec.Frame{Data: []byte("test")},
|
||||||
}
|
}
|
||||||
|
|
||||||
buf, err := NewCodec(codec.Flatten(true)).Marshal(s)
|
buf, err := NewCodec().Marshal(s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -36,3 +36,15 @@ 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) {
|
||||||
|
s := &struct {
|
||||||
|
Name string
|
||||||
|
}{}
|
||||||
|
c := NewCodec()
|
||||||
|
b := bytes.NewReader(nil)
|
||||||
|
err := c.ReadBody(b, s)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
158
json/json.go
158
json/json.go
@@ -1,11 +1,13 @@
|
|||||||
// Package json provides a json codec
|
// Package json provides a json codec
|
||||||
package json // import "go.unistack.org/micro-codec-segmentio/v3/json"
|
package json // import "go.unistack.org/micro-codec-segmentio/v4/json"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io"
|
||||||
|
|
||||||
"github.com/segmentio/encoding/json"
|
"github.com/segmentio/encoding/json"
|
||||||
pb "go.unistack.org/micro-proto/v3/codec"
|
pb "go.unistack.org/micro-proto/v4/codec"
|
||||||
"go.unistack.org/micro/v3/codec"
|
"go.unistack.org/micro/v4/codec"
|
||||||
rutil "go.unistack.org/micro/v3/util/reflect"
|
rutil "go.unistack.org/micro/v4/util/reflect"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -19,9 +21,10 @@ var (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var _ codec.Codec = &jsonCodec{}
|
||||||
_ codec.Codec = (*jsonCodec)(nil)
|
|
||||||
_ codec.CodecV2 = (*jsonCodecV2)(nil)
|
const (
|
||||||
|
flattenTag = "flatten"
|
||||||
)
|
)
|
||||||
|
|
||||||
type JsonMarshalOptions struct {
|
type JsonMarshalOptions struct {
|
||||||
@@ -46,12 +49,6 @@ type jsonCodec struct {
|
|||||||
decodeFlags json.ParseFlags
|
decodeFlags json.ParseFlags
|
||||||
}
|
}
|
||||||
|
|
||||||
type jsonCodecV2 struct {
|
|
||||||
opts codec.Options
|
|
||||||
encodeFlags json.AppendFlags
|
|
||||||
decodeFlags json.ParseFlags
|
|
||||||
}
|
|
||||||
|
|
||||||
func getMarshalFlags(o JsonMarshalOptions) json.AppendFlags {
|
func getMarshalFlags(o JsonMarshalOptions) json.AppendFlags {
|
||||||
var encodeFlags json.AppendFlags
|
var encodeFlags json.AppendFlags
|
||||||
|
|
||||||
@@ -114,10 +111,8 @@ func (c *jsonCodec) Marshal(v interface{}, opts ...codec.Option) ([]byte, error)
|
|||||||
o(&options)
|
o(&options)
|
||||||
}
|
}
|
||||||
|
|
||||||
if options.Flatten {
|
if nv, err := rutil.StructFieldByTag(v, options.TagName, flattenTag); err == nil {
|
||||||
if nv, err := rutil.StructFieldByTag(v, options.TagName, "flatten"); err == nil {
|
v = nv
|
||||||
v = nv
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch m := v.(type) {
|
switch m := v.(type) {
|
||||||
@@ -125,10 +120,6 @@ func (c *jsonCodec) Marshal(v interface{}, opts ...codec.Option) ([]byte, error)
|
|||||||
return m.Data, nil
|
return m.Data, nil
|
||||||
case *pb.Frame:
|
case *pb.Frame:
|
||||||
return m.Data, nil
|
return m.Data, nil
|
||||||
case codec.RawMessage:
|
|
||||||
return []byte(m), nil
|
|
||||||
case *codec.RawMessage:
|
|
||||||
return []byte(*m), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
marshalOptions := DefaultMarshalOptions
|
marshalOptions := DefaultMarshalOptions
|
||||||
@@ -154,10 +145,8 @@ func (c *jsonCodec) Unmarshal(b []byte, v interface{}, opts ...codec.Option) err
|
|||||||
o(&options)
|
o(&options)
|
||||||
}
|
}
|
||||||
|
|
||||||
if options.Flatten {
|
if nv, err := rutil.StructFieldByTag(v, options.TagName, flattenTag); err == nil {
|
||||||
if nv, err := rutil.StructFieldByTag(v, options.TagName, "flatten"); err == nil {
|
v = nv
|
||||||
v = nv
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch m := v.(type) {
|
switch m := v.(type) {
|
||||||
@@ -167,12 +156,6 @@ func (c *jsonCodec) Unmarshal(b []byte, v interface{}, opts ...codec.Option) err
|
|||||||
case *pb.Frame:
|
case *pb.Frame:
|
||||||
m.Data = b
|
m.Data = b
|
||||||
return nil
|
return nil
|
||||||
case *codec.RawMessage:
|
|
||||||
*m = append((*m)[0:0], b...)
|
|
||||||
return nil
|
|
||||||
case codec.RawMessage:
|
|
||||||
copy(m, b)
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unmarshalOptions := DefaultUnmarshalOptions
|
unmarshalOptions := DefaultUnmarshalOptions
|
||||||
@@ -186,89 +169,44 @@ func (c *jsonCodec) Unmarshal(b []byte, v interface{}, opts ...codec.Option) err
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *jsonCodec) ReadHeader(conn io.Reader, m *codec.Message, t codec.MessageType) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *jsonCodec) ReadBody(conn io.Reader, v interface{}) error {
|
||||||
|
if v == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
buf, err := io.ReadAll(conn)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
} else if len(buf) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return c.Unmarshal(buf, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *jsonCodec) 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
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = conn.Write(buf)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
func (c *jsonCodec) String() string {
|
func (c *jsonCodec) String() string {
|
||||||
return "json"
|
return "json"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *jsonCodecV2) Marshal(b []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, err := rutil.StructFieldByTag(v, options.TagName, "flatten"); err == nil {
|
|
||||||
v = nv
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
switch m := v.(type) {
|
|
||||||
case *codec.Frame:
|
|
||||||
return m.Data, nil
|
|
||||||
case *pb.Frame:
|
|
||||||
return m.Data, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
marshalOptions := DefaultMarshalOptions
|
|
||||||
if options.Context != nil {
|
|
||||||
if f, ok := options.Context.Value(marshalOptionsKey{}).(JsonMarshalOptions); ok {
|
|
||||||
marshalOptions = f
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var err error
|
|
||||||
b, err = json.Append(b[:0], v, getMarshalFlags(marshalOptions))
|
|
||||||
return b, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *jsonCodecV2) Unmarshal(b []byte, v interface{}, opts ...codec.Option) error {
|
|
||||||
if len(b) == 0 || v == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
options := c.opts
|
|
||||||
for _, o := range opts {
|
|
||||||
o(&options)
|
|
||||||
}
|
|
||||||
|
|
||||||
if options.Flatten {
|
|
||||||
if nv, err := rutil.StructFieldByTag(v, options.TagName, "flatten"); err == nil {
|
|
||||||
v = nv
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
switch m := v.(type) {
|
|
||||||
case *codec.Frame:
|
|
||||||
m.Data = b
|
|
||||||
return nil
|
|
||||||
case *pb.Frame:
|
|
||||||
m.Data = b
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
unmarshalOptions := DefaultUnmarshalOptions
|
|
||||||
if options.Context != nil {
|
|
||||||
if f, ok := options.Context.Value(unmarshalOptionsKey{}).(JsonUnmarshalOptions); ok {
|
|
||||||
unmarshalOptions = f
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err := json.Parse(b, v, getUnmarshalFlags(unmarshalOptions))
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *jsonCodecV2) String() string {
|
|
||||||
return "json"
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewCodec(opts ...codec.Option) *jsonCodec {
|
func NewCodec(opts ...codec.Option) *jsonCodec {
|
||||||
return &jsonCodec{opts: codec.NewOptions(opts...)}
|
return &jsonCodec{opts: codec.NewOptions(opts...)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCodecV2(opts ...codec.Option) *jsonCodecV2 {
|
|
||||||
return &jsonCodecV2{opts: codec.NewOptions(opts...)}
|
|
||||||
}
|
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
package json
|
package json
|
||||||
|
|
||||||
import (
|
import (
|
||||||
codec "go.unistack.org/micro/v3/codec"
|
codec "go.unistack.org/micro/v4/codec"
|
||||||
)
|
)
|
||||||
|
|
||||||
type unmarshalOptionsKey struct{}
|
type unmarshalOptionsKey struct{}
|
||||||
|
@@ -4,7 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"go.unistack.org/micro/v3/codec"
|
"go.unistack.org/micro/v4/codec"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestFrame(t *testing.T) {
|
func TestFrame(t *testing.T) {
|
||||||
@@ -28,7 +28,7 @@ func TestFrameFlatten(t *testing.T) {
|
|||||||
Name: &codec.Frame{Data: []byte("test")},
|
Name: &codec.Frame{Data: []byte("test")},
|
||||||
}
|
}
|
||||||
|
|
||||||
buf, err := NewCodec(codec.Flatten(true)).Marshal(s)
|
buf, err := NewCodec().Marshal(s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -36,3 +36,16 @@ 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("no proto generated")
|
||||||
|
s := &struct {
|
||||||
|
Name string
|
||||||
|
}{}
|
||||||
|
c := NewCodec()
|
||||||
|
b := bytes.NewReader(nil)
|
||||||
|
err := c.ReadBody(b, s)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -1,11 +1,13 @@
|
|||||||
// Package proto provides a proto codec
|
// Package proto provides a proto codec
|
||||||
package proto // import "go.unistack.org/micro-codec-segmentio/v3/proto"
|
package proto // import "go.unistack.org/micro-codec-segmentio/v4/proto"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io"
|
||||||
|
|
||||||
"github.com/segmentio/encoding/proto"
|
"github.com/segmentio/encoding/proto"
|
||||||
pb "go.unistack.org/micro-proto/v3/codec"
|
pb "go.unistack.org/micro-proto/v4/codec"
|
||||||
"go.unistack.org/micro/v3/codec"
|
"go.unistack.org/micro/v4/codec"
|
||||||
rutil "go.unistack.org/micro/v3/util/reflect"
|
rutil "go.unistack.org/micro/v4/util/reflect"
|
||||||
newproto "google.golang.org/protobuf/proto"
|
newproto "google.golang.org/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -15,6 +17,10 @@ type protoCodec struct {
|
|||||||
|
|
||||||
var _ codec.Codec = &protoCodec{}
|
var _ codec.Codec = &protoCodec{}
|
||||||
|
|
||||||
|
const (
|
||||||
|
flattenTag = "flatten"
|
||||||
|
)
|
||||||
|
|
||||||
func (c *protoCodec) Marshal(v interface{}, opts ...codec.Option) ([]byte, error) {
|
func (c *protoCodec) Marshal(v interface{}, opts ...codec.Option) ([]byte, error) {
|
||||||
if v == nil {
|
if v == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
@@ -25,10 +31,8 @@ func (c *protoCodec) Marshal(v interface{}, opts ...codec.Option) ([]byte, error
|
|||||||
o(&options)
|
o(&options)
|
||||||
}
|
}
|
||||||
|
|
||||||
if options.Flatten {
|
if nv, nerr := rutil.StructFieldByTag(v, options.TagName, flattenTag); nerr == nil {
|
||||||
if nv, nerr := rutil.StructFieldByTag(v, options.TagName, "flatten"); nerr == nil {
|
v = nv
|
||||||
v = nv
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch m := v.(type) {
|
switch m := v.(type) {
|
||||||
@@ -43,13 +47,9 @@ func (c *protoCodec) Marshal(v interface{}, opts ...codec.Option) ([]byte, error
|
|||||||
return proto.Marshal(m)
|
return proto.Marshal(m)
|
||||||
case newproto.Message:
|
case newproto.Message:
|
||||||
return proto.Marshal(m)
|
return proto.Marshal(m)
|
||||||
case codec.RawMessage:
|
|
||||||
return []byte(m), nil
|
|
||||||
case *codec.RawMessage:
|
|
||||||
return []byte(*m), nil
|
|
||||||
default:
|
|
||||||
return nil, codec.ErrInvalidMessage
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil, codec.ErrInvalidMessage
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *protoCodec) Unmarshal(d []byte, v interface{}, opts ...codec.Option) error {
|
func (c *protoCodec) Unmarshal(d []byte, v interface{}, opts ...codec.Option) error {
|
||||||
@@ -62,10 +62,8 @@ func (c *protoCodec) Unmarshal(d []byte, v interface{}, opts ...codec.Option) er
|
|||||||
o(&options)
|
o(&options)
|
||||||
}
|
}
|
||||||
|
|
||||||
if options.Flatten {
|
if nv, nerr := rutil.StructFieldByTag(v, options.TagName, flattenTag); nerr == nil {
|
||||||
if nv, nerr := rutil.StructFieldByTag(v, options.TagName, "flatten"); nerr == nil {
|
v = nv
|
||||||
v = nv
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch m := v.(type) {
|
switch m := v.(type) {
|
||||||
@@ -75,12 +73,6 @@ func (c *protoCodec) Unmarshal(d []byte, v interface{}, opts ...codec.Option) er
|
|||||||
case *pb.Frame:
|
case *pb.Frame:
|
||||||
m.Data = d
|
m.Data = d
|
||||||
return nil
|
return nil
|
||||||
case *codec.RawMessage:
|
|
||||||
*m = append((*m)[0:0], d...)
|
|
||||||
return nil
|
|
||||||
case codec.RawMessage:
|
|
||||||
copy(m, d)
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch m := v.(type) {
|
switch m := v.(type) {
|
||||||
@@ -88,9 +80,43 @@ func (c *protoCodec) Unmarshal(d []byte, v interface{}, opts ...codec.Option) er
|
|||||||
return proto.Unmarshal(d, m)
|
return proto.Unmarshal(d, m)
|
||||||
case newproto.Message:
|
case newproto.Message:
|
||||||
return proto.Unmarshal(d, m)
|
return proto.Unmarshal(d, m)
|
||||||
default:
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return codec.ErrInvalidMessage
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *protoCodec) ReadHeader(conn io.Reader, m *codec.Message, t codec.MessageType) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *protoCodec) ReadBody(conn io.Reader, v interface{}) error {
|
||||||
|
if v == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
buf, err := io.ReadAll(conn)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
} else if len(buf) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return c.Unmarshal(buf, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *protoCodec) 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 *protoCodec) String() string {
|
func (c *protoCodec) String() string {
|
||||||
|
Reference in New Issue
Block a user