-
Notifications
You must be signed in to change notification settings - Fork 0
/
http.go
42 lines (37 loc) · 899 Bytes
/
http.go
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
41
42
// Copyright 2021 Juan Ismael Vasquez <ismael.juan@gmail.com>.
// All rights reserved. Use of this source code is governed by
// a MIT style license that can be found in the LICENSE file.
package cexio
import (
"bytes"
"io"
"io/ioutil"
"log"
"net/http"
)
func readBody(body io.Reader) ([]byte, error) {
result, err := ioutil.ReadAll(body)
if err != nil {
log.Printf(errorReadingResponse, err)
return nil, err
}
return result, nil
}
func getMethod(u string) ([]byte, error) {
res, err := http.Get(u)
if err != nil {
log.Printf(errorHTTPComunication, err)
return nil, err
}
defer res.Body.Close()
return readBody(res.Body)
}
func postMethod(u string, v []byte) ([]byte, error) {
res, err := http.Post(u, postContentType, bytes.NewBuffer(v))
if err != nil {
log.Printf(errorHTTPComunication, err)
return nil, err
}
defer res.Body.Close()
return readBody(res.Body)
}