Newer
Older
Fabian Seidl
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package managerClient
import (
"fmt"
"io"
"net/http"
"net/url"
"strings"
"code.fbi.h-da.de/danet/quant/qkdnManager-simulator/config"
"github.com/sirupsen/logrus"
)
func buildUrlEncodedRequest(qkdnAppAddress, clientTarget string, formBody url.Values) (*http.Request, error) {
address := formatTargetAddress(qkdnAppAddress, clientTarget)
dataReader := formBody.Encode()
req, err := http.NewRequest(
http.MethodPost,
address,
strings.NewReader(dataReader),
)
if err != nil {
return nil, err
}
// set the content-type header
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
return req, nil
}
func formatTargetAddress(address, resource string) string {
return fmt.Sprintf("http://%s%s%s", address, config.APIPrefix, resource)
}
func checkCloseResponseBodyError(body io.ReadCloser) {
if err := body.Close(); err != nil {
logrus.Error(err)
}
}