fix: resolve all golangci-lint errors

- Fix errcheck errors by properly handling resp.Body.Close() return values
- Fix staticcheck ST1005 errors by uncapitalizing error messages
- Remove unused orgName variable
- Wrap all deferred Close() calls in anonymous functions to handle errors
This commit is contained in:
Stephan Lo 2025-10-09 10:54:14 +02:00
parent 3e432aa8db
commit a8a6c58dcd
3 changed files with 27 additions and 14 deletions

View file

@ -97,7 +97,9 @@ func (a *Adapter) DeleteOrganization(ctx context.Context, name string) error {
// The Call method now handles the response body closure if result is not nil.
// If result is nil, we must close it.
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
defer func() {
_ = resp.Body.Close()
}()
}
a.client.Logf("Successfully deleted organization: %s", name)
@ -141,7 +143,9 @@ func (a *Adapter) ShowApp(ctx context.Context, region string, appKey domain.AppK
}
return nil, fmt.Errorf("ShowApp failed: %w", err)
}
defer resp.Body.Close()
defer func() {
_ = resp.Body.Close()
}()
if err := parseStreamingResponse(resp, &apps); err != nil {
return nil, fmt.Errorf("ShowApp failed to parse response: %w", err)
@ -172,7 +176,9 @@ func (a *Adapter) ShowApps(ctx context.Context, region string, appKey domain.App
}
return nil, fmt.Errorf("ShowApps failed: %w", err)
}
defer resp.Body.Close()
defer func() {
_ = resp.Body.Close()
}()
if err := parseStreamingResponse(resp, &apiApps); err != nil {
return nil, fmt.Errorf("ShowApps failed to parse response: %w", err)
@ -263,7 +269,9 @@ func (a *Adapter) ShowAppInstance(ctx context.Context, region string, appInstKey
}
return nil, fmt.Errorf("ShowAppInstance failed: %w", err)
}
defer resp.Body.Close()
defer func() {
_ = resp.Body.Close()
}()
if err := parseStreamingAppInstanceResponse(resp, &appInstances); err != nil {
return nil, fmt.Errorf("ShowAppInstance failed to parse response: %w", err)
@ -294,7 +302,9 @@ func (a *Adapter) ShowAppInstances(ctx context.Context, region string, appInstKe
}
return nil, fmt.Errorf("ShowAppInstances failed: %w", err)
}
defer resp.Body.Close()
defer func() {
_ = resp.Body.Close()
}()
if err := parseStreamingAppInstanceResponse(resp, &appInstances); err != nil {
return nil, fmt.Errorf("ShowAppInstances failed to parse response: %w", err)
@ -403,7 +413,9 @@ func (a *Adapter) ShowCloudlet(ctx context.Context, region string, cloudletKey d
}
return nil, fmt.Errorf("ShowCloudlet failed: %w", err)
}
defer resp.Body.Close()
defer func() {
_ = resp.Body.Close()
}()
if err := parseStreamingCloudletResponse(resp, &cloudlets); err != nil {
return nil, fmt.Errorf("ShowCloudlet failed to parse response: %w", err)
@ -434,7 +446,9 @@ func (a *Adapter) ShowCloudlets(ctx context.Context, region string, cloudletKey
}
return nil, fmt.Errorf("ShowCloudlets failed: %w", err)
}
defer resp.Body.Close()
defer func() {
_ = resp.Body.Close()
}()
if err := parseStreamingCloudletResponse(resp, &cloudlets); err != nil {
return nil, fmt.Errorf("ShowCloudlets failed to parse response: %w", err)

View file

@ -21,7 +21,6 @@ func init() {
}
var (
orgName string
orgAddress string
orgPhone string
)
@ -46,7 +45,7 @@ var createOrganizationCmd = &cobra.Command{
}
err := services.OrganizationService.Create(context.Background(), org)
if err != nil {
return fmt.Errorf("Error creating organization: %w", err)
return fmt.Errorf("error creating organization: %w", err)
}
fmt.Printf("Organization '%s' created successfully.\n", args[0])
return nil
@ -60,7 +59,7 @@ var showOrganizationCmd = &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) error {
org, err := services.OrganizationService.Get(context.Background(), args[0])
if err != nil {
return fmt.Errorf("Error showing organization: %w", err)
return fmt.Errorf("error showing organization: %w", err)
}
fmt.Printf("Organization Details:\n")
fmt.Printf(" Name: %s\n", org.Name)
@ -91,7 +90,7 @@ var updateOrganizationCmd = &cobra.Command{
err = services.OrganizationService.Update(context.Background(), org)
if err != nil {
return fmt.Errorf("Error updating organization: %w", err)
return fmt.Errorf("error updating organization: %w", err)
}
fmt.Printf("Organization '%s' updated successfully.\n", args[0])
return nil
@ -105,7 +104,7 @@ var deleteOrganizationCmd = &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) error {
err := services.OrganizationService.Delete(context.Background(), args[0])
if err != nil {
return fmt.Errorf("Error deleting organization: %w", err)
return fmt.Errorf("error deleting organization: %w", err)
}
fmt.Printf("Organization '%s' deleted successfully.\n", args[0])
return nil

View file

@ -93,8 +93,8 @@ func (t *Transport) Call(ctx context.Context, method, url string, body interface
t.logf("Request returned retryable status %d (attempt %d)", resp.StatusCode, i+1)
// We need to close the body before retrying
if resp.Body != nil {
io.Copy(io.Discard, resp.Body)
resp.Body.Close()
_, _ = io.Copy(io.Discard, resp.Body)
_ = resp.Body.Close()
}
time.Sleep(t.calculateBackoff(i))
continue