@@ -108,9 +108,9 @@ func (w *worker) start() {
108108 }
109109}
110110
111- func (w * worker ) sortOutput () []output {
111+ func (w * worker ) sortOutput (em map [ string ]config. Endpoint ) []output {
112112 m := make (map [string ]output )
113- for i := 0 ; i < w .size (region ); i ++ {
113+ for i := 0 ; i < w .size (em , region ); i ++ {
114114 o := <- w .outputs
115115
116116 a := m [o .region ]
@@ -133,17 +133,17 @@ func (w *worker) sortOutput() []output {
133133 return all
134134}
135135
136- func (w * worker ) reportAll () {
136+ func (w * worker ) reportAll (em map [ string ]config. Endpoint ) {
137137 w .inputs = make (chan input , concurrency )
138- w .outputs = make (chan output , w .size (region ))
138+ w .outputs = make (chan output , w .size (em , region ))
139139 for i := 0 ; i < number ; i ++ {
140- for r , e := range config . AllEndpoints {
140+ for r , e := range em {
141141 w .inputs <- input {region : r , endpoint : e .URL }
142142 }
143143 }
144144 close (w .inputs )
145145
146- sorted := w .sortOutput ()
146+ sorted := w .sortOutput (em )
147147 tr := tabwriter .NewWriter (os .Stdout , 3 , 2 , 2 , ' ' , 0 )
148148 for i , a := range sorted {
149149 fmt .Fprintf (tr , "%2d.\t [%v]\t %v" , i + 1 , a .region , a .median ())
@@ -155,59 +155,58 @@ func (w *worker) reportAll() {
155155 tr .Flush ()
156156}
157157
158- func (w * worker ) reportCSV () {
158+ func (w * worker ) reportCSV (em map [ string ]config. Endpoint ) {
159159 w .inputs = make (chan input , concurrency )
160- w .outputs = make (chan output , w .size (region ))
160+ w .outputs = make (chan output , w .size (em , region ))
161161 for i := 0 ; i < number ; i ++ {
162- for r , e := range config . AllEndpoints {
162+ for r , e := range em {
163163 w .inputs <- input {region : r , endpoint : e .URL }
164164 }
165165 }
166166 close (w .inputs )
167167
168- sorted := w .sortOutput ()
168+ sorted := w .sortOutput (em )
169169 fmt .Println ("region,latency_ns,errors" )
170170 for _ , a := range sorted {
171171 fmt .Printf ("%v,%v,%v\n " , a .region , a .median ().Nanoseconds (), a .errors )
172172 }
173173}
174174
175- func (w * worker ) reportTop () {
175+ func (w * worker ) reportTop (em map [ string ]config. Endpoint ) {
176176 w .inputs = make (chan input , concurrency )
177- w .outputs = make (chan output , w .size (region ))
177+ w .outputs = make (chan output , w .size (em , region ))
178178 for i := 0 ; i < number ; i ++ {
179- for r , e := range config . AllEndpoints {
179+ for r , e := range em {
180180 w .inputs <- input {region : r , endpoint : e .URL }
181181 }
182182 }
183183 close (w .inputs )
184184
185- sorted := w .sortOutput ()
185+ sorted := w .sortOutput (em )
186186 t := sorted [0 ].region
187187 if t == "global" {
188188 t = sorted [1 ].region
189189 }
190- fmt .Println (t )
190+ fmt .Println (t )
191191 return
192192}
193193
194- func (w * worker ) reportRegion (region string ) {
194+ func (w * worker ) reportRegion (em map [ string ]config. Endpoint , region string ) {
195195 w .inputs = make (chan input , concurrency )
196- w .outputs = make (chan output , w .size (region ))
196+ w .outputs = make (chan output , w .size (em , region ))
197197 for i := 0 ; i < number ; i ++ {
198- e , _ := config . AllEndpoints [region ]
198+ e , _ := em [region ]
199199 w .inputs <- input {region : region , endpoint : e .URL }
200200 }
201201 close (w .inputs )
202202
203- sorted := w .sortOutput ()
203+ sorted := w .sortOutput (em )
204204 fmt .Println (sorted [0 ].median ())
205-
206205}
207206
208- func (w * worker ) size (region string ) int {
207+ func (w * worker ) size (em map [ string ]config. Endpoint , region string ) int {
209208 if region != "" {
210209 return number
211210 }
212- return number * len (config . AllEndpoints )
211+ return number * len (em )
213212}
0 commit comments