44 "fmt"
55 "net/http"
66 "regexp"
7- "time"
87 "unicode/utf8"
98
109 "github.com/rodaine/table"
@@ -53,8 +52,8 @@ type ClosestLocationResponse struct {
5352 Server string
5453}
5554
56- func (c * LocationsClient ) Closest () (string , error ) {
57- r , err := c .client .Get ("https://region.turso.io" , nil )
55+ func (c * LocationsClient ) Closest (regionUrl string ) (string , error ) {
56+ r , err := c .client .Get (regionUrl , nil )
5857 if err != nil {
5958 return "" , fmt .Errorf ("failed to request closest: %s" , err )
6059 }
@@ -73,35 +72,6 @@ func (c *LocationsClient) Closest() (string, error) {
7372 return data .Server , nil
7473}
7574
76- func ProbeLocation (location string ) * time.Duration {
77- client := & http.Client {Timeout : 2 * time .Second }
78- req , err := http .NewRequest ("GET" , "http://region.turso.io:8080/" , nil )
79- if err != nil {
80- return nil
81- }
82- req .Header .Add ("fly-prefer-region" , location )
83-
84- start := time .Now ()
85- r , err := client .Do (req )
86- if err != nil {
87- return nil
88- }
89- defer r .Body .Close ()
90-
91- dur := time .Since (start )
92- if r .StatusCode != http .StatusOK {
93- return nil
94- }
95- data , err := unmarshal [ClosestLocationResponse ](r )
96- if err != nil {
97- return nil
98- }
99- if data .Server != location {
100- return nil
101- }
102- return & dur
103- }
104-
10575func LocationsTable (columns []interface {}) table.Table {
10676 regex := regexp .MustCompile (`\x1b\[[0-9;]*m` )
10777 return table .New (columns ... ).WithWidthFunc (func (s string ) int {
0 commit comments