Skip to content

Commit

Permalink
Refactor subnet resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
ducvm29 committed Sep 9, 2024
1 parent 5952bfe commit 34cccb3
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions fptcloud/subnet/subnetClient.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package fptcloud_subnet

import (
"encoding/json"
"terraform-provider-fptcloud/commons"
)

type SubnetClient struct {
*commons.Client
}

func NewSubnetClient(client *commons.Client) *SubnetClient {
return &SubnetClient{client}
}

func (c *SubnetClient) ListNetworks(vpcId string) ([]SubnetData, error) {
url := commons.ApiPath.Subnet(vpcId)
res, err := c.SendGetRequest(url)

if err != nil {
return nil, err
}

var r subnetResponse
if err = json.Unmarshal(res, &r); err != nil {
return nil, err
}

return r.Data, nil
}

type SubnetData struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
DefaultGateway string `json:"defaultGateway"`
SubnetPrefixLength int `json:"subnetPrefixLength"`
NetworkID interface{} `json:"network_id"`
NetworkType string `json:"networkType"`
}

type subnetResponse struct {
Data []SubnetData `json:"data"`
}

0 comments on commit 34cccb3

Please sign in to comment.