-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
57 lines (45 loc) · 1.12 KB
/
config.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//**********************************************************
//
// Copyright (C) 2018 - 2021 J&J Ideenschmiede GmbH <info@jj-ideenschmiede.de>
//
// This file is part of placetel.
// All code may be used. Feel free and maybe code something better.
//
// Author: Jonas Kwiedor
//
//**********************************************************
package goplacetel
import (
"bytes"
"net/http"
)
const (
resourceUrl = "https://api.placetel.de/v2"
)
// Request is to define the request data
type Request struct {
Path, Method, Token string
Body []byte
}
// Send is to send a new request
func (r Request) Send() (*http.Response, error) {
// Set url
url := resourceUrl + r.Path
// Define client
client := &http.Client{}
// Request
request, err := http.NewRequest(r.Method, url, bytes.NewBuffer(r.Body))
if err != nil {
return nil, err
}
// Define header
request.Header.Add("Content-Type", "application/json")
request.Header.Add("Authorization", "Bearer "+r.Token)
// Send request & get response
response, err := client.Do(request)
if err != nil {
return nil, err
}
// Return data
return response, nil
}