register and deregister

This commit is contained in:
Asim Aslam 2019-01-24 13:58:56 +00:00 committed by Vasiliy Tolstov
parent 88911744b5
commit 00b9b850c6
2 changed files with 6 additions and 17 deletions

View File

@ -246,12 +246,18 @@ func (h *httpServer) Start() error {
return errors.New("Server required http.Handler") return errors.New("Server required http.Handler")
} }
// register
h.Register()
go http.Serve(ln, handler) go http.Serve(ln, handler)
go func() { go func() {
ch := <-h.exit ch := <-h.exit
ch <- ln.Close() ch <- ln.Close()
// deregister
h.Deregister()
opts.Broker.Disconnect() opts.Broker.Disconnect()
}() }()

View File

@ -6,7 +6,6 @@ import (
"net/http" "net/http"
"testing" "testing"
"github.com/micro/go-micro/registry"
"github.com/micro/go-micro/registry/memory" "github.com/micro/go-micro/registry/memory"
"github.com/micro/go-micro/server" "github.com/micro/go-micro/server"
) )
@ -36,11 +35,6 @@ func TestHTTPServer(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
// register server
if err := srv.Register(); err != nil {
t.Fatal(err)
}
// lookup server // lookup server
service, err := reg.GetService(server.DefaultName) service, err := reg.GetService(server.DefaultName)
if err != nil { if err != nil {
@ -71,17 +65,6 @@ func TestHTTPServer(t *testing.T) {
t.Fatalf("Expected response %s, got %s", "hello world", s) 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 // stop server
if err := srv.Stop(); err != nil { if err := srv.Stop(); err != nil {
t.Fatal(err) t.Fatal(err)