* WIP: grpc server setup * add register grpc routes * updated go mod * updated grpc for all modules * added pb file for grpc gateway * udpated gw file * added a test for grpc route * fixed conflicts * added grpc server * grpc tests added * cleanup * Fix gateway forward issue * Add godoc * updated tests * fix lint * fix tests * fix tests * fix tests * fixed test * Add grpc headers * Fix error handling * Fix tests - hacky * Fix lint * remove debug logs * Fix review comments * move grpc tests into a separate file * Fix protobuf version * Update x/capability/module.go * Fix godoc * Fix review suggestions * Fix codec * Add query params test for gateway request * Fix gofmt Co-authored-by: anilCSE <anil@vitwit.com> Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
39 lines
725 B
Go
39 lines
725 B
Go
package testutil
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"net/http"
|
|
)
|
|
|
|
// GetRequestWithHeaders defines a wrapper around an HTTP GET request with a provided URL
|
|
// and custom headers
|
|
// An error is returned if the request or reading the body fails.
|
|
func GetRequestWithHeaders(url string, headers map[string]string) ([]byte, error) {
|
|
req, err := http.NewRequest("GET", url, nil)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
client := &http.Client{}
|
|
|
|
for key, value := range headers {
|
|
req.Header.Set(key, value)
|
|
}
|
|
|
|
res, err := client.Do(req)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
body, err := ioutil.ReadAll(res.Body)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if err = res.Body.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return body, nil
|
|
}
|