1+ // TODO(adonovan): rename to package codespaces, and codespaces.Client?
12package api
23
34import (
@@ -9,7 +10,6 @@ import (
910 "fmt"
1011 "io/ioutil"
1112 "net/http"
12- "sort"
1313 "strconv"
1414 "strings"
1515)
@@ -29,10 +29,6 @@ type User struct {
2929 Login string `json:"login"`
3030}
3131
32- type errResponse struct {
33- Message string `json:"message"`
34- }
35-
3632func (a * API ) GetUser (ctx context.Context ) (* User , error ) {
3733 req , err := http .NewRequest (http .MethodGet , githubAPI + "/user" , nil )
3834 if err != nil {
@@ -63,7 +59,9 @@ func (a *API) GetUser(ctx context.Context) (*User, error) {
6359}
6460
6561func (a * API ) errorResponse (b []byte ) error {
66- var response errResponse
62+ var response struct {
63+ Message string `json:"message"`
64+ }
6765 if err := json .Unmarshal (b , & response ); err != nil {
6866 return fmt .Errorf ("error unmarshaling error response: %v" , err )
6967 }
@@ -104,14 +102,6 @@ func (a *API) GetRepository(ctx context.Context, nwo string) (*Repository, error
104102 return & response , nil
105103}
106104
107- type Codespaces []* Codespace
108-
109- func (c Codespaces ) SortByCreatedAt () {
110- sort .Slice (c , func (i , j int ) bool {
111- return c [i ].CreatedAt > c [j ].CreatedAt
112- })
113- }
114-
115105type Codespace struct {
116106 Name string `json:"name"`
117107 GUID string `json:"guid"`
@@ -139,7 +129,7 @@ type CodespaceEnvironmentConnection struct {
139129 RelaySAS string `json:"relaySas"`
140130}
141131
142- func (a * API ) ListCodespaces (ctx context.Context , user * User ) (Codespaces , error ) {
132+ func (a * API ) ListCodespaces (ctx context.Context , user * User ) ([] * Codespace , error ) {
143133 req , err := http .NewRequest (
144134 http .MethodGet , githubAPI + "/vscs_internal/user/" + user .Login + "/codespaces" , nil ,
145135 )
@@ -162,9 +152,9 @@ func (a *API) ListCodespaces(ctx context.Context, user *User) (Codespaces, error
162152 return nil , a .errorResponse (b )
163153 }
164154
165- response := struct {
166- Codespaces Codespaces `json:"codespaces"`
167- }{}
155+ var response struct {
156+ Codespaces [] * Codespace `json:"codespaces"`
157+ }
168158 if err := json .Unmarshal (b , & response ); err != nil {
169159 return nil , fmt .Errorf ("error unmarshaling response: %v" , err )
170160 }
@@ -297,14 +287,12 @@ func (a *API) GetCodespaceRegionLocation(ctx context.Context) (string, error) {
297287 return response .Current , nil
298288}
299289
300- type Skus []* Sku
301-
302- type Sku struct {
290+ type SKU struct {
303291 Name string `json:"name"`
304292 DisplayName string `json:"display_name"`
305293}
306294
307- func (a * API ) GetCodespacesSkus (ctx context.Context , user * User , repository * Repository , location string ) (Skus , error ) {
295+ func (a * API ) GetCodespacesSkus (ctx context.Context , user * User , repository * Repository , location string ) ([] * SKU , error ) {
308296 req , err := http .NewRequest (http .MethodGet , githubAPI + "/vscs_internal/user/" + user .Login + "/skus" , nil )
309297 if err != nil {
310298 return nil , fmt .Errorf ("err creating request: %v" , err )
@@ -326,14 +314,14 @@ func (a *API) GetCodespacesSkus(ctx context.Context, user *User, repository *Rep
326314 return nil , fmt .Errorf ("error reading response body: %v" , err )
327315 }
328316
329- response := struct {
330- Skus Skus `json:"skus"`
331- }{}
317+ var response struct {
318+ SKUs [] * SKU `json:"skus"`
319+ }
332320 if err := json .Unmarshal (b , & response ); err != nil {
333321 return nil , fmt .Errorf ("error unmarshaling response: %v" , err )
334322 }
335323
336- return response .Skus , nil
324+ return response .SKUs , nil
337325}
338326
339327type createCodespaceRequest struct {
0 commit comments