mirror of
https://github.com/openfaas/faas.git
synced 2025-06-18 20:16:37 +00:00
Changes from pull request feedback
1. Use httptest.ResponseRecorder instead of custom implementation StringResponseWriter. 2. Remove verbose log line in infohandler Signed-off-by: Edward Wilde <ewilde@gmail.com>
This commit is contained in:
@ -5,6 +5,9 @@ import (
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"io/ioutil"
|
||||
"net/http/httptest"
|
||||
|
||||
"github.com/openfaas/faas/gateway/types"
|
||||
"github.com/openfaas/faas/gateway/version"
|
||||
)
|
||||
@ -12,16 +15,19 @@ import (
|
||||
// MakeInfoHandler is responsible for display component version information
|
||||
func MakeInfoHandler(h http.Handler) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
sw := types.NewStringResponseWriter()
|
||||
h.ServeHTTP(sw, r)
|
||||
responseRecorder := httptest.NewRecorder()
|
||||
h.ServeHTTP(responseRecorder, r)
|
||||
upstreamCall := responseRecorder.Result()
|
||||
|
||||
defer upstreamCall.Body.Close()
|
||||
|
||||
log.Printf("Body: %s", sw.Body())
|
||||
provider := make(map[string]interface{})
|
||||
providerVersion := &types.VersionInfo{}
|
||||
|
||||
err := json.Unmarshal(sw.Body(), &provider)
|
||||
upstreamBody, _ := ioutil.ReadAll(upstreamCall.Body)
|
||||
err := json.Unmarshal(upstreamBody, &provider)
|
||||
if err != nil {
|
||||
log.Printf("Error unmarshalling provider json. Got %s. Error %s\n", string(sw.Body()), err.Error())
|
||||
log.Printf("Error unmarshalling provider json from body %s. Error %s\n", upstreamBody, err.Error())
|
||||
}
|
||||
|
||||
versionMap := provider["version"].(map[string]interface{})
|
||||
|
Reference in New Issue
Block a user