diff --git a/src/router/functionServiceMap.go b/src/router/functionServiceMap.go index 98997ab9..0f0db7d9 100644 --- a/src/router/functionServiceMap.go +++ b/src/router/functionServiceMap.go @@ -19,6 +19,7 @@ package router import ( "errors" "log" + "net/url" ) type requestType int @@ -30,17 +31,17 @@ const ( ) type functionServiceMapResponse struct { - serviceUrl string + serviceUrl url.URL error } type functionServiceMapRequest struct { function - serviceUrl string + serviceUrl url.URL requestType responseChannel chan<- functionServiceMapResponse } type functionServiceMapEntry struct { - serviceUrl string + serviceUrl url.URL generation uint64 } @@ -85,21 +86,21 @@ func (fmap *functionServiceMap) functionServiceMapWork() { } } -func (fmap *functionServiceMap) lookup(f *function) (string, error) { +func (fmap *functionServiceMap) lookup(f *function) (*url.URL, error) { respChannel := make(chan functionServiceMapResponse) fmap.requestChannel <- &functionServiceMapRequest{ function: *f, requestType: LOOKUP, responseChannel: respChannel } resp := <-respChannel if (resp.error != nil) { - return "", resp.error + return nil, resp.error } else { - return resp.serviceUrl, nil + return &resp.serviceUrl, nil } } -func (fmap *functionServiceMap) assign(f *function, serviceUrl string) { +func (fmap *functionServiceMap) assign(f *function, serviceUrl *url.URL) { fmap.requestChannel <- - &functionServiceMapRequest{ function: *f, serviceUrl: serviceUrl, requestType: ASSIGN } + &functionServiceMapRequest{ function: *f, serviceUrl: *serviceUrl, requestType: ASSIGN } } func (fmap *functionServiceMap) nextGen() { diff --git a/src/router/functionServiceMap_test.go b/src/router/functionServiceMap_test.go index b5c9897b..6aa420c7 100644 --- a/src/router/functionServiceMap_test.go +++ b/src/router/functionServiceMap_test.go @@ -18,21 +18,25 @@ package router import ( "testing" + "net/url" ) func TestFunctionServiceMap(t *testing.T) { m := makeFunctionServiceMap() fn := &function{ name: "foo", uid: "012" } - url := "/foo012" + u, err := url.Parse("/foo012") + if (err != nil) { + t.Errorf("can't parse url") + } - m.assign(fn, url) + m.assign(fn, u) v, err := m.lookup(fn) if (err != nil) { - t.Errorf("Lookup error: %s", err) + t.Errorf("Lookup error: %v", err) } - if (v != url) { - t.Errorf("Expected %s, got %s", url, v) + if (*v != *u) { + t.Errorf("Expected %#v, got %#v", u, v) } fn.name = "bar"