Skip to content

Commit

Permalink
lint fixes. go error (gomnd, gosimple, golint)
Browse files Browse the repository at this point in the history
  • Loading branch information
abhimutant committed Dec 13, 2023
1 parent 4730df3 commit 88e5b96
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 42 deletions.
2 changes: 1 addition & 1 deletion nutanix/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,5 @@ type Client struct {
WaitTimeout int64
FoundationCentral *foundation_central.Client
Era *era.Client
NetworkingAPI *networking.NetworkingClient
NetworkingAPI *networking.Client
}
18 changes: 9 additions & 9 deletions nutanix/sdks/v4/networking/networking.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import (
"github.com/terraform-providers/terraform-provider-nutanix/nutanix/client"
)

type NetworkingClient struct {
SubnetApiInstance *api.SubnetApi
VpcApiInstance *api.VpcApi
FloatingIpApiInstance *api.FloatingIpApi
type Client struct {
SubnetAPIInstance *api.SubnetApi
VpcAPIInstance *api.VpcApi
FloatingIPAPIInstance *api.FloatingIpApi
RoutingPolicy *api.RoutingPolicyApi
}

func NewNetworkingClient(credentials client.Credentials) (*NetworkingClient, error) {
func NewNetworkingClient(credentials client.Credentials) (*Client, error) {
var baseClient *network.ApiClient

// check if all required fields are present. Else create an empty client
Expand All @@ -29,10 +29,10 @@ func NewNetworkingClient(credentials client.Credentials) (*NetworkingClient, err
baseClient = pcClient
}

f := &NetworkingClient{
SubnetApiInstance: api.NewSubnetApi(baseClient),
VpcApiInstance: api.NewVpcApi(baseClient),
FloatingIpApiInstance: api.NewFloatingIpApi(baseClient),
f := &Client{
SubnetAPIInstance: api.NewSubnetApi(baseClient),
VpcAPIInstance: api.NewVpcApi(baseClient),
FloatingIPAPIInstance: api.NewFloatingIpApi(baseClient),
RoutingPolicy: api.NewRoutingPolicyApi(baseClient),
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func DatasourceNutanixFloatingIPV4Read(ctx context.Context, d *schema.ResourceDa
conn := meta.(*conns.Client).NetworkingAPI

extID := d.Get("ext_id")
resp, err := conn.FloatingIpApiInstance.GetFloatingIp(utils.StringPtr(extID.(string)))
resp, err := conn.FloatingIPAPIInstance.GetFloatingIp(utils.StringPtr(extID.(string)))
if err != nil {
var errordata map[string]interface{}
e := json.Unmarshal([]byte(err.Error()), &errordata)
Expand Down Expand Up @@ -208,7 +208,7 @@ func DatasourceNutanixFloatingIPV4Read(ctx context.Context, d *schema.ResourceDa
if err := d.Set("vpc", flattenVpc(getResp.Vpc)); err != nil {
return diag.FromErr(err)
}
if err := d.Set("vm_nic", flattenVmNic(getResp.VmNic)); err != nil {
if err := d.Set("vm_nic", flattenVMNic(getResp.VmNic)); err != nil {
return diag.FromErr(err)
}

Expand Down Expand Up @@ -294,7 +294,7 @@ func flattenVpc(pr *import1.Vpc) []map[string]interface{} {
return nil
}

func flattenVmNic(pr *import1.VmNic) []map[string]interface{} {
func flattenVMNic(pr *import1.VmNic) []map[string]interface{} {
if pr != nil {
nics := make([]map[string]interface{}, 0)
nic := make(map[string]interface{})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func DatasourceNutanixFloatingIPsV4() *schema.Resource {
func datasourceNutanixFloatingIPsV4Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*conns.Client).NetworkingAPI

// initialise query params
// initialize query params
var filter, orderBy, expand *string
var page, limit *int

Expand Down Expand Up @@ -78,7 +78,7 @@ func datasourceNutanixFloatingIPsV4Read(ctx context.Context, d *schema.ResourceD
expand = nil
}

resp, err := conn.FloatingIpApiInstance.ListFloatingIp(page, limit, filter, orderBy, expand)
resp, err := conn.FloatingIPAPIInstance.ListFloatingIp(page, limit, filter, orderBy, expand)
if err != nil {
var errordata map[string]interface{}
e := json.Unmarshal([]byte(err.Error()), &errordata)
Expand Down Expand Up @@ -121,7 +121,7 @@ func flattenFloatingIPsEntities(pr []import1.FloatingIp) []map[string]interface{
fip["vpc_reference"] = v.VpcReference
fip["vm_nic_reference"] = v.VmNicReference
fip["vpc"] = flattenVpc(v.Vpc)
fip["vm_nic"] = flattenVmNic(v.VmNic)
fip["vm_nic"] = flattenVMNic(v.VmNic)
fip["links"] = flattenLinks(v.Links)
fip["tenant_id"] = v.TenantId
fip["metadata"] = flattenMetadata(v.Metadata)
Expand Down
27 changes: 15 additions & 12 deletions nutanix/services/v2/networking/data_source_nutanix_pbr_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,13 +463,14 @@ func flattenPortRange(pr []import1.PortRange) []interface{} {

func flattenAddressType(pr *import1.AddressType) string {
if pr != nil {
if *pr == import1.AddressType(2) {
const two, three, four = 2, 3, 4
if *pr == import1.AddressType(two) {
return "ANY"
}
if *pr == import1.AddressType(3) {
if *pr == import1.AddressType(three) {
return "EXTERNAL"
}
if *pr == import1.AddressType(4) {
if *pr == import1.AddressType(four) {
return "SUBNET"
}
}
Expand All @@ -478,16 +479,17 @@ func flattenAddressType(pr *import1.AddressType) string {

func flattenRoutingPolicyActionType(pr *import1.RoutingPolicyActionType) string {
if pr != nil {
if *pr == import1.RoutingPolicyActionType(2) {
const two, three, four, five = 2, 3, 4, 5
if *pr == import1.RoutingPolicyActionType(two) {
return "PERMIT"
}
if *pr == import1.RoutingPolicyActionType(3) {
if *pr == import1.RoutingPolicyActionType(three) {
return "DENY"
}
if *pr == import1.RoutingPolicyActionType(4) {
if *pr == import1.RoutingPolicyActionType(four) {
return "REROUTE"
}
if *pr == import1.RoutingPolicyActionType(5) {
if *pr == import1.RoutingPolicyActionType(five) {
return "FORWARD"
}
}
Expand All @@ -496,19 +498,20 @@ func flattenRoutingPolicyActionType(pr *import1.RoutingPolicyActionType) string

func flattenProtocolType(pr *import1.ProtocolType) string {
if pr != nil {
if *pr == import1.ProtocolType(2) {
const two, three, four, five, six = 2, 3, 4, 5, 6
if *pr == import1.ProtocolType(two) {
return "ANY"
}
if *pr == import1.ProtocolType(3) {
if *pr == import1.ProtocolType(three) {
return "ICMP"
}
if *pr == import1.ProtocolType(4) {
if *pr == import1.ProtocolType(four) {
return "TCP"
}
if *pr == import1.ProtocolType(5) {
if *pr == import1.ProtocolType(five) {
return "UDP"
}
if *pr == import1.ProtocolType(6) {
if *pr == import1.ProtocolType(six) {
return "PROTOCOL_NUMBER"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func DatasourceNutanixPbrsV4() *schema.Resource {
func DatasourceNutanixPbrsV4Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*conns.Client).NetworkingAPI

// initialise query params
// initialize query params
var filter, orderBy *string
var page, limit *int

Expand Down
16 changes: 8 additions & 8 deletions nutanix/services/v2/networking/data_source_nutanix_subnet_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ func dataSourceNutanixSubnetv4Read(ctx context.Context, d *schema.ResourceData,
conn := meta.(*conns.Client).NetworkingAPI

extID := d.Get("ext_id")
resp, err := conn.SubnetApiInstance.GetSubnet(utils.StringPtr(extID.(string)))
resp, err := conn.SubnetAPIInstance.GetSubnet(utils.StringPtr(extID.(string)))
if err != nil {
var errordata map[string]interface{}
e := json.Unmarshal([]byte(err.Error()), &errordata)
Expand Down Expand Up @@ -837,7 +837,7 @@ func flattenDhcpOptions(pr *import1.DhcpOptions) []interface{} {
if pr != nil {
dhcpOps := make([]interface{}, 0)

dhcp := make(map[string]interface{}, 0)
dhcp := make(map[string]interface{})

dhcp["domain_name_servers"] = flattenNtpServer(pr.DomainNameServers)
dhcp["domain_name"] = pr.DomainName
Expand Down Expand Up @@ -874,7 +874,7 @@ func flattenIPv4(pr *config.IPv4Address) []interface{} {
if pr != nil {
ipv4 := make([]interface{}, 0)

ip := make(map[string]interface{}, 0)
ip := make(map[string]interface{})

ip["value"] = pr.Value
ip["prefix_length"] = pr.PrefixLength
Expand All @@ -890,7 +890,7 @@ func flattenIPv6(pr *config.IPv6Address) []interface{} {
if pr != nil {
ipv6 := make([]interface{}, 0)

ip := make(map[string]interface{}, 0)
ip := make(map[string]interface{})

ip["value"] = pr.Value
ip["prefix_length"] = pr.PrefixLength
Expand Down Expand Up @@ -951,7 +951,7 @@ func flattenIPv6Subnet(pr *import1.IPv6Subnet) []interface{} {

func flattenPoolListIPv4(pr []import1.IPv4Pool) []map[string]interface{} {
if len(pr) > 0 {
poolList := make([]map[string]interface{}, 0)
poolList := make([]map[string]interface{}, len(pr))

for k, v := range pr {
pool := make(map[string]interface{})
Expand All @@ -968,7 +968,7 @@ func flattenPoolListIPv4(pr []import1.IPv4Pool) []map[string]interface{} {

func flattenPoolListIPv6(pr []import1.IPv6Pool) []map[string]interface{} {
if len(pr) > 0 {
poolList := make([]map[string]interface{}, 0)
poolList := make([]map[string]interface{}, len(pr))

for k, v := range pr {
pool := make(map[string]interface{})
Expand Down Expand Up @@ -1258,15 +1258,15 @@ func flattenIPUsage(pr *import1.IPUsage) []map[string]interface{} {
ip["num_macs"] = pr.NumMacs
ip["num_free_ips"] = pr.NumFreeIPs
ip["num_assigned_ips"] = pr.NumAssignedIPs
ip["ip_pool_usages"] = flattenIpPoolUsages(pr.IpPoolUsages)
ip["ip_pool_usages"] = flattenIPPoolUsages(pr.IpPoolUsages)

usage = append(usage, ip)
return usage
}
return nil
}

func flattenIpPoolUsages(pr []import1.IPPoolUsage) []map[string]interface{} {
func flattenIPPoolUsages(pr []import1.IPPoolUsage) []map[string]interface{} {
if len(pr) > 0 {
ips := make([]map[string]interface{}, len(pr))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func DataSourceNutanixSubnetsv4() *schema.Resource {
func dataSourceNutanixSubnetsv4Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*conns.Client).NetworkingAPI

// initialise query params
// initialize query params
var filter, orderBy, expand, selects *string
var page, limit *int

Expand Down Expand Up @@ -87,7 +87,7 @@ func dataSourceNutanixSubnetsv4Read(ctx context.Context, d *schema.ResourceData,
selects = nil
}

resp, err := conn.SubnetApiInstance.ListSubnets(page, limit, filter, orderBy, expand, selects)
resp, err := conn.SubnetAPIInstance.ListSubnets(page, limit, filter, orderBy, expand, selects)
if err != nil {
var errordata map[string]interface{}
e := json.Unmarshal([]byte(err.Error()), &errordata)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func dataSourceNutanixVPCv4Read(ctx context.Context, d *schema.ResourceData, met
conn := meta.(*conns.Client).NetworkingAPI

extID := d.Get("ext_id")
resp, err := conn.VpcApiInstance.GetVpc(utils.StringPtr(extID.(string)))
resp, err := conn.VpcAPIInstance.GetVpc(utils.StringPtr(extID.(string)))
if err != nil {
var errordata map[string]interface{}
e := json.Unmarshal([]byte(err.Error()), &errordata)
Expand Down
4 changes: 2 additions & 2 deletions nutanix/services/v2/networking/data_source_nutanix_vpcs_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func DataSourceNutanixVPCsv4() *schema.Resource {
func dataSourceNutanixVPCsv4Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*conns.Client).NetworkingAPI

// initialise query params
// initialize query params
var filter, orderBy, selects *string
var page, limit *int

Expand Down Expand Up @@ -79,7 +79,7 @@ func dataSourceNutanixVPCsv4Read(ctx context.Context, d *schema.ResourceData, me
} else {
selects = nil
}
resp, err := conn.VpcApiInstance.ListVpcs(page, limit, filter, orderBy, selects)
resp, err := conn.VpcAPIInstance.ListVpcs(page, limit, filter, orderBy, selects)
if err != nil {
var errordata map[string]interface{}
e := json.Unmarshal([]byte(err.Error()), &errordata)
Expand Down

0 comments on commit 88e5b96

Please sign in to comment.