MCPcopy
hub / github.com/nats-io/nats.go / addURLToPool

Method addURLToPool

nats.go:2114–2133  ·  view source on GitHub ↗

addURLToPool adds an entry to the server pool

(sURL string, implicit, saveTLSName bool)

Source from the content-addressed store, hash-verified

2112
2113// addURLToPool adds an entry to the server pool
2114func (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

Callers 3

TestWSTlsNoConfigFunction · 0.95
setupServerPoolMethod · 0.95
processInfoMethod · 0.95

Calls 2

parseServerURLMethod · 0.95
isWebsocketSchemeFunction · 0.85

Tested by 1

TestWSTlsNoConfigFunction · 0.76