Compare commits

...

40 Commits

Author SHA1 Message Date
Renovate Bot
61259f6bbb fix(deps): update module github.com/unistack-org/micro/v3 to v3.3.17 2021-04-27 08:44:26 +00:00
Renovate Bot
01e39a24a6 fix(deps): update module github.com/evanphx/json-patch/v5 to v5.3.0 2021-04-21 03:55:48 +00:00
Renovate Bot
5a65acebd8 fix(deps): update module github.com/unistack-org/micro/v3 to v3.3.16 2021-04-20 13:08:46 +00:00
Renovate Bot
54e992ef03 fix(deps): update module github.com/unistack-org/micro/v3 to v3.3.15 2021-04-19 15:37:01 +00:00
Renovate Bot
71073b77ac fix(deps): update module github.com/unistack-org/micro/v3 to v3.3.14 2021-04-19 02:37:43 +00:00
39d17ab5ce fix for latest micro
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2021-04-10 01:28:34 +03:00
Renovate Bot
0d86de8e87 fix(deps): update module github.com/unistack-org/micro/v3 to v3.3.11 2021-04-03 11:28:06 +00:00
Renovate Bot
fede23f41e fix(deps): update module github.com/unistack-org/micro/v3 to v3.3.10 2021-04-01 01:25:23 +00:00
Renovate Bot
c963499f76 fix(deps): update module github.com/unistack-org/micro/v3 to v3.3.9 2021-03-30 04:10:58 +00:00
Renovate Bot
633df3de9b fix(deps): update module github.com/unistack-org/micro/v3 to v3.3.8 2021-03-29 01:56:26 +00:00
Renovate Bot
289261d557 fix(deps): update module github.com/unistack-org/micro/v3 to v3.3.7 2021-03-28 19:42:40 +00:00
Renovate Bot
b8ceef488d fix(deps): update module github.com/unistack-org/micro/v3 to v3.3.4 2021-03-26 18:17:19 +00:00
Renovate Bot
63e41699a0 fix(deps): update module github.com/unistack-org/micro/v3 to v3.3.2 2021-03-25 14:28:48 +00:00
Renovate Bot
d66e8bb594 fix(deps): update module github.com/unistack-org/micro/v3 to v3.3.1 2021-03-25 02:10:48 +00:00
Renovate Bot
6f693a2c1d fix(deps): update module github.com/unistack-org/micro/v3 to v3.3.0 2021-03-24 14:47:25 +00:00
Renovate Bot
9eb9adc97e fix(deps): update module github.com/unistack-org/micro/v3 to v3.2.26 2021-03-23 17:47:19 +00:00
Renovate Bot
93bd2c2579 fix(deps): update module github.com/unistack-org/micro/v3 to v3.2.24 2021-03-21 15:22:06 +00:00
Renovate Bot
7046f19fe2 fix(deps): update module github.com/unistack-org/micro/v3 to v3.2.23 2021-03-16 19:00:25 +00:00
Renovate Bot
a17bf063a6 fix(deps): update module github.com/unistack-org/micro/v3 to v3.2.22 2021-03-15 02:15:51 +00:00
Renovate Bot
1054c722b7 fix(deps): update module github.com/unistack-org/micro/v3 to v3.2.20 2021-03-06 23:59:58 +00:00
Renovate Bot
97948f4177 fix(deps): update module github.com/unistack-org/micro/v3 to v3.2.18 2021-03-06 20:00:54 +00:00
Renovate Bot
798cad129d fix(deps): update module github.com/unistack-org/micro/v3 to v3.2.17 2021-03-05 17:42:29 +00:00
Renovate Bot
c21f43c6da fix(deps): update module github.com/unistack-org/micro/v3 to v3.2.16 2021-03-04 12:55:16 +00:00
6debf95e34 fix content type for fatal error
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2021-03-03 16:53:42 +03:00
Renovate Bot
3ce74daa8e fix(deps): update module github.com/unistack-org/micro/v3 to v3.2.15 2021-03-01 12:57:17 +00:00
Renovate Bot
8eae96c272 fix(deps): update module unistack-org/micro/v3 to v3.2.14 2021-02-18 19:30:50 +00:00
4480627cf0 update workflows
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2021-02-18 18:45:28 +03:00
Renovate Bot
a151bed4ba chore(deps): update module unistack-org/micro/v3 to v3.2.11 2021-02-12 15:34:58 +00:00
4c8bc015c3 update renovate.json
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2021-02-12 12:40:02 +03:00
08ceb7b108 avoid creating new err variable
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2021-02-11 15:21:44 +03:00
d300f5cfe7
Merge pull request #5 from unistack-org/renovate/all
chore(deps): update module unistack-org/micro/v3 to v3.2.8
2021-02-10 20:06:38 +03:00
8b6e62db29
Merge pull request #6 from unistack-org/renovate/major-all
chore(deps): update actions/setup-go action to v2
2021-02-10 20:06:13 +03:00
Renovate Bot
9f2d486f24
chore(deps): update actions/setup-go action to v2 2021-02-10 10:19:36 +00:00
Renovate Bot
fa77cdc265
chore(deps): update module unistack-org/micro/v3 to v3.2.8 2021-02-10 10:19:29 +00:00
1a8404244b move renovate.json
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2021-02-10 13:18:27 +03:00
08865f11e8
Merge pull request #4 from unistack-org/renovate/golangci-golangci-lint-action-2.x
chore(deps): update golangci/golangci-lint-action action to v2
2021-02-10 09:20:12 +03:00
Renovate Bot
c989fceb4f
chore(deps): update golangci/golangci-lint-action action to v2 2021-02-09 21:24:10 +00:00
1d191243e9
Merge pull request #1 from unistack-org/renovate/configure
Configure Renovate
2021-02-10 00:23:04 +03:00
Renovate Bot
f053c1299b
Add renovate.json 2021-02-08 23:50:46 +00:00
a9abd60f7c use own fork
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2021-01-16 00:55:19 +03:00
17 changed files with 605 additions and 232 deletions

