diff --git a/main.go b/main.go index bbd4781..779bdc2 100644 --- a/main.go +++ b/main.go @@ -2,7 +2,9 @@ package main import ( "context" + "encoding/json" "fmt" + "os" "github.com/Snawoot/windscribe-proxy/wndclient" ) @@ -27,6 +29,17 @@ func main() { if err != nil { panic(err) } - fmt.Printf("wndc=%#v\n", wndc) fmt.Printf("Username = %s\nPassword = %s\n", wndc.ProxyUsername, wndc.ProxyPassword) + + list, err := wndc.ServerList(context.TODO()) + if err != nil { + panic(err) + } + + enc := json.NewEncoder(os.Stdout) + enc.SetIndent("", " ") + err = enc.Encode(list) + if err != nil { + panic(err) + } } diff --git a/wndclient/messages.go b/wndclient/messages.go index fa66874..4cafed2 100644 --- a/wndclient/messages.go +++ b/wndclient/messages.go @@ -40,7 +40,7 @@ type ServerCredentialsResponse struct { } type ServerListResponse struct { - Data *ServerList `json:"data"` + Data ServerList `json:"data"` Info *struct { Revision int `json:"revision"` RevisionHash string `json:"revision_hash"` diff --git a/wndclient/wndclient.go b/wndclient/wndclient.go index 6908ce7..e72bca2 100644 --- a/wndclient/wndclient.go +++ b/wndclient/wndclient.go @@ -203,13 +203,13 @@ func (c *WndClient) ServerCredentials(ctx context.Context) error { return nil } -func (c *WndClient) ServerList(ctx context.Context) error { +func (c *WndClient) ServerList(ctx context.Context) (ServerList, error) { c.Mux.Lock() defer c.Mux.Unlock() requestUrl, err := url.Parse(c.Settings.Endpoints.ServerList) if err != nil { - return err + return nil, err } isPremium := "0" if c.IsPremium { @@ -221,13 +221,13 @@ func (c *WndClient) ServerList(ctx context.Context) error { err = c.getJSON(ctx, requestUrl.String(), &output) if err != nil { - return err + return nil, err } if output.Data == nil { - return ErrNoDataInResponse + return nil, ErrNoDataInResponse } - return nil + return output.Data, nil } func (c *WndClient) postJSON(ctx context.Context, endpoint string, input, output interface{}) error {