register and deregister
This commit is contained in:
parent
88911744b5
commit
00b9b850c6
6
http.go
6
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()
|
||||
}()
|
||||
|
||||
|
17
http_test.go
17
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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user