handle RegisterInterval option

This commit is contained in:
xinfei.wu 2019-02-01 17:11:25 +08:00 committed by Vasiliy Tolstov
parent 00b9b850c6
commit b8a7b08984

27
http.go
View File

@ -8,6 +8,7 @@ import (
"net/http" "net/http"
"sort" "sort"
"sync" "sync"
"time"
log "github.com/micro/go-log" log "github.com/micro/go-log"
"github.com/micro/go-micro/broker" "github.com/micro/go-micro/broker"
@ -252,7 +253,31 @@ func (h *httpServer) Start() error {
go http.Serve(ln, handler) go http.Serve(ln, handler)
go func() { go func() {
ch := <-h.exit t := new(time.Ticker)
// only process if it exists
if opts.RegisterInterval > time.Duration(0) {
// new ticker
t = time.NewTicker(opts.RegisterInterval)
}
// return error chan
var ch chan error
Loop:
for {
select {
// register self on interval
case <-t.C:
if err := h.Register(); err != nil {
log.Log("Server register error: ", err)
}
// wait for exit
case ch = <-h.exit:
break Loop
}
}
ch <- ln.Close() ch <- ln.Close()
// deregister // deregister