Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(971)

Unified Diff: state/api/apiclient.go

Issue 103820044: Use localhost only if pressent for opening state
Patch Set: Use localhost only if pressent for opening state Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: state/api/apiclient.go
=== modified file 'state/api/apiclient.go'
--- state/api/apiclient.go 2014-05-30 16:12:13 +0000
+++ state/api/apiclient.go 2014-06-02 20:54:43 +0000
@@ -8,7 +8,6 @@
"crypto/x509"
"fmt"
"io"
- "sort"
"strings"
"time"
@@ -110,18 +109,6 @@
}
}
-type LocalFirst []string
-
-func (l LocalFirst) Len() int {
- return len(l)
-}
-func (l LocalFirst) Swap(i, j int) {
- l[i], l[j] = l[j], l[i]
-}
-func (l LocalFirst) Less(i, j int) bool {
- return strings.HasPrefix(l[i], "localhost") && !strings.HasPrefix(l[j], "localhost")
-}
-
func Open(info *Info, opts DialOpts) (*State, error) {
if len(info.Addrs) == 0 {
return nil, fmt.Errorf("no API addresses to connect to")
@@ -137,8 +124,15 @@
try := parallel.NewTry(0, nil)
defer try.Kill()
var addrs []string
- addrs = append(addrs, info.Addrs...)
- sort.Sort(LocalFirst(addrs))
+ for _, addr := range info.Addrs {
+ if strings.HasPrefix(addr, "localhost:") {
+ addrs = append(addrs, addr)
+ break
+ }
+ }
+ if len(addrs) == 0 {
+ addrs = info.Addrs
+ }
for _, addr := range addrs {
err := dialWebsocket(addr, opts, pool, try)
if err == parallel.ErrStopped {
« no previous file with comments | « [revision details] ('k') | state/api/apiclient_test.go » ('j') | state/api/apiclient_test.go » ('J')

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b