-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvegeta.go
More file actions
60 lines (51 loc) · 1.11 KB
/
vegeta.go
File metadata and controls
60 lines (51 loc) · 1.11 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package vegeta
import (
"io/ioutil"
"log"
"net/http"
)
// Handler object handles the requests to the API
type Handler struct {
Token string
User string
Password string
Headers map[string]string
Request http.Request
}
func (h *Handler) SetUsername(u string) {
h.User = u
}
func (h *Handler) SetPassword(p string) {
h.Password = p
}
//GetRequest is used to make requests using the get method
func (h *Handler) GetRequest(url string) (output []byte, err error) {
var client http.Client
request, err := http.NewRequest("GET", url, nil)
if err != nil {
log.Print(err)
return
}
for key, value := range h.Headers {
request.Header.Add(key, value)
}
response, err := client.Do(request)
if err != nil {
log.Print(err)
return
}
output, err = ioutil.ReadAll(response.Body)
if err != nil {
log.Print(err)
return
}
return
}
//SetHeaders is used to set the HTTP headers
func (h *Handler) SetHeaders(headers map[string]string) {
h.Headers = headers
}
//NewHandler is the constructor that initializes the map object
func NewHandler() *Handler {
return &Handler{Headers: make(map[string]string)}
}