24
.github/ISSUE_TEMPLATE/bug_report.md vendored Normal file
View File

@ -0,0 +1,24 @@
---
name: Bug report
about: For reporting bugs in go-micro
title: "[BUG]"
labels: ''
assignees: ''
---
**Describe the bug**
1. What are you trying to do?
2. What did you expect to happen?
3. What happens instead?
**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

@ -0,0 +1,17 @@
---
name: Feature request / Enhancement
about: If you have a need not served by go-micro
title: "[FEATURE]"
labels: ''
assignees: ''
---
**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
**Describe the solution you'd like**
A clear and concise description of what you want to happen.
**Additional context**
Add any other context or screenshots about the feature request here.

14
.github/ISSUE_TEMPLATE/question.md vendored Normal file
View File

@ -0,0 +1,14 @@
---
name: Question
about: Ask a question about go-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

9
.github/PULL_REQUEST_TEMPLATE.md vendored Normal file
View File

@ -0,0 +1,9 @@
## Pull Request template
Please, go through these steps before clicking submit on this PR.
1. Give a descriptive title to your PR.
2. Provide a description of your changes.
3. Make sure you have some relevant tests.
4. Put `closes #XXXX` in your comment to auto-close the issue that your PR fixes (if applicable).
**PLEASE REMOVE THIS TEMPLATE BEFORE SUBMITTING**

19
.github/renovate.json vendored Normal file
View File

@ -0,0 +1,19 @@
{
"extends": [
"config:base"
],
"packageRules": [
{
"matchUpdateTypes": ["minor", "patch", "pin", "digest"],
"automerge": true
},
{
"groupName": "all deps",
"separateMajorMinor": true,
"groupSlug": "all",
"packagePatterns": [
"*"
]
}
]
}

13
.github/stale.sh vendored Executable file
View File

@ -0,0 +1,13 @@
#!/bin/bash -ex
export PATH=$PATH:$(pwd)/bin
export GO111MODULE=on
export GOBIN=$(pwd)/bin
#go get github.com/rvflash/goup@v0.4.1
#goup -v ./...
#go get github.com/psampaz/go-mod-outdated@v0.6.0
go list -u -m -mod=mod -json all | go-mod-outdated -update -direct -ci || true
#go list -u -m -json all | go-mod-outdated -update

46
.github/workflows/build.yml vendored Normal file
View File

@ -0,0 +1,46 @@
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

46
.github/workflows/pr.yml vendored Normal file
View File

@ -0,0 +1,46 @@
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

15
.gitignore vendored Normal file
View File

@ -0,0 +1,15 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# Test binary, built with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# Dependency directories (remove the comment below to include it)
# vendor/

1
.synced Normal file
View File

@ -0,0 +1 @@
0a6e451539fd046bbfea625b05ef2e3006c69214

201
LICENSE Normal file
View File

@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

1
README.md Normal file
View File

@ -0,0 +1 @@
# micro-api-handler-rpc

13
go.mod Normal file
View File

@ -0,0 +1,13 @@
module github.com/unistack-org/micro-api-handler-rpc/v3
go 1.15
require (
github.com/evanphx/json-patch/v5 v5.3.0
github.com/gobwas/httphead v0.1.0
github.com/gobwas/pool v0.2.1 // indirect
github.com/gobwas/ws v1.0.4
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c
github.com/pkg/errors v0.9.1 // indirect
github.com/unistack-org/micro/v3 v3.3.17
)

55
go.sum Normal file
View File

@ -0,0 +1,55 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/ef-ds/deque v1.0.4/go.mod h1:gXDnTC3yqvBcHbq2lcExjtAcVrOnJCbMcZXmuj8Z4tg=
github.com/evanphx/json-patch/v5 v5.2.0 h1:8ozOH5xxoMYDt5/u+yMTsVXydVCbTORFnOOoq2lumco=
github.com/evanphx/json-patch/v5 v5.2.0/go.mod h1:G79N1coSVB93tBe7j6PhzjmR3/2VvlbKOFpnXhI9Bw4=
github.com/evanphx/json-patch/v5 v5.3.0 h1:iaBOvzmvcdDnf9VYBVPGS7kVp+l/hZztlESv/w0Vre0=
github.com/evanphx/json-patch/v5 v5.3.0/go.mod h1:G79N1coSVB93tBe7j6PhzjmR3/2VvlbKOFpnXhI9Bw4=
github.com/gobwas/httphead v0.1.0 h1:exrUm0f4YX0L7EBwZHuCF4GDp8aJfVeBrlLQrs6NqWU=
github.com/gobwas/httphead v0.1.0/go.mod h1:O/RXo79gxV8G+RqlR/otEwx4Q36zl9rqC5u12GKvMCM=
github.com/gobwas/pool v0.2.1 h1:xfeeEhW7pwmX8nuLVlqbzVc7udMDrwetjEv+TZIz1og=
github.com/gobwas/pool v0.2.1/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw=
github.com/gobwas/ws v1.0.4 h1:5eXU1CZhpQdq5kXbKb+sECH5Ia5KiO6CYzIzdlVx6Bs=
github.com/gobwas/ws v1.0.4/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM=
github.com/google/uuid v1.2.0 h1:qJYtXnJRWmpe7m/3XlyhrsLrEURqHRM2kxzoxXqyUDs=
github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c h1:rp5dCmg/yLR3mgFuSOe4oEnDDmGLROTvMragMUXpTQw=
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c/go.mod h1:X07ZCGwUbLaax7L0S3Tw4hpejzu63ZrrQiUe6W0hcy0=
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/silas/dag v0.0.0-20210121180416-41cf55125c34/go.mod h1:7RTUFBdIRC9nZ7/3RyRNH1bdqIShrDejd1YbLwgPS+I=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/unistack-org/micro/v3 v3.3.13 h1:y4bDDkbwnjgOckrhFkC6D/o42tr75X33UbrB+Ko0M68=
github.com/unistack-org/micro/v3 v3.3.13/go.mod h1:98hNcMXp/WyWJwLwCuwrhN1Jm7aCWaRNsMfRjK8Fq+Y=
github.com/unistack-org/micro/v3 v3.3.14 h1:CAkDMjHZT8/D6GGF5h3gK84m6tlWZC17IGPb2GkAn/4=
github.com/unistack-org/micro/v3 v3.3.14/go.mod h1:ETGcQQUcjxGaD44LUMX+0fgo8Loh7ExldfIPLvfUmDo=
github.com/unistack-org/micro/v3 v3.3.15 h1:rj+spzhezCg4gmj1nuF0FRGixC51/7xFACOchB/23/E=
github.com/unistack-org/micro/v3 v3.3.15/go.mod h1:ETGcQQUcjxGaD44LUMX+0fgo8Loh7ExldfIPLvfUmDo=
github.com/unistack-org/micro/v3 v3.3.16 h1:v0h/oC0TO2n1djQJeOjD2jNEqKkiykwI6cpflEVTlQE=
github.com/unistack-org/micro/v3 v3.3.16/go.mod h1:ETGcQQUcjxGaD44LUMX+0fgo8Loh7ExldfIPLvfUmDo=
github.com/unistack-org/micro/v3 v3.3.17 h1:WcyS7InP0DlS/JpRQGLh5sG6VstkdHJbgpMp+gmHmwg=
github.com/unistack-org/micro/v3 v3.3.17/go.mod h1:022EOEZZ789hZY3yB5ZSMXU6jLiadBgcNB/cpediV3c=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.0.0-20210415231046-e915ea6b2b7d/go.mod h1:9tjilg8BloeKEkVJvy7fQ90B1CfIiPueXVOjqfkSzI8=
golang.org/x/net v0.0.0-20210423184538-5f58ad60dda6/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44 h1:Bli41pIlzTzf3KEY06n+xnzK/BESIg2ze4Pgfh/aI8c=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da h1:b3NXsE2LusjYGGjL5bxEVZZORm/YEFFrWFjR8eFrw/c=
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.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
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=
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=

