Skip to content

Commit 69d2c0e

Browse files
committed
Added missing spec annotations for endpoint spec in options.go
1 parent 2e6cae4 commit 69d2c0e

File tree

3 files changed

+12
-14
lines changed

3 files changed

+12
-14
lines changed

ably/options.go

+10-8
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ func getPrimaryNonProdHost(root string) string {
6868
}
6969

7070
func 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

430430
func (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
511512
func (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

526528
func empty(s string) bool {
@@ -556,12 +558,12 @@ func (opts *clientOptions) realtimeURL(realtimeHost string) (realtimeUrl string)
556558
func (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
}

ably/realtime_conn.go

-1
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,6 @@ func (c *Connection) connectWith(arg connArgs) (result, error) {
388388

389389
var conn conn
390390
primaryHost := c.opts.getRealtimeHost()
391-
392391
hosts := []string{primaryHost}
393392
fallbackHosts, err := c.opts.getFallbackHosts()
394393
if err != nil {

ablytest/sandbox.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,9 @@ var PresenceFixtures = func() []Presence {
100100
}
101101

102102
type Sandbox struct {
103-
Config *Config
104-
105-
// Endpoint is the hostname to connect to
103+
Config *Config
106104
Endpoint string
107-
108-
client *http.Client
105+
client *http.Client
109106
}
110107

111108
func NewRealtime(opts ...ably.ClientOption) (*Sandbox, *ably.Realtime) {

0 commit comments

Comments
 (0)