From 00b9b850c603b3a644aec182654cc31aea660f1d Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 24 Jan 2019 13:58:56 +0000 Subject: [PATCH] register and deregister --- http.go | 6 ++++++ http_test.go | 17 ----------------- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/http.go b/http.go index 9040f09..9b1385c 100644 --- a/http.go +++ b/http.go @@ -246,12 +246,18 @@ func (h *httpServer) Start() error { return errors.New("Server required http.Handler") } + // register + h.Register() + go http.Serve(ln, handler) go func() { ch := <-h.exit ch <- ln.Close() + // deregister + h.Deregister() + opts.Broker.Disconnect() }() diff --git a/http_test.go b/http_test.go index edf2b23..483d9fd 100644 --- a/http_test.go +++ b/http_test.go @@ -6,7 +6,6 @@ import ( "net/http" "testing" - "github.com/micro/go-micro/registry" "github.com/micro/go-micro/registry/memory" "github.com/micro/go-micro/server" ) @@ -36,11 +35,6 @@ func TestHTTPServer(t *testing.T) { t.Fatal(err) } - // register server - if err := srv.Register(); err != nil { - t.Fatal(err) - } - // lookup server service, err := reg.GetService(server.DefaultName) if err != nil { @@ -71,17 +65,6 @@ func TestHTTPServer(t *testing.T) { t.Fatalf("Expected response %s, got %s", "hello world", s) } - // deregister server - if err := srv.Deregister(); err != nil { - t.Fatal(err) - } - - // try get service - service, err = reg.GetService(server.DefaultName) - if err == nil { - t.Fatalf("Expected %v got %+v", registry.ErrNotFound, service) - } - // stop server if err := srv.Stop(); err != nil { t.Fatal(err)