Skip to content

Commit

Permalink
fix: orgs list unmarshall error
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Destructive committed Oct 30, 2023
1 parent 3a66808 commit 425de05
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
20 changes: 10 additions & 10 deletions auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,35 @@ type Tokens struct {
client *client
}

type token struct {
type Token struct {
Name string `json:"name"`
Id string `json:"id"`
Token string `json:"token,omitempty"`
}

type tokenList struct {
Tokens []token `json:"tokens"`
type TokenList struct {
Tokens []Token `json:"tokens"`
}

type tokenValidate struct {
Expiration time.Duration `json:"exp"`
}

func (t *Tokens) List() (*tokenList, error) {
func (t *Tokens) List() (*TokenList, error) {
endpoint := fmt.Sprintf("%s/v1/auth/api-tokens", tursoBaseURL)
resp, err := t.client.tursoAPIrequest(endpoint, http.MethodGet, nil)
if err != nil {
return nil, err
}
var tokens tokenList
if err := json.NewDecoder(resp.Body).Decode(&tokens); err != nil {
return nil, err
}
var tokens TokenList
if err := json.NewDecoder(resp.Body).Decode(&tokens); err != nil {
return nil, err
}
defer resp.Body.Close()
return &tokens, nil
}

func (t *Tokens) Mint(name string) (*token, error) {
func (t *Tokens) Mint(name string) (*Token, error) {
if name == "" {
return nil, fmt.Errorf("token name is required")
}
Expand All @@ -48,7 +48,7 @@ func (t *Tokens) Mint(name string) (*token, error) {
if err != nil {
return nil, err
}
var token token
var token Token
if err := json.NewDecoder(resp.Body).Decode(&token); err != nil {
return nil, err
}
Expand Down
14 changes: 7 additions & 7 deletions organizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ type OrganizationMembers struct {
Username string `json:"username"`
}

type OrganisationList struct {
Orgs []Organization `json:"organizations"`
}

type Database struct {
Name string `json:"name"`
Hostname string `json:"hostname"`
Expand Down Expand Up @@ -61,10 +65,6 @@ type Instance struct {
Name string `json:"name"`
}

type organizationList struct {
Organizations []Organization `json:"organizations"`
}

type organizationMembersList struct {
Members []OrganizationMembers `json:"members"`
}
Expand Down Expand Up @@ -93,14 +93,14 @@ type jwtToken struct {
JWT string `json:"jwt"`
}

func (org *Organizations) List() (*organizationList, error) {
func (org *Organizations) List() (*OrganisationList, error) {
endpoint := fmt.Sprintf("%s/v1/organizations", tursoBaseURL)
resp, err := org.client.tursoAPIrequest(endpoint, http.MethodGet, nil)
if err != nil {
return nil, err
}
var organizations = organizationList{}
err = json.NewDecoder(resp.Body).Decode(&organizations)
var organizations = OrganisationList{}
err = json.NewDecoder(resp.Body).Decode(&organizations.Orgs)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 425de05

Please sign in to comment.