fix:http server start panic when use Endpoint (#1492)

pull/1496/head
seasrain 3 years ago committed by GitHub
parent 55e00ce9f3
commit 423b60b330
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      transport/http/server.go
  2. 10
      transport/http/server_test.go

@ -91,13 +91,6 @@ func ErrorEncoder(en EncodeErrorFunc) ServerOption {
} }
} }
// Endpoint with server endpoint.
func Endpoint(endpoint *url.URL) ServerOption {
return func(o *Server) {
o.endpoint = endpoint
}
}
// TLSConfig with TLS config. // TLSConfig with TLS config.
func TLSConfig(c *tls.Config) ServerOption { func TLSConfig(c *tls.Config) ServerOption {
return func(o *Server) { return func(o *Server) {
@ -227,9 +220,6 @@ func (s *Server) filter() mux.MiddlewareFunc {
// http://127.0.0.1:8000?isSecure=false // http://127.0.0.1:8000?isSecure=false
func (s *Server) Endpoint() (*url.URL, error) { func (s *Server) Endpoint() (*url.URL, error) {
s.once.Do(func() { s.once.Do(func() {
if s.endpoint != nil {
return
}
lis, err := net.Listen(s.network, s.address) lis, err := net.Listen(s.network, s.address)
if err != nil { if err != nil {
s.err = err s.err = err

@ -7,7 +7,6 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"net/url"
"strings" "strings"
"testing" "testing"
"time" "time"
@ -201,15 +200,6 @@ func TestLogger(t *testing.T) {
// todo // todo
} }
func TestEndpoint(t *testing.T) {
u, err := url.Parse("http://hello/world")
assert.NoError(t, err)
o := &Server{}
Endpoint(u)(o)
assert.Equal(t, "hello", o.endpoint.Host)
assert.Equal(t, "http", o.endpoint.Scheme)
}
func TestMiddleware(t *testing.T) { func TestMiddleware(t *testing.T) {
o := &Server{} o := &Server{}
v := []middleware.Middleware{ v := []middleware.Middleware{

Loading…
Cancel
Save