Skip to content
This repository has been archived by the owner on Jun 23, 2020. It is now read-only.

Commit

Permalink
Apply review feedback from @jhorwit2
Browse files Browse the repository at this point in the history
  • Loading branch information
prydie committed Oct 23, 2017
1 parent c8d22e1 commit cef79fb
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions pkg/oci/instancemeta/instance_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package instancemeta
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)

Expand All @@ -28,6 +27,7 @@ const (

// InstanceMetadata holds the subset of the instance metadata retrieved from the
// local OCI instance metadata API endpoint.
// https://docs.us-phoenix-1.oraclecloud.com/Content/Compute/Tasks/gettingmetadata.htm
type InstanceMetadata struct {
CompartmentOCID string `json:"compartmentId"`
Region string `json:"region"`
Expand Down Expand Up @@ -62,16 +62,16 @@ func (m *metadataGetter) Get() (*InstanceMetadata, error) {

}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("failed to read instance metadata: %v", err)

if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("metadata endpoint returned status %d; expected 200 OK", resp.StatusCode)
}

metadata := &InstanceMetadata{}
err = json.Unmarshal(body, metadata)
md := &InstanceMetadata{}
err = json.NewDecoder(resp.Body).Decode(md)
if err != nil {
return nil, fmt.Errorf("failed to unmarshal instance metadata: %v", err)
return nil, err
}

return metadata, nil
return md, nil
}

0 comments on commit cef79fb

Please sign in to comment.