From 3eb135aaf2e2942538cf4af2b95308db40ecce59 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 9 Jul 2019 18:41:26 +0100 Subject: [PATCH] move transport back --- http.go | 11 ---- http_test.go | 138 --------------------------------------------------- options.go | 23 --------- 3 files changed, 172 deletions(-) delete mode 100644 http.go delete mode 100644 http_test.go delete mode 100644 options.go diff --git a/http.go b/http.go deleted file mode 100644 index a3a6bbf..0000000 --- a/http.go +++ /dev/null @@ -1,11 +0,0 @@ -// Package http returns a http2 transport using net/http -package http - -import ( - "github.com/micro/go-micro/network/transport" -) - -// NewTransport returns a new http transport using net/http and supporting http2 -func NewTransport(opts ...transport.Option) transport.Transport { - return transport.NewTransport(opts...) -} diff --git a/http_test.go b/http_test.go deleted file mode 100644 index 5744503..0000000 --- a/http_test.go +++ /dev/null @@ -1,138 +0,0 @@ -package http - -import ( - "sync" - "testing" - - "github.com/micro/go-micro/network/transport" -) - -func call(b *testing.B, c int) { - b.StopTimer() - - tr := NewTransport() - - // server listen - l, err := tr.Listen("localhost:0") - if err != nil { - b.Fatal(err) - } - defer l.Close() - - // socket func - fn := func(sock transport.Socket) { - defer sock.Close() - - for { - var m transport.Message - if err := sock.Recv(&m); err != nil { - return - } - - if err := sock.Send(&m); err != nil { - return - } - } - } - - done := make(chan bool) - - // accept connections - go func() { - if err := l.Accept(fn); err != nil { - select { - case <-done: - default: - b.Fatalf("Unexpected accept err: %v", err) - } - } - }() - - m := transport.Message{ - Header: map[string]string{ - "Content-Type": "application/json", - }, - Body: []byte(`{"message": "Hello World"}`), - } - - // client connection - client, err := tr.Dial(l.Addr()) - if err != nil { - b.Fatalf("Unexpected dial err: %v", err) - } - - send := func(c transport.Client) { - // send message - if err := c.Send(&m); err != nil { - b.Fatalf("Unexpected send err: %v", err) - } - - var rm transport.Message - // receive message - if err := c.Recv(&rm); err != nil { - b.Fatalf("Unexpected recv err: %v", err) - } - } - - // warm - for i := 0; i < 10; i++ { - send(client) - } - - client.Close() - - ch := make(chan int, c*4) - - var wg sync.WaitGroup - wg.Add(c) - - for i := 0; i < c; i++ { - go func() { - cl, err := tr.Dial(l.Addr()) - if err != nil { - b.Fatalf("Unexpected dial err: %v", err) - } - defer cl.Close() - - for range ch { - send(cl) - } - - wg.Done() - }() - } - - b.StartTimer() - - for i := 0; i < b.N; i++ { - ch <- i - } - - b.StopTimer() - close(ch) - - wg.Wait() - - // finish - close(done) -} - -func BenchmarkTransport1(b *testing.B) { - call(b, 1) -} - -func BenchmarkTransport8(b *testing.B) { - call(b, 8) -} - -func BenchmarkTransport16(b *testing.B) { - call(b, 16) -} - -func BenchmarkTransport64(b *testing.B) { - call(b, 64) -} - -func BenchmarkTransport128(b *testing.B) { - call(b, 128) -} diff --git a/options.go b/options.go deleted file mode 100644 index 3d70f94..0000000 --- a/options.go +++ /dev/null @@ -1,23 +0,0 @@ -package http - -import ( - "context" - "net/http" - - "github.com/micro/go-micro/network/transport" -) - -// Handle registers the handler for the given pattern. -func Handle(pattern string, handler http.Handler) transport.Option { - return func(o *transport.Options) { - if o.Context == nil { - o.Context = context.Background() - } - handlers, ok := o.Context.Value("http_handlers").(map[string]http.Handler) - if !ok { - handlers = make(map[string]http.Handler) - } - handlers[pattern] = handler - o.Context = context.WithValue(o.Context, "http_handlers", handlers) - } -}