From 677f00c3c099a2f8878d73fadc95d863a170135b Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Wed, 27 Oct 2021 23:19:52 +0300 Subject: [PATCH 1/9] update workflows Signed-off-by: Vasiliy Tolstov --- .github/workflows/codeql-analysis.yml | 21 +++--- .github/workflows/dependabot-automerge.yml | 75 ++++++---------------- 2 files changed, 32 insertions(+), 64 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index fa4081e..b50aad2 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -9,7 +9,7 @@ # the `language` matrix defined below to confirm you have the correct set of # supported CodeQL languages. # -name: "CodeQL" +name: "codeql" on: workflow_run: @@ -17,16 +17,16 @@ on: types: - completed push: - branches: [ master ] + branches: [ master, v3 ] pull_request: # The branches below must be a subset of the branches above - branches: [ master ] + branches: [ master, v3 ] schedule: - cron: '34 1 * * 0' jobs: analyze: - name: Analyze + name: analyze runs-on: ubuntu-latest permissions: actions: read @@ -42,11 +42,14 @@ jobs: # 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 + - name: checkout uses: actions/checkout@v2 - + - name: setup + uses: actions/setup-go@v2 + with: + go-version: 1.16 # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL + - name: init uses: github/codeql-action/init@v1 with: languages: ${{ matrix.language }} @@ -57,7 +60,7 @@ jobs: # 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 + - name: autobuild uses: github/codeql-action/autobuild@v1 # ℹ️ Command-line programs to run using the OS shell. @@ -71,5 +74,5 @@ jobs: # make bootstrap # make release - - name: Perform CodeQL Analysis + - name: analyze uses: github/codeql-action/analyze@v1 diff --git a/.github/workflows/dependabot-automerge.yml b/.github/workflows/dependabot-automerge.yml index dd6a62e..69e4c39 100644 --- a/.github/workflows/dependabot-automerge.yml +++ b/.github/workflows/dependabot-automerge.yml @@ -1,66 +1,31 @@ name: "prautomerge" on: - workflow_run: - workflows: ["prbuild"] - types: - - completed + pull_request_target: + types: [assigned, opened, synchronize, reopened] permissions: - contents: write pull-requests: write + contents: write jobs: - Dependabot-Automerge: + dependabot: 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 )) + if: ${{ github.actor == 'dependabot[bot]' }} steps: - - name: Approve Changes and Merge changes if label 'dependencies' is set - uses: actions/github-script@v5 + - name: metadata + id: metadata + uses: dependabot/fetch-metadata@v1.1.1 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'); - } + github-token: "${{ secrets.TOKEN }}" + - name: approve + run: gh pr review --approve "$PR_URL" + env: + PR_URL: ${{github.event.pull_request.html_url}} + GITHUB_TOKEN: ${{secrets.TOKEN}} + - name: 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}} From e7b5a90b5cfb2efc3f3ef5d25b4a38cf703cda7b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 27 Oct 2021 20:25:03 +0000 Subject: [PATCH 2/9] Bump go.unistack.org/micro/v3 from 3.8.5 to 3.8.7 Bumps [go.unistack.org/micro/v3](https://github.com/unistack-org/micro) from 3.8.5 to 3.8.7. - [Release notes](https://github.com/unistack-org/micro/releases) - [Commits](https://github.com/unistack-org/micro/compare/v3.8.5...v3.8.7) --- updated-dependencies: - dependency-name: go.unistack.org/micro/v3 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index c03d21a..e29302b 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,6 @@ module go.unistack.org/micro-server-http/v3 go 1.16 require ( - go.unistack.org/micro/v3 v3.8.5 + go.unistack.org/micro/v3 v3.8.7 golang.org/x/net v0.0.0-20211020060615-d418f374d309 ) diff --git a/go.sum b/go.sum index 1aba847..4f222f5 100644 --- a/go.sum +++ b/go.sum @@ -9,8 +9,8 @@ github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTK 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.5 h1:DIYWRsQF+NPhKZP45sCtNsUhaRw6u2+Ps7U+pKU7i3s= -go.unistack.org/micro/v3 v3.8.5/go.mod h1:KMMmOmbgo/D52/rCAbqeKbBsgEEbSKM69he54J3ZIuA= +go.unistack.org/micro/v3 v3.8.7 h1:k1zOpJ3uS8MxdhK8annRsa5J/LW7MpqPjwYuekW61wE= +go.unistack.org/micro/v3 v3.8.7/go.mod h1:KMMmOmbgo/D52/rCAbqeKbBsgEEbSKM69he54J3ZIuA= golang.org/x/net v0.0.0-20210928044308-7d9f5e0b762b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211020060615-d418f374d309 h1:A0lJIi+hcTR6aajJH4YqKWwohY4aW9RO7oRMcdv+HKI= golang.org/x/net v0.0.0-20211020060615-d418f374d309/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= From 7a096d660573082a0471d1d6689c92a255976069 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 19 Nov 2021 17:22:25 +0000 Subject: [PATCH 3/9] Bump go.unistack.org/micro/v3 from 3.8.7 to 3.8.10 Bumps [go.unistack.org/micro/v3](https://github.com/unistack-org/micro) from 3.8.7 to 3.8.10. - [Release notes](https://github.com/unistack-org/micro/releases) - [Commits](https://github.com/unistack-org/micro/compare/v3.8.7...v3.8.10) --- updated-dependencies: - dependency-name: go.unistack.org/micro/v3 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index e29302b..faa3f5d 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,6 @@ module go.unistack.org/micro-server-http/v3 go 1.16 require ( - go.unistack.org/micro/v3 v3.8.7 + go.unistack.org/micro/v3 v3.8.10 golang.org/x/net v0.0.0-20211020060615-d418f374d309 ) diff --git a/go.sum b/go.sum index 4f222f5..b37f237 100644 --- a/go.sum +++ b/go.sum @@ -9,8 +9,8 @@ github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTK 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.7 h1:k1zOpJ3uS8MxdhK8annRsa5J/LW7MpqPjwYuekW61wE= -go.unistack.org/micro/v3 v3.8.7/go.mod h1:KMMmOmbgo/D52/rCAbqeKbBsgEEbSKM69he54J3ZIuA= +go.unistack.org/micro/v3 v3.8.10 h1:ZMKGGalqkZc677S5BmSPTAMZAE4q3u2FuqCrCd1TO7g= +go.unistack.org/micro/v3 v3.8.10/go.mod h1:KMMmOmbgo/D52/rCAbqeKbBsgEEbSKM69he54J3ZIuA= golang.org/x/net v0.0.0-20210928044308-7d9f5e0b762b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211020060615-d418f374d309 h1:A0lJIi+hcTR6aajJH4YqKWwohY4aW9RO7oRMcdv+HKI= golang.org/x/net v0.0.0-20211020060615-d418f374d309/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= From 4cb133546d363520335da408a69bf0532024ec11 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 24 Nov 2021 17:22:53 +0000 Subject: [PATCH 4/9] Bump go.unistack.org/micro/v3 from 3.8.10 to 3.8.11 Bumps [go.unistack.org/micro/v3](https://github.com/unistack-org/micro) from 3.8.10 to 3.8.11. - [Release notes](https://github.com/unistack-org/micro/releases) - [Commits](https://github.com/unistack-org/micro/compare/v3.8.10...v3.8.11) --- updated-dependencies: - dependency-name: go.unistack.org/micro/v3 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index faa3f5d..d8fcbd3 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,6 @@ module go.unistack.org/micro-server-http/v3 go 1.16 require ( - go.unistack.org/micro/v3 v3.8.10 + go.unistack.org/micro/v3 v3.8.11 golang.org/x/net v0.0.0-20211020060615-d418f374d309 ) diff --git a/go.sum b/go.sum index b37f237..462aeda 100644 --- a/go.sum +++ b/go.sum @@ -9,8 +9,8 @@ github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTK 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.10 h1:ZMKGGalqkZc677S5BmSPTAMZAE4q3u2FuqCrCd1TO7g= -go.unistack.org/micro/v3 v3.8.10/go.mod h1:KMMmOmbgo/D52/rCAbqeKbBsgEEbSKM69he54J3ZIuA= +go.unistack.org/micro/v3 v3.8.11 h1:Wv1YopcYNcsN3bW8Mv8v6AF99s0uKBtWQ1M/Ag8QLec= +go.unistack.org/micro/v3 v3.8.11/go.mod h1:KMMmOmbgo/D52/rCAbqeKbBsgEEbSKM69he54J3ZIuA= golang.org/x/net v0.0.0-20210928044308-7d9f5e0b762b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211020060615-d418f374d309 h1:A0lJIi+hcTR6aajJH4YqKWwohY4aW9RO7oRMcdv+HKI= golang.org/x/net v0.0.0-20211020060615-d418f374d309/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= From b93dcbb165ebae752adac93c02c123233d44562f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 28 Dec 2021 17:15:29 +0000 Subject: [PATCH 5/9] Bump go.unistack.org/micro/v3 from 3.8.11 to 3.8.13 Bumps [go.unistack.org/micro/v3](https://github.com/unistack-org/micro) from 3.8.11 to 3.8.13. - [Release notes](https://github.com/unistack-org/micro/releases) - [Commits](https://github.com/unistack-org/micro/compare/v3.8.11...v3.8.13) --- updated-dependencies: - dependency-name: go.unistack.org/micro/v3 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index d8fcbd3..96d7113 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,6 @@ module go.unistack.org/micro-server-http/v3 go 1.16 require ( - go.unistack.org/micro/v3 v3.8.11 + go.unistack.org/micro/v3 v3.8.13 golang.org/x/net v0.0.0-20211020060615-d418f374d309 ) diff --git a/go.sum b/go.sum index 462aeda..e8c03fc 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ github.com/ef-ds/deque v1.0.4/go.mod h1:gXDnTC3yqvBcHbq2lcExjtAcVrOnJCbMcZXmuj8Z4tg= -github.com/golang-jwt/jwt/v4 v4.1.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg= +github.com/golang-jwt/jwt/v4 v4.2.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= @@ -9,8 +9,8 @@ github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTK 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.11 h1:Wv1YopcYNcsN3bW8Mv8v6AF99s0uKBtWQ1M/Ag8QLec= -go.unistack.org/micro/v3 v3.8.11/go.mod h1:KMMmOmbgo/D52/rCAbqeKbBsgEEbSKM69he54J3ZIuA= +go.unistack.org/micro/v3 v3.8.13 h1:9ibK5UNJ1mmxh5PNaNUUEUj86nvhoJyJaVhcg8DTncM= +go.unistack.org/micro/v3 v3.8.13/go.mod h1:s5cpmK2YqOpIsn5FTVxQaNCa66rHxO+WBDwdQKbcYlU= golang.org/x/net v0.0.0-20210928044308-7d9f5e0b762b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211020060615-d418f374d309 h1:A0lJIi+hcTR6aajJH4YqKWwohY4aW9RO7oRMcdv+HKI= golang.org/x/net v0.0.0-20211020060615-d418f374d309/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= From 2816fd756a267a1c773e2194b05ce23a63ee2276 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 10 Jan 2022 17:21:25 +0000 Subject: [PATCH 6/9] Bump go.unistack.org/micro/v3 from 3.8.13 to 3.8.14 Bumps [go.unistack.org/micro/v3](https://github.com/unistack-org/micro) from 3.8.13 to 3.8.14. - [Release notes](https://github.com/unistack-org/micro/releases) - [Commits](https://github.com/unistack-org/micro/compare/v3.8.13...v3.8.14) --- updated-dependencies: - dependency-name: go.unistack.org/micro/v3 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 96d7113..1f32c6e 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,6 @@ module go.unistack.org/micro-server-http/v3 go 1.16 require ( - go.unistack.org/micro/v3 v3.8.13 + go.unistack.org/micro/v3 v3.8.14 golang.org/x/net v0.0.0-20211020060615-d418f374d309 ) diff --git a/go.sum b/go.sum index e8c03fc..caebc34 100644 --- a/go.sum +++ b/go.sum @@ -7,10 +7,10 @@ github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH 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/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.13 h1:9ibK5UNJ1mmxh5PNaNUUEUj86nvhoJyJaVhcg8DTncM= -go.unistack.org/micro/v3 v3.8.13/go.mod h1:s5cpmK2YqOpIsn5FTVxQaNCa66rHxO+WBDwdQKbcYlU= +go.unistack.org/micro-proto/v3 v3.1.1 h1:78qRmltwGek5kSQ9tNmDZ9TCRvZM7YDIOgzriKvabjA= +go.unistack.org/micro-proto/v3 v3.1.1/go.mod h1:DpRhYCBXlmSJ/AAXTmntvlh7kQkYU6eFvlmYAx4BQS8= +go.unistack.org/micro/v3 v3.8.14 h1:gvGAh11n484XuJFt+YFUvDJUwbn/a/6/NdTdTqeUnis= +go.unistack.org/micro/v3 v3.8.14/go.mod h1:zEbgew93bFhU+gANJubbbnPP1LtDTQRbM/17QXTbTrY= golang.org/x/net v0.0.0-20210928044308-7d9f5e0b762b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211020060615-d418f374d309 h1:A0lJIi+hcTR6aajJH4YqKWwohY4aW9RO7oRMcdv+HKI= golang.org/x/net v0.0.0-20211020060615-d418f374d309/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= From 8a6a25940433ecb066e53cc3f194f6960f085652 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 19 Jan 2022 17:20:18 +0000 Subject: [PATCH 7/9] Bump go.unistack.org/micro/v3 from 3.8.14 to 3.8.15 Bumps [go.unistack.org/micro/v3](https://github.com/unistack-org/micro) from 3.8.14 to 3.8.15. - [Release notes](https://github.com/unistack-org/micro/releases) - [Commits](https://github.com/unistack-org/micro/compare/v3.8.14...v3.8.15) --- updated-dependencies: - dependency-name: go.unistack.org/micro/v3 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 1f32c6e..fca5ab8 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,6 @@ module go.unistack.org/micro-server-http/v3 go 1.16 require ( - go.unistack.org/micro/v3 v3.8.14 + go.unistack.org/micro/v3 v3.8.15 golang.org/x/net v0.0.0-20211020060615-d418f374d309 ) diff --git a/go.sum b/go.sum index caebc34..c438b1e 100644 --- a/go.sum +++ b/go.sum @@ -9,8 +9,8 @@ github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTK github.com/silas/dag v0.0.0-20210626123444-3804bac2d6d4/go.mod h1:7RTUFBdIRC9nZ7/3RyRNH1bdqIShrDejd1YbLwgPS+I= go.unistack.org/micro-proto/v3 v3.1.1 h1:78qRmltwGek5kSQ9tNmDZ9TCRvZM7YDIOgzriKvabjA= go.unistack.org/micro-proto/v3 v3.1.1/go.mod h1:DpRhYCBXlmSJ/AAXTmntvlh7kQkYU6eFvlmYAx4BQS8= -go.unistack.org/micro/v3 v3.8.14 h1:gvGAh11n484XuJFt+YFUvDJUwbn/a/6/NdTdTqeUnis= -go.unistack.org/micro/v3 v3.8.14/go.mod h1:zEbgew93bFhU+gANJubbbnPP1LtDTQRbM/17QXTbTrY= +go.unistack.org/micro/v3 v3.8.15 h1:9KzaPmWW4CpThOT8tiq8XEG3YLmVV8hztqnzPBmJudQ= +go.unistack.org/micro/v3 v3.8.15/go.mod h1:zEbgew93bFhU+gANJubbbnPP1LtDTQRbM/17QXTbTrY= golang.org/x/net v0.0.0-20210928044308-7d9f5e0b762b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211020060615-d418f374d309 h1:A0lJIi+hcTR6aajJH4YqKWwohY4aW9RO7oRMcdv+HKI= golang.org/x/net v0.0.0-20211020060615-d418f374d309/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= From be637e8324bbc69d062cd813fb6024b7b0e7c9f2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 21 Jan 2022 17:19:27 +0000 Subject: [PATCH 8/9] Bump go.unistack.org/micro/v3 from 3.8.15 to 3.8.18 Bumps [go.unistack.org/micro/v3](https://github.com/unistack-org/micro) from 3.8.15 to 3.8.18. - [Release notes](https://github.com/unistack-org/micro/releases) - [Commits](https://github.com/unistack-org/micro/compare/v3.8.15...v3.8.18) --- updated-dependencies: - dependency-name: go.unistack.org/micro/v3 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index fca5ab8..ea9c700 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,6 @@ module go.unistack.org/micro-server-http/v3 go 1.16 require ( - go.unistack.org/micro/v3 v3.8.15 + go.unistack.org/micro/v3 v3.8.18 golang.org/x/net v0.0.0-20211020060615-d418f374d309 ) diff --git a/go.sum b/go.sum index c438b1e..ccfe5f0 100644 --- a/go.sum +++ b/go.sum @@ -6,11 +6,11 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= 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/silas/dag v0.0.0-20210626123444-3804bac2d6d4/go.mod h1:7RTUFBdIRC9nZ7/3RyRNH1bdqIShrDejd1YbLwgPS+I= +github.com/silas/dag v0.0.0-20211117232152-9d50aa809f35/go.mod h1:7RTUFBdIRC9nZ7/3RyRNH1bdqIShrDejd1YbLwgPS+I= go.unistack.org/micro-proto/v3 v3.1.1 h1:78qRmltwGek5kSQ9tNmDZ9TCRvZM7YDIOgzriKvabjA= go.unistack.org/micro-proto/v3 v3.1.1/go.mod h1:DpRhYCBXlmSJ/AAXTmntvlh7kQkYU6eFvlmYAx4BQS8= -go.unistack.org/micro/v3 v3.8.15 h1:9KzaPmWW4CpThOT8tiq8XEG3YLmVV8hztqnzPBmJudQ= -go.unistack.org/micro/v3 v3.8.15/go.mod h1:zEbgew93bFhU+gANJubbbnPP1LtDTQRbM/17QXTbTrY= +go.unistack.org/micro/v3 v3.8.18 h1:+7UiB46D9EoCgGN+JfhoWCvn36yvtplh6fmA1+ZiqEE= +go.unistack.org/micro/v3 v3.8.18/go.mod h1:ueDiiOe3fRW9kL0Fbh4OWw/R/SQhMd6vUcAV/WHYRWw= golang.org/x/net v0.0.0-20210928044308-7d9f5e0b762b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211020060615-d418f374d309 h1:A0lJIi+hcTR6aajJH4YqKWwohY4aW9RO7oRMcdv+HKI= golang.org/x/net v0.0.0-20211020060615-d418f374d309/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= From 6714e48f4f67fbfda0e7e7cc304c941b009e7b2d Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sat, 22 Jan 2022 01:10:24 +0300 Subject: [PATCH 9/9] internal rewrite to be more performant (#85) Signed-off-by: Vasiliy Tolstov --- go.mod | 2 +- go.sum | 10 +++++-- handler.go | 65 ++++++++++++++++++------------------------ http.go | 83 ++++++++++++++++++++++-------------------------------- options.go | 33 ++++++---------------- 5 files changed, 78 insertions(+), 115 deletions(-) diff --git a/go.mod b/go.mod index ea9c700..5bfc797 100644 --- a/go.mod +++ b/go.mod @@ -4,5 +4,5 @@ go 1.16 require ( go.unistack.org/micro/v3 v3.8.18 - golang.org/x/net v0.0.0-20211020060615-d418f374d309 + golang.org/x/net v0.0.0-20220121210141-e204ce36a2ba ) diff --git a/go.sum b/go.sum index ccfe5f0..e2c5c0a 100644 --- a/go.sum +++ b/go.sum @@ -12,12 +12,18 @@ go.unistack.org/micro-proto/v3 v3.1.1/go.mod h1:DpRhYCBXlmSJ/AAXTmntvlh7kQkYU6eF go.unistack.org/micro/v3 v3.8.18 h1:+7UiB46D9EoCgGN+JfhoWCvn36yvtplh6fmA1+ZiqEE= go.unistack.org/micro/v3 v3.8.18/go.mod h1:ueDiiOe3fRW9kL0Fbh4OWw/R/SQhMd6vUcAV/WHYRWw= golang.org/x/net v0.0.0-20210928044308-7d9f5e0b762b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20211020060615-d418f374d309 h1:A0lJIi+hcTR6aajJH4YqKWwohY4aW9RO7oRMcdv+HKI= -golang.org/x/net v0.0.0-20211020060615-d418f374d309/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20220121175114-2ed6ce1e1725 h1:YtkHkox9J+kfAdNdlvEXp2SkLMQSkSjWFP4sjgxEPa8= +golang.org/x/net v0.0.0-20220121175114-2ed6ce1e1725/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= +golang.org/x/net v0.0.0-20220121210141-e204ce36a2ba h1:6u6sik+bn/y7vILcYkK3iwTBWN7WtBvB0+SZswQnbf8= +golang.org/x/net v0.0.0-20220121210141-e204ce36a2ba/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= 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/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= 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= diff --git a/handler.go b/handler.go index f326d4d..124bb06 100644 --- a/handler.go +++ b/handler.go @@ -31,14 +31,13 @@ var ( type patHandler struct { mtype *methodType rcvr reflect.Value - pat *rhttp.Trie name string } type httpHandler struct { opts server.HandlerOptions hd interface{} - handlers map[string][]patHandler + handlers *rhttp.Trie name string eps []*register.Endpoint sopts server.Options @@ -62,6 +61,7 @@ func (h *httpHandler) Options() server.HandlerOptions { } func (h *httpServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { + // check for http.HandlerFunc handlers if ph, _, ok := h.pathHandlers.Search(r.Method, r.URL.Path); ok { ph.(http.HandlerFunc)(w, r) return @@ -72,17 +72,10 @@ func (h *httpServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { ct = htype } - if idx := strings.Index(ct, ":"); idx > 0 { - if ph, ok := h.contentTypeHandlers[ct[:idx]]; ok { - ph(w, r) - return - } - } - ctx := context.WithValue(r.Context(), rspCodeKey{}, &rspCodeVal{}) md, ok := metadata.FromIncomingContext(ctx) if !ok { - md = metadata.New(len(r.Header)) + md = metadata.New(len(r.Header) + 8) } for k, v := range r.Header { md.Set(k, strings.Join(v, ", ")) @@ -114,22 +107,20 @@ func (h *httpServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { matches := make(map[string]interface{}) var match bool - var hldr patHandler + var hldr *patHandler var handler *httpHandler - for _, hpat := range h.handlers { - handlertmp := hpat.(*httpHandler) - for _, hldrtmp := range handlertmp.handlers[r.Method] { - _, mp, ok := hldrtmp.pat.Search(r.Method, path) - if ok { - match = true - for k, v := range mp { - matches[k] = v - } - hldr = hldrtmp - handler = handlertmp - break + for _, shdlr := range h.handlers { + hdlr := shdlr.(*httpHandler) + fh, mp, ok := hdlr.handlers.Search(r.Method, path) + if ok { + match = true + for k, v := range mp { + matches[k] = v } + hldr = fh.(*patHandler) + handler = hdlr + break } } @@ -171,29 +162,29 @@ func (h *httpServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { function := hldr.mtype.method.Func var returnValues []reflect.Value - if err = cf.ReadBody(r.Body, argv.Interface()); err != nil && err != io.EOF { + buf, err := io.ReadAll(r.Body) + if err != nil && err != io.EOF { h.errorHandler(ctx, handler, w, r, err, http.StatusInternalServerError) return } + if err = cf.Unmarshal(buf, argv.Interface()); err != nil { + h.errorHandler(ctx, handler, w, r, err, http.StatusBadRequest) + return + } + matches = rflutil.FlattenMap(matches) if err = rflutil.Merge(argv.Interface(), matches, rflutil.SliceAppend(true), rflutil.Tags([]string{"protobuf", "json"})); err != nil { h.errorHandler(ctx, handler, w, r, err, http.StatusBadRequest) return } - b, err := cf.Marshal(argv.Interface()) - if err != nil { - h.errorHandler(ctx, handler, w, r, err, http.StatusBadRequest) - return - } - hr := &rpcRequest{ codec: cf, service: handler.sopts.Name, contentType: ct, method: fmt.Sprintf("%s.%s", hldr.name, hldr.mtype.method.Name), - body: b, + body: buf, payload: argv.Interface(), header: md, } @@ -255,14 +246,14 @@ func (h *httpServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { switch verr := appErr.(type) { case *errors.Error: scode = int(verr.Code) - b, err = cf.Marshal(verr) + buf, err = cf.Marshal(verr) case *Error: - b, err = cf.Marshal(verr.err) + buf, err = cf.Marshal(verr.err) default: - b, err = cf.Marshal(appErr) + buf, err = cf.Marshal(appErr) } } else { - b, err = cf.Marshal(replyv.Interface()) + buf, err = cf.Marshal(replyv.Interface()) } if err != nil && handler.sopts.Logger.V(logger.ErrorLevel) { @@ -275,7 +266,7 @@ func (h *httpServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { } w.WriteHeader(scode) - if _, cerr := w.Write(b); cerr != nil { - logger.DefaultLogger.Errorf(ctx, "write failed: %v", cerr) + if _, cerr := w.Write(buf); cerr != nil { + handler.sopts.Logger.Errorf(ctx, "write failed: %v", cerr) } } diff --git a/http.go b/http.go index b8f2448..1eb4047 100644 --- a/http.go +++ b/http.go @@ -22,29 +22,16 @@ import ( "golang.org/x/net/netutil" ) -var httpAllMethods = []string{ - http.MethodConnect, - http.MethodDelete, - http.MethodGet, - http.MethodHead, - http.MethodOptions, - http.MethodPatch, - http.MethodPost, - http.MethodPut, - http.MethodTrace, -} - type httpServer struct { - hd server.Handler - rsvc *register.Service - handlers map[string]server.Handler - exit chan chan error - subscribers map[*httpSubscriber][]broker.Subscriber - errorHandler func(context.Context, server.Handler, http.ResponseWriter, *http.Request, error, int) - pathHandlers *rhttp.Trie - contentTypeHandlers map[string]http.HandlerFunc - opts server.Options - registerRPC bool + hd server.Handler + rsvc *register.Service + handlers map[string]server.Handler + exit chan chan error + subscribers map[*httpSubscriber][]broker.Subscriber + errorHandler func(context.Context, server.Handler, http.ResponseWriter, *http.Request, error, int) + pathHandlers *rhttp.Trie + opts server.Options + registerRPC bool sync.RWMutex registered bool init bool @@ -89,22 +76,19 @@ func (h *httpServer) Init(opts ...server.Option) error { if h.pathHandlers == nil { h.pathHandlers = rhttp.NewTrie() } - if h.contentTypeHandlers == nil { - h.contentTypeHandlers = make(map[string]http.HandlerFunc) - } if v, ok := h.opts.Context.Value(registerRPCHandlerKey{}).(bool); ok { h.registerRPC = v } if phs, ok := h.opts.Context.Value(pathHandlerKey{}).(*pathHandlerVal); ok && phs.h != nil { - for pp, ph := range phs.h { - h.pathHandlers.Insert(httpAllMethods, pp, ph) - } - } - if phs, ok := h.opts.Context.Value(contentTypeHandlerKey{}).(*contentTypeHandlerVal); ok && phs.h != nil { - for pp, ph := range phs.h { - h.contentTypeHandlers[pp] = ph + for pm, ps := range phs.h { + for pp, ph := range ps { + if err := h.pathHandlers.Insert([]string{pm}, pp, ph); err != nil { + h.Unlock() + return err + } + } } } h.Unlock() @@ -148,6 +132,7 @@ func (h *httpServer) Init(opts ...server.Option) error { } func (h *httpServer) Handle(handler server.Handler) error { + // passed unknown handler hdlr, ok := handler.(*httpHandler) if !ok { h.Lock() @@ -156,6 +141,7 @@ func (h *httpServer) Handle(handler server.Handler) error { return nil } + // passed http.Handler like some muxer if _, ok := hdlr.hd.(http.Handler); ok { h.Lock() h.hd = handler @@ -163,6 +149,7 @@ func (h *httpServer) Handle(handler server.Handler) error { return nil } + // passed micro compat handler h.Lock() if h.handlers == nil { h.handlers = make(map[string]server.Handler) @@ -185,20 +172,16 @@ func (h *httpServer) NewHandler(handler interface{}, opts ...server.HandlerOptio } hdlr := &httpHandler{ - eps: eps, - hd: handler, - opts: options, - sopts: h.opts, + eps: eps, + hd: handler, + opts: options, + sopts: h.opts, + handlers: rhttp.NewTrie(), } tp := reflect.TypeOf(handler) - type nilHandler struct{} - hdlr.handlers = make(map[string][]patHandler) for hn, md := range options.Metadata { - pat := rhttp.NewTrie() - pat.Insert([]string{md["Method"]}, md["Path"], &nilHandler{}) - var method reflect.Method mname := hn[strings.Index(hn, ".")+1:] for m := 0; m < tp.NumMethod(); m++ { @@ -220,25 +203,25 @@ func (h *httpServer) NewHandler(handler interface{}, opts ...server.HandlerOptio h.opts.Logger.Errorf(h.opts.Context, "%v", err) continue } else if mtype == nil { + h.opts.Logger.Errorf(h.opts.Context, "nil mtype for %s", mname) continue } rcvr := reflect.ValueOf(handler) name := reflect.Indirect(rcvr).Type().Name() - pth := patHandler{pat: pat, mtype: mtype, name: name, rcvr: rcvr} + pth := &patHandler{mtype: mtype, name: name, rcvr: rcvr} hdlr.name = name - hdlr.handlers[md["Method"]] = append(hdlr.handlers[md["Method"]], pth) - if !h.registerRPC { - continue + if err := hdlr.handlers.Insert([]string{md["Method"]}, md["Path"], pth); err != nil { + h.opts.Logger.Errorf(h.opts.Context, "cant add handler for %s %s", md["Method"], md["Path"]) } - rpat := rhttp.NewTrie() - rpat.Insert([]string{http.MethodPost}, "/"+hn, &nilHandler{}) - - pth = patHandler{pat: rpat, mtype: mtype, name: name, rcvr: rcvr} - hdlr.handlers[http.MethodPost] = append(hdlr.handlers[http.MethodPost], pth) + if h.registerRPC { + if err := hdlr.handlers.Insert([]string{http.MethodPost}, "/"+hn, pth); err != nil { + h.opts.Logger.Errorf(h.opts.Context, "cant add handler for %s %s", md["Method"], md["Path"]) + } + } } return hdlr diff --git a/options.go b/options.go index 2b7c805..7a2903d 100644 --- a/options.go +++ b/options.go @@ -78,44 +78,27 @@ func ErrorHandler(fn func(ctx context.Context, s server.Handler, w http.Response type ( pathHandlerKey struct{} pathHandlerVal struct { - h map[string]http.HandlerFunc + h map[string]map[string]http.HandlerFunc } ) // PathHandler specifies http handler for path regexp -func PathHandler(path string, h http.HandlerFunc) server.Option { +func PathHandler(method, path string, handler http.HandlerFunc) server.Option { return func(o *server.Options) { if o.Context == nil { o.Context = context.Background() } v, ok := o.Context.Value(pathHandlerKey{}).(*pathHandlerVal) if !ok { - v = &pathHandlerVal{h: make(map[string]http.HandlerFunc)} + v = &pathHandlerVal{h: make(map[string]map[string]http.HandlerFunc)} } - v.h[path] = h - o.Context = context.WithValue(o.Context, pathHandlerKey{}, v) - } -} - -type ( - contentTypeHandlerKey struct{} - contentTypeHandlerVal struct { - h map[string]http.HandlerFunc - } -) - -// ContentTypeHandler specifies http handler for Content-Type -func ContentTypeHandler(ct string, h http.HandlerFunc) server.Option { - return func(o *server.Options) { - if o.Context == nil { - o.Context = context.Background() - } - v, ok := o.Context.Value(contentTypeHandlerKey{}).(*contentTypeHandlerVal) + m, ok := v.h[method] if !ok { - v = &contentTypeHandlerVal{h: make(map[string]http.HandlerFunc)} + m = make(map[string]http.HandlerFunc) + v.h[method] = m } - v.h[ct] = h - o.Context = context.WithValue(o.Context, contentTypeHandlerKey{}, v) + m[path] = handler + o.Context = context.WithValue(o.Context, pathHandlerKey{}, v) } }