M mconsul/kv.go => mconsul/kv.go +3 -4
@@ 5,7 5,6 @@ import (
"encoding/json"
"errors"
"fmt"
- "io"
"log"
"net/http"
)
@@ 41,12 40,12 @@ func FetchValueFromKvStore(key string) ([]byte, error) {
}
// Defer closing the response body
- defer func(Body io.ReadCloser) {
- err := Body.Close()
+ defer func() {
+ err := resp.Body.Close()
if err != nil {
log.Println("failed to close Consul response body:", err)
}
- }(resp.Body)
+ }()
// Check response status
if resp.StatusCode != http.StatusOK {
M mconsul/services.go => mconsul/services.go +3 -4
@@ 4,7 4,6 @@ import (
"encoding/json"
"errors"
"fmt"
- "io"
"log"
"math/rand"
"net/http"
@@ 45,12 44,12 @@ func FetchServiceAddress(serviceName string) (*FoundService, error) {
}
// Defer closing the response body
- defer func(Body io.ReadCloser) {
- err := Body.Close()
+ defer func() {
+ err := resp.Body.Close()
if err != nil {
log.Println("failed to close Consul response body:", err)
}
- }(resp.Body)
+ }()
// Check response status
if resp.StatusCode != http.StatusOK {
M msecrets/secrets.go => msecrets/secrets.go +2 -2
@@ 59,12 59,12 @@ func (s *Secrets) Read() {
return
}
- defer func(file *os.File) {
+ defer func() {
err := file.Close()
if err != nil {
log.Printf("Failed to close secrets file: %v", err)
}
- }(file)
+ }()
scanner := bufio.NewScanner(file)
linum := 0
M phttpc/http.go => phttpc/http.go +3 -3
@@ 88,12 88,12 @@ func getJson(req *http.Request, endpoint *url.URL, target interface{}) {
panic(err)
}
- defer func(Body io.ReadCloser) {
- err := Body.Close()
+ defer func() {
+ err := resp.Body.Close()
if err != nil {
log.Println("failed to close HTTP response body:", err)
}
- }(resp.Body)
+ }()
// Check response status
if resp.StatusCode != http.StatusOK {