159
rpc.go
View File

@ -1,4 +1,4 @@
// Package rpc is a go-micro rpc handler. // Package rpc is a micro rpc handler.
package rpc package rpc
import ( import (
@ -7,22 +7,23 @@ import (
"net/http" "net/http"
"strconv" "strconv"
"strings" "strings"
"time"
jsonpatch "github.com/evanphx/json-patch/v5" jsonpatch "github.com/evanphx/json-patch/v5"
"github.com/micro/go-micro/v3/api"
"github.com/micro/go-micro/v3/api/handler"
"github.com/micro/go-micro/v3/api/internal/proto"
"github.com/micro/go-micro/v3/client"
"github.com/micro/go-micro/v3/codec"
"github.com/micro/go-micro/v3/codec/jsonrpc"
"github.com/micro/go-micro/v3/codec/protorpc"
"github.com/micro/go-micro/v3/errors"
"github.com/micro/go-micro/v3/logger"
"github.com/micro/go-micro/v3/metadata"
"github.com/micro/go-micro/v3/util/ctx"
"github.com/micro/go-micro/v3/util/qson"
"github.com/micro/go-micro/v3/util/router"
"github.com/oxtoacart/bpool" "github.com/oxtoacart/bpool"
// jsonrpc "github.com/unistack-org/micro-codec-jsonrpc"
// protorpc "github.com/unistack-org/micro-codec-protorpc"
"github.com/unistack-org/micro/v3/api"
"github.com/unistack-org/micro/v3/api/handler"
"github.com/unistack-org/micro/v3/client"
"github.com/unistack-org/micro/v3/codec"
"github.com/unistack-org/micro/v3/errors"
"github.com/unistack-org/micro/v3/logger"
"github.com/unistack-org/micro/v3/metadata"
"github.com/unistack-org/micro/v3/util/ctx"
"github.com/unistack-org/micro/v3/util/qson"
"github.com/unistack-org/micro/v3/util/router"
) )
const ( const (
@ -34,7 +35,7 @@ var (
jsonCodecs = []string{ jsonCodecs = []string{
"application/grpc+json", "application/grpc+json",
"application/json", "application/json",
"application/json-rpc", // "application/json-rpc",
} }
// support proto codecs // support proto codecs
@ -43,8 +44,8 @@ var (
"application/grpc+proto", "application/grpc+proto",
"application/proto", "application/proto",
"application/protobuf", "application/protobuf",
"application/proto-rpc", // "application/proto-rpc",
"application/octet-stream", // "application/octet-stream",
} }
bufferPool = bpool.NewSizedBufferPool(1024, 8) bufferPool = bpool.NewSizedBufferPool(1024, 8)
@ -113,7 +114,14 @@ func (h *rpcHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} }
// create custom router // create custom router
callOpt := client.WithRouter(router.New(service.Services)) callOpts := []client.CallOption{client.WithRouter(router.New(service.Services))}
if t := r.Header.Get("Timeout"); t != "" {
// assume timeout integer seconds now
if td, err := time.ParseDuration(t + "s"); err == nil {
callOpts = append(callOpts, client.WithRequestTimeout(td))
}
}
// walk the standard call path // walk the standard call path
// get payload // get payload
@ -128,34 +136,29 @@ func (h *rpcHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
switch { switch {
// proto codecs // proto codecs
case hasCodec(ct, protoCodecs): case hasCodec(ct, protoCodecs):
request := &proto.Message{} request := &codec.Frame{}
// if the extracted payload isn't empty lets use it // if the extracted payload isn't empty lets use it
if len(br) > 0 { if len(br) > 0 {
request = proto.NewMessage(br) request.Data = br
} }
// create request/response // create request/response
response := &proto.Message{} response := &codec.Frame{}
req := c.NewRequest( req := c.NewRequest(
service.Name, service.Name,
service.Endpoint.Name, service.Endpoint.Name,
request, request,
client.WithContentType(ct), client.RequestContentType(ct),
) )
// make the call // make the call
if err := c.Call(cx, req, response, callOpt); err != nil { if err := c.Call(cx, req, response, callOpts...); err != nil {
writeError(w, r, err) writeError(w, r, err)
return return
} }
// marshall response rsp = response.Data
rsp, err = response.Marshal()
if err != nil {
writeError(w, r, err)
return
}
default: default:
// if json codec is not present set to json // if json codec is not present set to json
@ -177,10 +180,10 @@ func (h *rpcHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
service.Name, service.Name,
service.Endpoint.Name, service.Endpoint.Name,
&request, &request,
client.WithContentType(ct), client.RequestContentType(ct),
) )
// make the call // make the call
if err := c.Call(cx, req, &response, callOpt); err != nil { if err := c.Call(cx, req, &response, callOpts...); err != nil {
writeError(w, r, err) writeError(w, r, err)
return return
} }
@ -221,39 +224,45 @@ func requestPayload(r *http.Request) ([]byte, error) {
ct := r.Header.Get("Content-Type") ct := r.Header.Get("Content-Type")
switch { switch {
case strings.Contains(ct, "application/json-rpc"): /*
msg := codec.Message{ case strings.Contains(ct, "application/json-rpc"):
Type: codec.Request, msg := codec.Message{
Header: make(map[string]string), Type: codec.Request,
} Header: metadata.New(0),
c := jsonrpc.NewCodec(&buffer{r.Body}) }
if err = c.ReadHeader(&msg, codec.Request); err != nil { c := jsonrpc.NewCodec(&buffer{r.Body})
if err = c.ReadHeader(&msg, codec.Request); err != nil {
return nil, err
}
var raw json.RawMessage
if err = c.ReadBody(&raw); err != nil {
return nil, err
}
return ([]byte)(raw), nil
*/
/*
case strings.Contains(ct, "application/proto-rpc"), strings.Contains(ct, "application/octet-stream"):
msg := codec.Message{
Type: codec.Request,
Header: metadata.New(0),
}
c := protorpc.NewCodec(&buffer{r.Body})
if err = c.ReadHeader(&msg, codec.Request); err != nil {
return nil, err
}
var raw proto.Message
if err = c.ReadBody(&raw); err != nil {
return nil, err
}
return raw.Marshal()
*/
case strings.Contains(ct, "application/www-x-form-urlencoded"):
if err = r.ParseForm(); err != nil {
return nil, err return nil, err
} }
var raw json.RawMessage
if err = c.ReadBody(&raw); err != nil {
return nil, err
}
return ([]byte)(raw), nil
case strings.Contains(ct, "application/proto-rpc"), strings.Contains(ct, "application/octet-stream"):
msg := codec.Message{
Type: codec.Request,
Header: make(map[string]string),
}
c := protorpc.NewCodec(&buffer{r.Body})
if err = c.ReadHeader(&msg, codec.Request); err != nil {
return nil, err
}
var raw proto.Message
if err = c.ReadBody(&raw); err != nil {
return nil, err
}
return raw.Marshal()
case strings.Contains(ct, "application/x-www-form-urlencoded"):
r.ParseForm()
// generate a new set of values from the form // generate a new set of values from the form
vals := make(map[string]string) vals := make(map[string]string, len(r.Form))
for k, v := range r.Form { for k, v := range r.Form {
vals[k] = strings.Join(v, ",") vals[k] = strings.Join(v, ",")
} }
@ -268,7 +277,7 @@ func requestPayload(r *http.Request) ([]byte, error) {
// dont user metadata.FromContext as it mangles names // dont user metadata.FromContext as it mangles names
md, ok := metadata.FromContext(ctx) md, ok := metadata.FromContext(ctx)
if !ok { if !ok {
md = make(map[string]string) md = metadata.New(0)
} }
// allocate maximum // allocate maximum
@ -347,10 +356,10 @@ func requestPayload(r *http.Request) ([]byte, error) {
switch r.Method { switch r.Method {
case "GET": case "GET":
// empty response // empty response
if strings.Contains(ct, "application/json") && string(out) == "{}" { if string(out) == "{}" && !strings.Contains(ct, "application/json") {
return out, nil
} else if string(out) == "{}" && !strings.Contains(ct, "application/json") {
return []byte{}, nil return []byte{}, nil
} else if string(out) == "{}" && strings.Contains(ct, "application/json") {
return out, nil
} }
return out, nil return out, nil
case "PATCH", "POST", "PUT", "DELETE": case "PATCH", "POST", "PUT", "DELETE":
@ -364,13 +373,6 @@ func requestPayload(r *http.Request) ([]byte, error) {
bodybuf = b bodybuf = b
} }
if bodydst == "" || bodydst == "*" { if bodydst == "" || bodydst == "*" {
// jsonpatch resequences the json object so we avoid it if possible (some usecases such as
// validating signatures require the request body to be unchangedd). We're keeping support
// for the custom paramaters for backwards compatability reasons.
if string(out) == "{}" {
return bodybuf, nil
}
if out, err = jsonpatch.MergeMergePatches(out, bodybuf); err == nil { if out, err = jsonpatch.MergeMergePatches(out, bodybuf); err == nil {
return out, nil return out, nil
} }
@ -417,6 +419,7 @@ func requestPayload(r *http.Request) ([]byte, error) {
//fallback to previous unknown behaviour //fallback to previous unknown behaviour
return bodybuf, nil return bodybuf, nil
} }
return []byte{}, nil return []byte{}, nil
@ -425,6 +428,9 @@ func requestPayload(r *http.Request) ([]byte, error) {
func writeError(w http.ResponseWriter, r *http.Request, err error) { func writeError(w http.ResponseWriter, r *http.Request, err error) {
ce := errors.Parse(err.Error()) ce := errors.Parse(err.Error())
// response content type
w.Header().Set("Content-Type", "application/json")
switch ce.Code { switch ce.Code {
case 0: case 0:
// assuming it's totally screwed // assuming it's totally screwed
@ -437,9 +443,6 @@ func writeError(w http.ResponseWriter, r *http.Request, err error) {
w.WriteHeader(int(ce.Code)) w.WriteHeader(int(ce.Code))
} }
// response content type
w.Header().Set("Content-Type", "application/json")
// Set trailers // Set trailers
if strings.Contains(r.Header.Get("Content-Type"), "application/grpc") { if strings.Contains(r.Header.Get("Content-Type"), "application/grpc") {
w.Header().Set("Trailer", "grpc-status") w.Header().Set("Trailer", "grpc-status")
@ -450,8 +453,8 @@ func writeError(w http.ResponseWriter, r *http.Request, err error) {
_, werr := w.Write([]byte(ce.Error())) _, werr := w.Write([]byte(ce.Error()))
if werr != nil { if werr != nil {
if logger.V(logger.ErrorLevel, logger.DefaultLogger) { if logger.V(logger.ErrorLevel) {
logger.Error(werr) logger.Error(r.Context(), werr.Error())
} }
} }
} }
@ -476,8 +479,8 @@ func writeResponse(w http.ResponseWriter, r *http.Request, rsp []byte) {
// write response // write response
_, err := w.Write(rsp) _, err := w.Write(rsp)
if err != nil { if err != nil {
if logger.V(logger.ErrorLevel, logger.DefaultLogger) { if logger.V(logger.ErrorLevel) {
logger.Error(err) logger.Error(r.Context(), err.Error())
} }
} }

View File

@ -1,112 +0,0 @@
package rpc
import (
"bytes"
"encoding/json"
"net/http"
"testing"
"github.com/golang/protobuf/proto"
go_api "github.com/micro/go-micro/v3/api/proto"
)
func TestRequestPayloadFromRequest(t *testing.T) {
// our test event so that we can validate serialising / deserializing of true protos works
protoEvent := go_api.Event{
Name: "Test",
}
protoBytes, err := proto.Marshal(&protoEvent)
if err != nil {
t.Fatal("Failed to marshal proto", err)
}
jsonBytes, err := json.Marshal(protoEvent)
if err != nil {
t.Fatal("Failed to marshal proto to JSON ", err)
}
jsonUrlBytes := []byte(`{"key1":"val1","key2":"val2","name":"Test"}`)
t.Run("extracting a json from a POST request with url params", func(t *testing.T) {
r, err := http.NewRequest("POST", "http://localhost/my/path?key1=val1&key2=val2", bytes.NewReader(jsonBytes))
if err != nil {
t.Fatalf("Failed to created http.Request: %v", err)
}
extByte, err := requestPayload(r)
if err != nil {
t.Fatalf("Failed to extract payload from request: %v", err)
}
if string(extByte) != string(jsonUrlBytes) {
t.Fatalf("Expected %v and %v to match", string(extByte), jsonUrlBytes)
}
})
t.Run("extracting a proto from a POST request", func(t *testing.T) {
r, err := http.NewRequest("POST", "http://localhost/my/path", bytes.NewReader(protoBytes))
if err != nil {
t.Fatalf("Failed to created http.Request: %v", err)
}
extByte, err := requestPayload(r)
if err != nil {
t.Fatalf("Failed to extract payload from request: %v", err)
}
if string(extByte) != string(protoBytes) {
t.Fatalf("Expected %v and %v to match", string(extByte), string(protoBytes))
}
})
t.Run("extracting JSON from a POST request", func(t *testing.T) {
r, err := http.NewRequest("POST", "http://localhost/my/path", bytes.NewReader(jsonBytes))
if err != nil {
t.Fatalf("Failed to created http.Request: %v", err)
}
extByte, err := requestPayload(r)
if err != nil {
t.Fatalf("Failed to extract payload from request: %v", err)
}
if string(extByte) != string(jsonBytes) {
t.Fatalf("Expected %v and %v to match", string(extByte), string(jsonBytes))
}
})
t.Run("extracting params from a GET request", func(t *testing.T) {
r, err := http.NewRequest("GET", "http://localhost/my/path", nil)
if err != nil {
t.Fatalf("Failed to created http.Request: %v", err)
}
q := r.URL.Query()
q.Add("name", "Test")
r.URL.RawQuery = q.Encode()
extByte, err := requestPayload(r)
if err != nil {
t.Fatalf("Failed to extract payload from request: %v", err)
}
if string(extByte) != string(jsonBytes) {
t.Fatalf("Expected %v and %v to match", string(extByte), string(jsonBytes))
}
})
t.Run("GET request with no params", func(t *testing.T) {
r, err := http.NewRequest("GET", "http://localhost/my/path", nil)
if err != nil {
t.Fatalf("Failed to created http.Request: %v", err)
}
extByte, err := requestPayload(r)
if err != nil {
t.Fatalf("Failed to extract payload from request: %v", err)
}
if string(extByte) != "" {
t.Fatalf("Expected %v and %v to match", string(extByte), "")
}
})
}

View File

@ -1,7 +1,6 @@
package rpc package rpc
import ( import (
"bytes"
"context" "context"
"encoding/json" "encoding/json"
"io" "io"
@ -12,11 +11,11 @@ import (
"github.com/gobwas/httphead" "github.com/gobwas/httphead"
"github.com/gobwas/ws" "github.com/gobwas/ws"
"github.com/gobwas/ws/wsutil" "github.com/gobwas/ws/wsutil"
"github.com/micro/go-micro/v3/api" "github.com/unistack-org/micro/v3/api"
"github.com/micro/go-micro/v3/client" "github.com/unistack-org/micro/v3/client"
raw "github.com/micro/go-micro/v3/codec/bytes" "github.com/unistack-org/micro/v3/codec"
"github.com/micro/go-micro/v3/logger" "github.com/unistack-org/micro/v3/logger"
"github.com/micro/go-micro/v3/util/router" "github.com/unistack-org/micro/v3/util/router"
) )
// serveWebsocket will stream rpc back over websockets assuming json // serveWebsocket will stream rpc back over websockets assuming json
@ -29,6 +28,16 @@ func serveWebsocket(ctx context.Context, w http.ResponseWriter, r *http.Request,
ct = ct[:idx] ct = ct[:idx]
} }
// create custom router
callOpts := []client.CallOption{client.WithRouter(router.New(service.Services))}
if t := r.Header.Get("Timeout"); t != "" {
// assume timeout integer secodns
if td, err := time.ParseDuration(t + "s"); err == nil {
callOpts = append(callOpts, client.WithRequestTimeout(td))
}
}
// check proto from request // check proto from request
switch ct { switch ct {
case "application/json": case "application/json":
@ -44,13 +53,15 @@ func serveWebsocket(ctx context.Context, w http.ResponseWriter, r *http.Request,
case "binary": case "binary":
hdr["Sec-WebSocket-Protocol"] = []string{"binary"} hdr["Sec-WebSocket-Protocol"] = []string{"binary"}
op = ws.OpBinary op = ws.OpBinary
default:
op = ws.OpBinary
} }
} }
} }
payload, err := requestPayload(r) payload, err := requestPayload(r)
if err != nil { if err != nil {
if logger.V(logger.ErrorLevel, logger.DefaultLogger) { if logger.V(logger.ErrorLevel) {
logger.Error(err) logger.Error(ctx, err.Error())
} }
return return
} }
@ -72,60 +83,57 @@ func serveWebsocket(ctx context.Context, w http.ResponseWriter, r *http.Request,
conn, rw, _, err := upgrader.Upgrade(r, w) conn, rw, _, err := upgrader.Upgrade(r, w)
if err != nil { if err != nil {
if logger.V(logger.ErrorLevel, logger.DefaultLogger) { if logger.V(logger.ErrorLevel) {
logger.Error(err) logger.Error(ctx, err.Error())
} }
return return
} }
defer func() { defer func() {
if err := conn.Close(); err != nil { if err := conn.Close(); err != nil {
if logger.V(logger.ErrorLevel, logger.DefaultLogger) { if logger.V(logger.ErrorLevel) {
logger.Error(err) logger.Error(ctx, err.Error())
} }
return return
} }
}() }()
var request interface{} var request interface{}
if !bytes.Equal(payload, []byte(`{}`)) {
switch ct { switch ct {
case "application/json", "": case "application/json":
m := json.RawMessage(payload) m := json.RawMessage(payload)
request = &m request = &m
default: default:
request = &raw.Frame{Data: payload} request = &codec.Frame{Data: payload}
}
} }
// we always need to set content type for message // we always need to set content type for message
if ct == "" { if ct == "" {
ct = "application/json" ct = "application/json"
} }
req := c.NewRequest( req := c.NewRequest(
service.Name, service.Name,
service.Endpoint.Name, service.Endpoint.Name,
request, request,
client.WithContentType(ct), client.RequestContentType(ct),
client.StreamingRequest(), client.StreamingRequest(true),
) )
// create custom router
callOpt := client.WithRouter(router.New(service.Services))
// create a new stream // create a new stream
stream, err := c.Stream(ctx, req, callOpt) stream, err := c.Stream(ctx, req, callOpts...)
if err != nil { if err != nil {
if logger.V(logger.ErrorLevel, logger.DefaultLogger) { if logger.V(logger.ErrorLevel) {
logger.Error(err) logger.Error(ctx, err.Error())
} }
return return
} }
if request != nil { if request != nil {
if err = stream.Send(request); err != nil { if err = stream.Send(request); err != nil {
if logger.V(logger.ErrorLevel, logger.DefaultLogger) { if logger.V(logger.ErrorLevel) {
logger.Error(err) logger.Error(ctx, err.Error())
} }
return return
} }
@ -150,22 +158,22 @@ func serveWebsocket(ctx context.Context, w http.ResponseWriter, r *http.Request,
if strings.Contains(err.Error(), "context canceled") { if strings.Contains(err.Error(), "context canceled") {
return return
} }
if logger.V(logger.ErrorLevel, logger.DefaultLogger) { if logger.V(logger.ErrorLevel) {
logger.Error(err) logger.Error(ctx, err.Error())
} }
return return
} }
// write the response // write the response
if err := wsutil.WriteServerMessage(rw, op, buf); err != nil { if err = wsutil.WriteServerMessage(rw, op, buf); err != nil {
if logger.V(logger.ErrorLevel, logger.DefaultLogger) { if logger.V(logger.ErrorLevel) {
logger.Error(err) logger.Error(ctx, err.Error())
} }
return return
} }
if err = rw.Flush(); err != nil { if err = rw.Flush(); err != nil {
if logger.V(logger.ErrorLevel, logger.DefaultLogger) { if logger.V(logger.ErrorLevel) {
logger.Error(err) logger.Error(ctx, err.Error())
} }
return return
} }
@ -195,8 +203,8 @@ func writeLoop(rw io.ReadWriter, stream client.Stream) {
return return
} }
} }
if logger.V(logger.ErrorLevel, logger.DefaultLogger) { if logger.V(logger.ErrorLevel) {
logger.Error(err) logger.Error(stream.Context(), err.Error())
} }
return return
} }
@ -210,10 +218,10 @@ func writeLoop(rw io.ReadWriter, stream client.Stream) {
// send to backend // send to backend
// default to trying json // default to trying json
// if the extracted payload isn't empty lets use it // if the extracted payload isn't empty lets use it
request := &raw.Frame{Data: buf} request := &codec.Frame{Data: buf}
if err := stream.Send(request); err != nil { if err := stream.Send(request); err != nil {
if logger.V(logger.ErrorLevel, logger.DefaultLogger) { if logger.V(logger.ErrorLevel) {
logger.Error(err) logger.Error(stream.Context(), err.Error())
} }
return return
} }