@@ -33,8 +33,9 @@ import (
3333)
3434
3535var (
36- errRpnStateless = errors .New ("rpn has no state or config" )
37- errRpnUpdateless = errors .New ("rpn cannot be updated only registered" )
36+ errRpnCountryless = errors .New ("rpn is not multi-country" )
37+ errRpnStateless = errors .New ("rpn has no state or config" )
38+ errRpnUpdateless = errors .New ("rpn cannot be updated only registered" )
3839)
3940
4041type RpnAcc interface {
@@ -67,8 +68,8 @@ func (RpnMultiCountry) MultiCountry() bool { return true }
6768
6869type RpnCountryless struct {}
6970
70- func (c RpnCountryless ) MultiCountry () bool { return false }
71- func (c RpnCountryless ) Locations () []x. RpnServer { return nil }
71+ func (c RpnCountryless ) MultiCountry () bool { return false }
72+ func (c RpnCountryless ) Locations () (x. RpnServers , error ) { return nil , errRpnCountryless }
7273
7374type RpnStateless struct {
7475 RpnUpdateless
@@ -81,6 +82,34 @@ type RpnUpdateless struct{}
8182
8283func (RpnUpdateless ) Update () (* x.Gobyte , error ) { return nil , errRpnUpdateless }
8384
85+ type RpnMultiCountryServers struct {
86+ all []x.RpnServer
87+ }
88+
89+ var _ x.RpnServers = (* RpnMultiCountryServers )(nil )
90+
91+ func (s * RpnMultiCountryServers ) Get (i int ) (* x.RpnServer , error ) {
92+ if i < 0 || i >= len (s .all ) {
93+ return nil , fmt .Errorf ("rpn: %d out of range [0, %d)" , i , len (s .all ))
94+ }
95+ return & s .all [i ], nil
96+ }
97+
98+ func (s * RpnMultiCountryServers ) Len () int {
99+ return len (s .all )
100+ }
101+
102+ func (s * RpnMultiCountryServers ) Json () (* x.Gobyte , error ) {
103+ if s == nil || len (s .all ) <= 0 {
104+ return nil , fmt .Errorf ("rpn: no servers" )
105+ }
106+ b , err := json .Marshal (s .all )
107+ if err != nil {
108+ return nil , fmt .Errorf ("rpn: marshal servers: %w" , err )
109+ }
110+ return x .BytesOf (b ), nil
111+ }
112+
84113type WarpClient struct {
85114 RpnCountryless
86115 RpnUpdateless
0 commit comments