forked from tears-of-noobs/gojira
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.go
43 lines (36 loc) · 1014 Bytes
/
client.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
43
package gojira
import (
"io"
"io/ioutil"
"net/http"
)
var BaseUrl string
var Username string
var Password string
func execRequest(requestType, requestUrl string,
data io.Reader) (int, []byte) {
client := &http.Client{}
req, err := http.NewRequest(requestType, requestUrl, data)
if err != nil {
panic(err)
}
req.Header.Add("Content-Type", "application/json")
req.SetBasicAuth(Username, Password)
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}
return resp.StatusCode, body
}
// RAW request to Jira API. The function takes full URL of resource,
// type of request (GET, POST, PUT, ...) and body with required params.
// Return values are - responce body and HTTP status code, so you cam manually
// handle the answer from Jira and decode body to you own data type.
func RawRequest(url, requestType string, body io.Reader) (int, []byte) {
return execRequest(requestType, url, body)
}