Commit d1b5320f authored by Dmitry Kniazev's avatar Dmitry Kniazev
Browse files

Merge branch 'close' into 'master'

Ensure response body is closed to prevent resource leak

See merge request osdu/tutorials/osdu-tutorials-go!2
parents ba5e8469 ea8c34e8
......@@ -10,21 +10,22 @@ package main
import (
"bytes"
"encoding/json"
"github.com/Azure/azure-storage-blob-go/azblob"
"github.com/tidwall/gjson"
"golang.org/x/net/context"
"io/ioutil"
"log"
"net/http"
"net/url"
"strconv"
"os"
"strconv"
"github.com/Azure/azure-storage-blob-go/azblob"
"github.com/tidwall/gjson"
"golang.org/x/net/context"
)
var (
// get OSDU API base URL from your Cloud Administrator
clientAPIBaseURL = os.Getenv("OSDU_API_BASE_URL")
// get Client ID and Client Secret from mgmt portal during app registration
// clientAuthBaseURL = os.Getenv("OSDU_AUTH_BASE_URL")
// clientID = os.Getenv("OSDU_CLIENT_ID")
......@@ -136,6 +137,7 @@ func main() {
if err != nil {
log.Printf("HTTP request failed with %s", err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
......
......@@ -10,17 +10,18 @@ import (
"bytes"
"encoding/json"
"fmt"
"github.com/tidwall/gjson"
"io/ioutil"
"log"
"net/http"
"os"
"github.com/tidwall/gjson"
)
var (
// get OSDU API base URL from your Cloud Administrator
clientAPIBaseURL = os.Getenv("OSDU_API_BASE_URL")
// get Client ID and Client Secret from mgmt portal during app registration
//clientAuthBaseURL = os.Getenv("OSDU_AUTH_BASE_URL")
//clientID = os.Getenv("OSDU_CLIENT_ID")
......@@ -107,10 +108,11 @@ func main() {
// call Search API with the well search request JSON
resp, err := http.Post(clientAPIBaseURL+"/indexSearch", "application/json", bytes.NewBuffer(buf))
if err != nil {
log.Printf("HTTP request failed with %s", err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
// parse the results and extract files/srns for each resource type
......@@ -124,7 +126,6 @@ func main() {
fmt.Fprintf(w, string(resJSON))
})
log.Printf("listening on http://%s/", "0.0.0.0:8080")
log.Fatal(http.ListenAndServe("0.0.0.0:8080", nil))
}
......@@ -16,27 +16,28 @@ package main
import (
"bytes"
"encoding/json"
"github.com/Azure/azure-storage-blob-go/azblob"
oidc "github.com/coreos/go-oidc"
"github.com/tidwall/gjson"
"golang.org/x/net/context"
"golang.org/x/oauth2"
"io/ioutil"
"log"
"net/http"
"net/url"
"strconv"
"os"
"strconv"
"github.com/Azure/azure-storage-blob-go/azblob"
oidc "github.com/coreos/go-oidc"
"github.com/tidwall/gjson"
"golang.org/x/net/context"
"golang.org/x/oauth2"
)
var (
// get OSDU API base URL from your Cloud Administrator
clientAPIBaseURL = os.Getenv("OSDU_API_BASE_URL")
// get Client ID and Client Secret from mgmt portal during app registration
clientAuthBaseURL = os.Getenv("OSDU_AUTH_BASE_URL")
clientID = os.Getenv("OSDU_CLIENT_ID")
clientSecret = os.Getenv("OSDU_CLIENT_SECRET")
clientID = os.Getenv("OSDU_CLIENT_ID")
clientSecret = os.Getenv("OSDU_CLIENT_SECRET")
)
/*
......@@ -219,9 +220,9 @@ func main() {
resp := struct {
OAuth2Token *oauth2.Token
UserInfo *oidc.UserInfo
IDToken string `json:"id_token"`
IDToken string `json:"id_token"`
}{oauth2Token, userInfo, IDToken}
data, err := json.MarshalIndent(resp, "", " ")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
......@@ -270,10 +271,11 @@ func main() {
// call Search API with the well search request JSON
resp, err := http.Post(clientAPIBaseURL+"/indexSearch", "application/json", bytes.NewBuffer(buf))
if err != nil {
log.Printf("HTTP request failed with %s", err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
// parse the results and extract files/srns for each resource type
......@@ -317,6 +319,7 @@ func main() {
if err != nil {
log.Printf("HTTP request failed with %s", err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment