@@ -68,11 +68,11 @@ func getPrimaryNonProdHost(root string) string {
6868}
6969
7070func getEndpointFallbackHosts (endpoint string ) []string {
71- if strings .HasPrefix (endpoint , "nonprod:" ) {
71+ if strings .HasPrefix (endpoint , "nonprod:" ) { // REC2c3
7272 root := strings .TrimPrefix (endpoint , "nonprod:" )
7373 return endpointFallbacks (root , "ably-realtime-nonprod.com" )
7474 }
75- return endpointFallbacks (endpoint , "ably-realtime.com" )
75+ return endpointFallbacks (endpoint , "ably-realtime.com" ) // REC2c4
7676}
7777
7878// endpointFallbacks generates a list of fallback hosts based on the given namespace and root.
@@ -428,6 +428,7 @@ type clientOptions struct {
428428}
429429
430430func (opts * clientOptions ) validate () error {
431+ // REC1b1
431432 if ! empty (opts .Endpoint ) && (! empty (opts .Environment ) || ! empty (opts .RealtimeHost ) || ! empty (opts .RESTHost ) || opts .FallbackHostsUseDefault ) {
432433 err := errors .New ("invalid client option: cannot use endpoint with any of deprecated options environment, realtimeHost, restHost or FallbackHostsUseDefault" )
433434 logger := opts .LogHandler
@@ -507,20 +508,21 @@ func isEndpointFQDN(endpoint string) bool {
507508 return strings .Contains (endpoint , "." ) || strings .Contains (endpoint , "::" ) || endpoint == "localhost"
508509}
509510
510- // REC2
511+ // REC1b
511512func (opts * clientOptions ) getHostnameFromEndpoint () string {
512513 endpoint := opts .Endpoint
513514 if empty (endpoint ) {
514515 return defaultPrimaryHost
515516 }
516- if isEndpointFQDN (endpoint ) {
517+ if isEndpointFQDN (endpoint ) { // REC1b2
517518 return endpoint
518519 }
520+ // REC1b3
519521 if strings .HasPrefix (endpoint , "nonprod:" ) {
520522 root := strings .TrimPrefix (endpoint , "nonprod:" )
521523 return getPrimaryNonProdHost (root )
522524 }
523- return getPrimaryProdHost (endpoint )
525+ return getPrimaryProdHost (endpoint ) // REC1b4
524526}
525527
526528func empty (s string ) bool {
@@ -556,12 +558,12 @@ func (opts *clientOptions) realtimeURL(realtimeHost string) (realtimeUrl string)
556558func (opts * clientOptions ) getFallbackHosts () ([]string , error ) {
557559 if ! empty (opts .Endpoint ) {
558560 if opts .FallbackHosts == nil {
559- if isEndpointFQDN (opts .Endpoint ) {
561+ if isEndpointFQDN (opts .Endpoint ) { // REC2c2
560562 return opts .FallbackHosts , nil
561563 }
562564 return getEndpointFallbackHosts (opts .Endpoint ), nil
563565 }
564- return opts .FallbackHosts , nil
566+ return opts .FallbackHosts , nil //REC2a2
565567 }
566568
567569 logger := opts .LogHandler
@@ -583,7 +585,7 @@ func (opts *clientOptions) getFallbackHosts() ([]string, error) {
583585 if opts .isProductionEnvironment () {
584586 return defaultOptions .FallbackHosts , nil
585587 }
586- return getEndpointFallbackHosts (opts .Environment ), nil
588+ return getEndpointFallbackHosts (opts .Environment ), nil // REC2c5
587589 }
588590 return opts .FallbackHosts , nil
589591}
0 commit comments