Skip to content

Commit

Permalink
chore: errcheck
Browse files Browse the repository at this point in the history
Technical Debt: errcheck

Check the return value to ensure that any issues are caught and handled appropriately.

Signed-off-by: Ryan Johnson <[email protected]>
  • Loading branch information
tenthirtyam committed Jan 22, 2025
1 parent f8e6e50 commit 8a39b99
Show file tree
Hide file tree
Showing 19 changed files with 158 additions and 37 deletions.
12 changes: 10 additions & 2 deletions hcx/activation.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ func PostActivate(c *Client, body ActivateBody) (ActivateBody, error) {
resp := ActivateBody{}

buf := new(bytes.Buffer)
json.NewEncoder(buf).Encode(body)
err := json.NewEncoder(buf).Encode(body)
if err != nil {
fmt.Println(err)
return resp, err
}

req, err := http.NewRequest("POST", fmt.Sprintf("%s:9443/api/admin/global/config/hcx", c.HostURL), buf)
if err != nil {
Expand Down Expand Up @@ -94,7 +98,11 @@ func DeleteActivate(c *Client, body ActivateBody) (ActivateBody, error) {
resp := ActivateBody{}

buf := new(bytes.Buffer)
json.NewEncoder(buf).Encode(body)
err := json.NewEncoder(buf).Encode(body)
if err != nil {
fmt.Println(err)
return resp, err
}

req, err := http.NewRequest("DELETE", fmt.Sprintf("%s:9443/api/admin/global/config/hcx", c.HostURL), buf)
if err != nil {
Expand Down
6 changes: 5 additions & 1 deletion hcx/certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ func InsertCertificate(c *Client, body InsertCertificateBody) (InsertCertificate
resp := InsertCertificateResult{}

buf := new(bytes.Buffer)
json.NewEncoder(buf).Encode(body)
err := json.NewEncoder(buf).Encode(body)
if err != nil {
fmt.Println(err)
return resp, err
}

req, err := http.NewRequest("POST", fmt.Sprintf("%s/hybridity/api/admin/certificates", c.HostURL), buf)
if err != nil {
Expand Down
5 changes: 4 additions & 1 deletion hcx/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ func (c *Client) HcxConnectorAuthenticate() error {

// Check if SSO is ready
var xmlmessage Entries
xml.Unmarshal(body, &xmlmessage)
err = xml.Unmarshal(body, &xmlmessage)
if err != nil {
return err
}

certificate_pb := false
for _, j := range xmlmessage.Entry {
Expand Down
6 changes: 5 additions & 1 deletion hcx/compute_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,11 @@ func InsertComputeProfile(c *Client, body InsertComputeProfileBody) (InsertCompu
resp := InsertComputeProfileResult{}

buf := new(bytes.Buffer)
json.NewEncoder(buf).Encode(body)
err := json.NewEncoder(buf).Encode(body)
if err != nil {
fmt.Println(err)
return resp, err
}

req, err := http.NewRequest("POST", fmt.Sprintf("%s/hybridity/api/interconnect/computeProfiles", c.HostURL), buf)
if err != nil {
Expand Down
6 changes: 5 additions & 1 deletion hcx/l2_extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ func InsertL2Extension(c *Client, body InsertL2ExtensionBody) (InsertL2Extention
resp := InsertL2ExtentionResult{}

buf := new(bytes.Buffer)
json.NewEncoder(buf).Encode(body)
err := json.NewEncoder(buf).Encode(body)
if err != nil {
fmt.Println(err)
return resp, err
}

req, err := http.NewRequest("POST", fmt.Sprintf("%s/hybridity/api/l2Extensions", c.HostURL), buf)
if err != nil {
Expand Down
5 changes: 4 additions & 1 deletion hcx/location.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ type GetLocationResult struct {
func SetLocation(c *Client, body SetLocationBody) error {

buf := new(bytes.Buffer)
json.NewEncoder(buf).Encode(body)
err := json.NewEncoder(buf).Encode(body)
if err != nil {
return err
}

req, err := http.NewRequest("PUT", fmt.Sprintf("%s:9443/api/admin/global/config/location", c.HostURL), buf)
if err != nil {
Expand Down
24 changes: 20 additions & 4 deletions hcx/network_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ func InsertNetworkProfile(c *Client, body NetworkProfileBody) (NetworkProfileRes
resp := NetworkProfileResult{}

buf := new(bytes.Buffer)
json.NewEncoder(buf).Encode(body)
err := json.NewEncoder(buf).Encode(body)
if err != nil {
fmt.Println(err)
return resp, err
}

req, err := http.NewRequest("POST", fmt.Sprintf("%s/admin/hybridity/api/networks", c.HostURL), buf)
if err != nil {
Expand Down Expand Up @@ -111,7 +115,11 @@ func GetNetworkProfile(c *Client, name string) (NetworkProfileBody, error) {
}

buf := new(bytes.Buffer)
json.NewEncoder(buf).Encode(body)
err := json.NewEncoder(buf).Encode(body)
if err != nil {
fmt.Println(err)
return NetworkProfileBody{}, err
}

req, err := http.NewRequest("POST", fmt.Sprintf("%s/hybridity/api/networks?action=queryIpUsage", c.HostURL), buf)
if err != nil {
Expand Down Expand Up @@ -154,7 +162,11 @@ func GetNetworkProfileById(c *Client, id string) (NetworkProfileBody, error) {
}

buf := new(bytes.Buffer)
json.NewEncoder(buf).Encode(body)
err := json.NewEncoder(buf).Encode(body)
if err != nil {
fmt.Println(err)
return NetworkProfileBody{}, err
}

req, err := http.NewRequest("POST", fmt.Sprintf("%s/hybridity/api/networks?action=queryIpUsage", c.HostURL), buf)
if err != nil {
Expand Down Expand Up @@ -219,7 +231,11 @@ func UpdateNetworkProfile(c *Client, body NetworkProfileBody) (NetworkProfileRes
resp := NetworkProfileResult{}

buf := new(bytes.Buffer)
json.NewEncoder(buf).Encode(body)
err := json.NewEncoder(buf).Encode(body)
if err != nil {
fmt.Println(err)
return resp, err
}

req, err := http.NewRequest("PUT", fmt.Sprintf("%s/hybridity/api/networks/%s", c.HostURL, body.ObjectId), buf)
if err != nil {
Expand Down
6 changes: 5 additions & 1 deletion hcx/role_mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ func PutRoleMapping(c *Client, body []RoleMapping) (RoleMappingResult, error) {
resp := RoleMappingResult{}

buf := new(bytes.Buffer)
json.NewEncoder(buf).Encode(body)
err := json.NewEncoder(buf).Encode(body)
if err != nil {
fmt.Println(err)
return resp, err
}

req, err := http.NewRequest("PUT", fmt.Sprintf("%s:9443/api/admin/global/config/roleMappings", c.HostURL), buf)
if err != nil {
Expand Down
6 changes: 5 additions & 1 deletion hcx/service_mesh.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ func InsertServiceMesh(c *Client, body InsertServiceMeshBody) (InsertServiceMesh
resp := InsertServiceMeshResult{}

buf := new(bytes.Buffer)
json.NewEncoder(buf).Encode(body)
err := json.NewEncoder(buf).Encode(body)
if err != nil {
fmt.Println(err)
return resp, err
}

req, err := http.NewRequest("POST", fmt.Sprintf("%s/hybridity/api/interconnect/serviceMesh", c.HostURL), buf)
if err != nil {
Expand Down
6 changes: 5 additions & 1 deletion hcx/site_pairing.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ func InsertSitePairing(c *Client, body RemoteCloudConfigBody) (PostRemoteCloudCo
resp := PostRemoteCloudConfigResult{}

buf := new(bytes.Buffer)
json.NewEncoder(buf).Encode(body)
err := json.NewEncoder(buf).Encode(body)
if err != nil {
fmt.Println(err)
return resp, err
}

req, err := http.NewRequest("POST", fmt.Sprintf("%s/hybridity/api/cloudConfigs", c.HostURL), buf)
if err != nil {
Expand Down
12 changes: 10 additions & 2 deletions hcx/sso.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ func InsertSSO(c *Client, body InsertSSOBody) (InsertSSOResult, error) {
resp := InsertSSOResult{}

buf := new(bytes.Buffer)
json.NewEncoder(buf).Encode(body)
err := json.NewEncoder(buf).Encode(body)
if err != nil {
fmt.Println(err)
return resp, err
}

req, err := http.NewRequest("POST", fmt.Sprintf("%s:9443/api/admin/global/config/lookupservice", c.HostURL), buf)
if err != nil {
Expand Down Expand Up @@ -106,7 +110,11 @@ func UpdateSSO(c *Client, body InsertSSOBody) (InsertSSOResult, error) {
resp := InsertSSOResult{}

buf := new(bytes.Buffer)
json.NewEncoder(buf).Encode(body)
err := json.NewEncoder(buf).Encode(body)
if err != nil {
fmt.Println(err)
return resp, err
}

req, err := http.NewRequest("POST", fmt.Sprintf("%s:9443/api/admin/global/config/lookupservice/%s", c.HostURL, body.Data.Items[0].Config.UUID), buf)
if err != nil {
Expand Down
54 changes: 45 additions & 9 deletions hcx/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,11 @@ func GetLocalContainer(c *Client) (PostResouceContainerListResultDataItem, error
}

buf := new(bytes.Buffer)
json.NewEncoder(buf).Encode(body)
err := json.NewEncoder(buf).Encode(body)
if err != nil {
fmt.Println(err)
return PostResouceContainerListResultDataItem{}, err
}

resp := PostResouceContainerListResult{}

Expand Down Expand Up @@ -342,7 +346,11 @@ func GetRemoteContainer(c *Client) (PostResouceContainerListResultDataItem, erro
}

buf := new(bytes.Buffer)
json.NewEncoder(buf).Encode(body)
err := json.NewEncoder(buf).Encode(body)
if err != nil {
fmt.Println(err)
return PostResouceContainerListResultDataItem{}, err
}

resp := PostResouceContainerListResult{}

Expand Down Expand Up @@ -381,7 +389,11 @@ func GetNetworkBacking(c *Client, endpointid string, network string, network_typ
}

buf := new(bytes.Buffer)
json.NewEncoder(buf).Encode(body)
err := json.NewEncoder(buf).Encode(body)
if err != nil {
fmt.Println(err)
return Dvpg{}, err
}

resp := PostNetworkBackingResult{}

Expand Down Expand Up @@ -461,7 +473,11 @@ func GetVcDatastore(c *Client, datastore_name string, vcuuid string, cluster str
}

buf := new(bytes.Buffer)
json.NewEncoder(buf).Encode(body)
err := json.NewEncoder(buf).Encode(body)
if err != nil {
fmt.Println(err)
return GetVcDatastoreResultDataItem{}, err
}

resp := GetVcDatastoreResult{}

Expand Down Expand Up @@ -506,7 +522,11 @@ func GetVcDvs(c *Client, dvs_name string, vcuuid string, cluster string) (GetVcD
}

buf := new(bytes.Buffer)
json.NewEncoder(buf).Encode(body)
err := json.NewEncoder(buf).Encode(body)
if err != nil {
fmt.Println(err)
return GetVcDvsResultDataItem{}, err
}

resp := GetVcDvsResult{}

Expand Down Expand Up @@ -549,7 +569,11 @@ func GetRemoteCloudList(c *Client) (PostCloudListResult, error) {
}

buf := new(bytes.Buffer)
json.NewEncoder(buf).Encode(body)
err := json.NewEncoder(buf).Encode(body)
if err != nil {
fmt.Println(err)
return PostCloudListResult{}, err
}

resp := PostCloudListResult{}

Expand Down Expand Up @@ -586,7 +610,11 @@ func GetLocalCloudList(c *Client) (PostCloudListResult, error) {
}

buf := new(bytes.Buffer)
json.NewEncoder(buf).Encode(body)
err := json.NewEncoder(buf).Encode(body)
if err != nil {
fmt.Println(err)
return PostCloudListResult{}, err
}

resp := PostCloudListResult{}

Expand Down Expand Up @@ -624,7 +652,11 @@ func GetAppliance(c *Client, endpointId string, service_mesh_id string) (GetAppl
}

buf := new(bytes.Buffer)
json.NewEncoder(buf).Encode(body)
err := json.NewEncoder(buf).Encode(body)
if err != nil {
fmt.Println(err)
return GetApplianceResultItem{}, err
}

resp := GetApplianceResult{}

Expand Down Expand Up @@ -669,7 +701,11 @@ func GetAppliances(c *Client, endpointId string, service_mesh_id string) ([]GetA
}

buf := new(bytes.Buffer)
json.NewEncoder(buf).Encode(body)
err := json.NewEncoder(buf).Encode(body)
if err != nil {
fmt.Println(err)
return []GetApplianceResultItem{}, err
}

resp := GetApplianceResult{}

Expand Down
6 changes: 5 additions & 1 deletion hcx/vcenter.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ func InsertvCenter(c *Client, body InsertvCenterBody) (InsertvCenterResult, erro
resp := InsertvCenterResult{}

buf := new(bytes.Buffer)
json.NewEncoder(buf).Encode(body)
err := json.NewEncoder(buf).Encode(body)
if err != nil {
fmt.Println(err)
return resp, err
}

req, err := http.NewRequest("POST", fmt.Sprintf("%s:9443/api/admin/global/config/vcenter", c.HostURL), buf)
if err != nil {
Expand Down
6 changes: 5 additions & 1 deletion hcx/vmc.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ func HcxCloudAuthenticate(client *Client, token string) error {
}

buf := new(bytes.Buffer)
json.NewEncoder(buf).Encode(body)
err := json.NewEncoder(buf).Encode(body)
if err != nil {
fmt.Println(err)
return err
}

req, err := http.NewRequest("POST", fmt.Sprintf("%s/api/sessions", c.HostURL), buf)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions resource_compute_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,12 @@ func resourceComputeProfileCreate(ctx context.Context, d *schema.ResourceData, m
}

buf := new(bytes.Buffer)
json.NewEncoder(buf).Encode(body)
if err := json.NewEncoder(buf).Encode(body); err != nil {
return diag.FromErr(err)
}

res2, err := hcx.InsertComputeProfile(client, body)

if err != nil {
//return diag.FromErr(errors.New(fmt.Sprintf("%s", buf)))
return diag.FromErr(err)
}

Expand Down
4 changes: 3 additions & 1 deletion resource_l2_extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ func resourceL2ExtensionCreate(ctx context.Context, d *schema.ResourceData, m in
}

buf := new(bytes.Buffer)
json.NewEncoder(buf).Encode(body)
if err := json.NewEncoder(buf).Encode(body); err != nil {
return diag.FromErr(err)
}

res2, err := hcx.InsertL2Extension(client, body)

Expand Down
5 changes: 3 additions & 2 deletions resource_service_mesh.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,13 @@ func resourceServiceMeshCreate(ctx context.Context, d *schema.ResourceData, m in
}

buf := new(bytes.Buffer)
json.NewEncoder(buf).Encode(body)
if err := json.NewEncoder(buf).Encode(body); err != nil {
return diag.FromErr(err)
}

res2, err := hcx.InsertServiceMesh(client, body)

if err != nil {
//return diag.FromErr(errors.New(fmt.Sprintf("%s", buf)))
return diag.FromErr(err)
}

Expand Down
Loading

0 comments on commit 8a39b99

Please sign in to comment.