addURLToPool adds an entry to the server pool
(sURL string, implicit, saveTLSName bool)
| 2112 | |
| 2113 | // addURLToPool adds an entry to the server pool |
| 2114 | func (nc *Conn) addURLToPool(sURL string, implicit, saveTLSName bool) error { |
| 2115 | s, err := nc.parseServerURL(sURL, implicit, saveTLSName) |
| 2116 | if err != nil { |
| 2117 | return err |
| 2118 | } |
| 2119 | |
| 2120 | // We don't support mix and match of websocket and non websocket URLs. |
| 2121 | // If this is the first URL, then we accept and switch the global state |
| 2122 | // to websocket. After that, we will know how to reject mixed URLs. |
| 2123 | isWS := isWebsocketScheme(s.URL) |
| 2124 | if len(nc.srvPool) == 0 { |
| 2125 | nc.ws = isWS |
| 2126 | } else if isWS != nc.ws { |
| 2127 | return ErrMixingWebsocketSchemes |
| 2128 | } |
| 2129 | |
| 2130 | nc.srvPool = append(nc.srvPool, s) |
| 2131 | nc.urls[s.URL.Host] = struct{}{} |
| 2132 | return nil |
| 2133 | } |
| 2134 | |
| 2135 | // shufflePool swaps randomly elements in the server pool |
| 2136 | // The `offset` value indicates that the shuffling should start at |