|
@@ -0,0 +1,31 @@
|
|
|
+package discourse
|
|
|
+
|
|
|
+import (
|
|
|
+ "bytes"
|
|
|
+ "net/http"
|
|
|
+ "time"
|
|
|
+)
|
|
|
+
|
|
|
+func newGetRequest(config APIConfig, url string) (*http.Request, error) {
|
|
|
+ req, err := http.NewRequest("GET", url, nil)
|
|
|
+ req.Header.Set("Api-Key", config.APIKey)
|
|
|
+ req.Header.Set("Api-Username", config.APIUsername)
|
|
|
+ req.Header.Set("Content-Type", "application/json")
|
|
|
+
|
|
|
+ return req, err
|
|
|
+}
|
|
|
+
|
|
|
+func newPostRequest(config APIConfig, url string, payload []byte) (*http.Request, error) {
|
|
|
+ req, err := http.NewRequest("POST", url, bytes.NewBuffer(payload))
|
|
|
+ req.Header.Set("Api-Key", config.APIKey)
|
|
|
+ req.Header.Set("Api-Username", config.APIUsername)
|
|
|
+ req.Header.Set("Content-Type", "application/json")
|
|
|
+
|
|
|
+ return req, err
|
|
|
+}
|
|
|
+
|
|
|
+func getClient() *http.Client {
|
|
|
+ client := &http.Client{Timeout: time.Second * 5}
|
|
|
+
|
|
|
+ return client
|
|
|
+}
|