Compare commits

..

No commits in common. "v3" and "upstream" have entirely different histories.
v3 ... upstream

19 changed files with 70 additions and 593 deletions

View File

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

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

View File

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

View File

@ -1,9 +0,0 @@
## 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**

View File

@ -1,19 +0,0 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
version: 2
updates:
# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
# Maintain dependencies for Golang
- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "daily"

View File

@ -1,20 +0,0 @@
name: "autoapprove"
on:
pull_request_target:
types: [assigned, opened, synchronize, reopened]
permissions:
pull-requests: write
contents: write
jobs:
autoapprove:
runs-on: ubuntu-latest
steps:
- name: approve
uses: hmarr/auto-approve-action@v3
if: github.actor == 'vtolstov' || github.actor == 'dependabot[bot]'
id: approve
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

View File

@ -1,21 +0,0 @@
name: "automerge"
on:
pull_request_target:
types: [assigned, opened, synchronize, reopened]
permissions:
pull-requests: write
contents: write
jobs:
automerge:
runs-on: ubuntu-latest
if: github.actor == 'vtolstov'
steps:
- name: merge
id: merge
run: gh pr merge --auto --merge "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{secrets.TOKEN}}

View File

@ -1,47 +0,0 @@
name: build
on:
push:
branches:
- master
- v3
jobs:
test:
name: test
runs-on: ubuntu-latest
steps:
- name: setup
uses: actions/setup-go@v3
with:
go-version: 1.17
- name: checkout
uses: actions/checkout@v3
- name: cache
uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-go-
- name: deps
run: go get -v -t -d ./...
- name: test
env:
INTEGRATION_TESTS: yes
run: go test -mod readonly -v ./...
lint:
name: lint
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v3
- name: lint
uses: golangci/golangci-lint-action@v3.4.0
continue-on-error: true
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.30
# Optional: working directory, useful for monorepos
# working-directory: somedir
# Optional: golangci-lint command line arguments.
# args: --issues-exit-code=0
# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true

View File

@ -1,78 +0,0 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "codeql"
on:
workflow_run:
workflows: ["prbuild"]
types:
- completed
push:
branches: [ master, v3 ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ master, v3 ]
schedule:
- cron: '34 1 * * 0'
jobs:
analyze:
name: analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
language: [ 'go' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
# Learn more:
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
steps:
- name: checkout
uses: actions/checkout@v3
- name: setup
uses: actions/setup-go@v3
with:
go-version: 1.17
# Initializes the CodeQL tools for scanning.
- name: init
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: autobuild
uses: github/codeql-action/autobuild@v2
# Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language
#- run: |
# make bootstrap
# make release
- name: analyze
uses: github/codeql-action/analyze@v2

View File

@ -1,27 +0,0 @@
name: "dependabot-automerge"
on:
pull_request_target:
types: [assigned, opened, synchronize, reopened]
permissions:
pull-requests: write
contents: write
jobs:
automerge:
runs-on: ubuntu-latest
if: github.actor == 'dependabot[bot]'
steps:
- name: metadata
id: metadata
uses: dependabot/fetch-metadata@v1.3.6
with:
github-token: "${{ secrets.TOKEN }}"
- name: merge
id: merge
if: ${{contains(steps.metadata.outputs.dependency-names, 'go.unistack.org')}}
run: gh pr merge --auto --merge "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{secrets.TOKEN}}

View File

@ -1,47 +0,0 @@
name: prbuild
on:
pull_request:
branches:
- master
- v3
jobs:
test:
name: test
runs-on: ubuntu-latest
steps:
- name: setup
uses: actions/setup-go@v3
with:
go-version: 1.17
- name: checkout
uses: actions/checkout@v3
- name: cache
uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-go-
- name: deps
run: go get -v -t -d ./...
- name: test
env:
INTEGRATION_TESTS: yes
run: go test -mod readonly -v ./...
lint:
name: lint
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v3
- name: lint
uses: golangci/golangci-lint-action@v3.4.0
continue-on-error: true
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.30
# Optional: working directory, useful for monorepos
# working-directory: somedir
# Optional: golangci-lint command line arguments.
# args: --issues-exit-code=0
# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true

View File

@ -1 +0,0 @@
8975184b88a75a692780bbd4d6b18f0a28e99819

201
LICENSE
View File

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

8
go.mod
View File

@ -1,8 +0,0 @@
module go.unistack.org/micro-network-transport-http/v3
go 1.16
require (
go.unistack.org/micro/v3 v3.10.14
golang.org/x/net v0.0.0-20220225172249-27dd8689420f
)

16
go.sum
View File

@ -1,16 +0,0 @@
github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg=
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
github.com/silas/dag v0.0.0-20211117232152-9d50aa809f35/go.mod h1:7RTUFBdIRC9nZ7/3RyRNH1bdqIShrDejd1YbLwgPS+I=
go.unistack.org/micro/v3 v3.10.14 h1:7fgLpwGlCN67twhwtngJDEQvrMkUBDSA5vzZqxIDqNE=
go.unistack.org/micro/v3 v3.10.14/go.mod h1:uMAc0U/x7dmtICCrblGf0ZLgYegu3VwQAquu+OFCw1Q=
golang.org/x/net v0.0.0-20220225172249-27dd8689420f h1:oA4XRj0qtSt8Yo1Zms0CUlsT3KG69V2UGQWPBxujDmc=
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
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-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
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=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

74
http.go
View File

@ -1,9 +1,8 @@
package http // import "go.unistack.org/micro-network-transport-http/v3" package http
import ( import (
"bufio" "bufio"
"bytes" "bytes"
"context"
"crypto/tls" "crypto/tls"
"errors" "errors"
"io" "io"
@ -14,9 +13,11 @@ import (
"sync" "sync"
"time" "time"
"go.unistack.org/micro/v3/network/transport" "github.com/micro/go-micro/v3/network/transport"
"go.unistack.org/micro/v3/util/buf" maddr "github.com/micro/go-micro/v3/util/addr"
mnet "go.unistack.org/micro/v3/util/net" "github.com/micro/go-micro/v3/util/buf"
mnet "github.com/micro/go-micro/v3/util/net"
mls "github.com/micro/go-micro/v3/util/tls"
"golang.org/x/net/http2" "golang.org/x/net/http2"
"golang.org/x/net/http2/h2c" "golang.org/x/net/http2/h2c"
) )
@ -468,7 +469,7 @@ func (h *httpTransportListener) Accept(fn func(transport.Socket)) error {
} }
// insecure connection use h2c // insecure connection use h2c
if h.ht.opts.TLSConfig == nil { if !(h.ht.opts.Secure || h.ht.opts.TLSConfig != nil) {
srv.Handler = h2c.NewHandler(mux, &http2.Server{}) srv.Handler = h2c.NewHandler(mux, &http2.Server{})
} }
@ -476,14 +477,20 @@ func (h *httpTransportListener) Accept(fn func(transport.Socket)) error {
return srv.Serve(h.listener) return srv.Serve(h.listener)
} }
func (h *httpTransport) Dial(ctx context.Context, addr string, opts ...transport.DialOption) (transport.Client, error) { func (h *httpTransport) Dial(addr string, opts ...transport.DialOption) (transport.Client, error) {
dopts := transport.DialOptions{
Timeout: transport.DefaultDialTimeout,
}
for _, opt := range opts {
opt(&dopts)
}
var conn net.Conn var conn net.Conn
var err error var err error
dopts := transport.NewDialOptions(opts...)
// TODO: support dial option here rather than using internal config // TODO: support dial option here rather than using internal config
if h.opts.TLSConfig != nil { if h.opts.Secure || h.opts.TLSConfig != nil {
config := h.opts.TLSConfig config := h.opts.TLSConfig
if config == nil { if config == nil {
config = &tls.Config{ config = &tls.Config{
@ -496,7 +503,7 @@ func (h *httpTransport) Dial(ctx context.Context, addr string, opts ...transport
})(addr) })(addr)
} else { } else {
conn, err = newConn(func(addr string) (net.Conn, error) { conn, err = newConn(func(addr string) (net.Conn, error) {
return (&net.Dialer{Timeout: dopts.Timeout}).DialContext(ctx, "tcp", addr) return net.DialTimeout("tcp", addr, dopts.Timeout)
})(addr) })(addr)
} }
@ -516,17 +523,40 @@ func (h *httpTransport) Dial(ctx context.Context, addr string, opts ...transport
}, nil }, nil
} }
func (h *httpTransport) Listen(ctx context.Context, addr string, opts ...transport.ListenOption) (transport.Listener, error) { func (h *httpTransport) Listen(addr string, opts ...transport.ListenOption) (transport.Listener, error) {
var options transport.ListenOptions
for _, o := range opts {
o(&options)
}
var l net.Listener var l net.Listener
var err error var err error
options := transport.NewListenOptions(opts...)
_ = options
// TODO: support use of listen options // TODO: support use of listen options
if h.opts.TLSConfig != nil { if h.opts.Secure || h.opts.TLSConfig != nil {
config := h.opts.TLSConfig
fn := func(addr string) (net.Listener, error) { fn := func(addr string) (net.Listener, error) {
return tls.Listen("tcp", addr, h.opts.TLSConfig) if config == nil {
hosts := []string{addr}
// check if its a valid host:port
if host, _, err := net.SplitHostPort(addr); err == nil {
if len(host) == 0 {
hosts = maddr.IPs()
} else {
hosts = []string{host}
}
}
// generate a certificate
cert, err := mls.Certificate(hosts...)
if err != nil {
return nil, err
}
config = &tls.Config{Certificates: []tls.Certificate{cert}}
}
return tls.Listen("tcp", addr, config)
} }
l, err = mnet.Listen(addr, fn) l, err = mnet.Listen(addr, fn)
@ -563,10 +593,10 @@ func (h *httpTransport) String() string {
return "http" return "http"
} }
func (h *httpTransport) Name() string {
return h.opts.Name
}
func NewTransport(opts ...transport.Option) transport.Transport { func NewTransport(opts ...transport.Option) transport.Transport {
return &httpTransport{opts: transport.NewOptions(opts...)} var options transport.Options
for _, o := range opts {
o(&options)
}
return &httpTransport{opts: options}
} }

View File

@ -1,21 +1,19 @@
package http package http
import ( import (
"context"
"sync" "sync"
"testing" "testing"
"go.unistack.org/micro/v3/network/transport" "github.com/micro/go-micro/v3/network/transport"
) )
func call(b *testing.B, c int) { func call(b *testing.B, c int) {
b.StopTimer() b.StopTimer()
ctx := context.Background()
tr := NewTransport() tr := NewTransport()
// server listen // server listen
l, err := tr.Listen(ctx, "localhost:0") l, err := tr.Listen("localhost:0")
if err != nil { if err != nil {
b.Fatal(err) b.Fatal(err)
} }
@ -58,7 +56,7 @@ func call(b *testing.B, c int) {
} }
// client connection // client connection
client, err := tr.Dial(ctx, l.Addr()) client, err := tr.Dial(l.Addr())
if err != nil { if err != nil {
b.Fatalf("Unexpected dial err: %v", err) b.Fatalf("Unexpected dial err: %v", err)
} }
@ -90,7 +88,7 @@ func call(b *testing.B, c int) {
for i := 0; i < c; i++ { for i := 0; i < c; i++ {
go func() { go func() {
cl, err := tr.Dial(ctx, l.Addr()) cl, err := tr.Dial(l.Addr())
if err != nil { if err != nil {
b.Fatalf("Unexpected dial err: %v", err) b.Fatalf("Unexpected dial err: %v", err)
} }

View File

@ -1,13 +1,12 @@
package http package http
import ( import (
"context"
"io" "io"
"net" "net"
"testing" "testing"
"time" "time"
"go.unistack.org/micro/v3/network/transport" "github.com/micro/go-micro/v3/network/transport"
) )
func expectedPort(t *testing.T, expected string, lsn transport.Listener) { func expectedPort(t *testing.T, expected string, lsn transport.Listener) {
@ -24,20 +23,20 @@ func expectedPort(t *testing.T, expected string, lsn transport.Listener) {
func TestHTTPTransportPortRange(t *testing.T) { func TestHTTPTransportPortRange(t *testing.T) {
tp := NewTransport() tp := NewTransport()
ctx := context.Background()
lsn1, err := tp.Listen(ctx, ":44444-44448") lsn1, err := tp.Listen(":44444-44448")
if err != nil { if err != nil {
t.Errorf("Did not expect an error, got %s", err) t.Errorf("Did not expect an error, got %s", err)
} }
expectedPort(t, "44444", lsn1) expectedPort(t, "44444", lsn1)
lsn2, err := tp.Listen(ctx, ":44444-44448") lsn2, err := tp.Listen(":44444-44448")
if err != nil { if err != nil {
t.Errorf("Did not expect an error, got %s", err) t.Errorf("Did not expect an error, got %s", err)
} }
expectedPort(t, "44445", lsn2) expectedPort(t, "44445", lsn2)
lsn, err := tp.Listen(ctx, "127.0.0.1:0") lsn, err := tp.Listen("127.0.0.1:0")
if err != nil { if err != nil {
t.Errorf("Did not expect an error, got %s", err) t.Errorf("Did not expect an error, got %s", err)
} }
@ -49,8 +48,8 @@ func TestHTTPTransportPortRange(t *testing.T) {
func TestHTTPTransportCommunication(t *testing.T) { func TestHTTPTransportCommunication(t *testing.T) {
tr := NewTransport() tr := NewTransport()
ctx := context.Background()
l, err := tr.Listen(ctx, "127.0.0.1:0") l, err := tr.Listen("127.0.0.1:0")
if err != nil { if err != nil {
t.Errorf("Unexpected listen err: %v", err) t.Errorf("Unexpected listen err: %v", err)
} }
@ -83,7 +82,7 @@ func TestHTTPTransportCommunication(t *testing.T) {
} }
}() }()
c, err := tr.Dial(ctx, l.Addr()) c, err := tr.Dial(l.Addr())
if err != nil { if err != nil {
t.Errorf("Unexpected dial err: %v", err) t.Errorf("Unexpected dial err: %v", err)
} }
@ -115,9 +114,8 @@ func TestHTTPTransportCommunication(t *testing.T) {
func TestHTTPTransportError(t *testing.T) { func TestHTTPTransportError(t *testing.T) {
tr := NewTransport() tr := NewTransport()
ctx := context.Background()
l, err := tr.Listen(ctx, "127.0.0.1:0") l, err := tr.Listen("127.0.0.1:0")
if err != nil { if err != nil {
t.Errorf("Unexpected listen err: %v", err) t.Errorf("Unexpected listen err: %v", err)
} }
@ -153,7 +151,7 @@ func TestHTTPTransportError(t *testing.T) {
} }
}() }()
c, err := tr.Dial(ctx, l.Addr()) c, err := tr.Dial(l.Addr())
if err != nil { if err != nil {
t.Errorf("Unexpected dial err: %v", err) t.Errorf("Unexpected dial err: %v", err)
} }
@ -186,8 +184,8 @@ func TestHTTPTransportError(t *testing.T) {
func TestHTTPTransportTimeout(t *testing.T) { func TestHTTPTransportTimeout(t *testing.T) {
tr := NewTransport(transport.Timeout(time.Millisecond * 100)) tr := NewTransport(transport.Timeout(time.Millisecond * 100))
ctx := context.Background()
l, err := tr.Listen(ctx, "127.0.0.1:0") l, err := tr.Listen("127.0.0.1:0")
if err != nil { if err != nil {
t.Errorf("Unexpected listen err: %v", err) t.Errorf("Unexpected listen err: %v", err)
} }
@ -229,7 +227,7 @@ func TestHTTPTransportTimeout(t *testing.T) {
} }
}() }()
c, err := tr.Dial(ctx, l.Addr()) c, err := tr.Dial(l.Addr())
if err != nil { if err != nil {
t.Errorf("Unexpected dial err: %v", err) t.Errorf("Unexpected dial err: %v", err)
} }

View File

@ -4,7 +4,7 @@ import (
"context" "context"
"net/http" "net/http"
"go.unistack.org/micro/v3/network/transport" "github.com/micro/go-micro/v3/network/transport"
) )
// Handle registers the handler for the given pattern. // Handle registers the handler for the given pattern.