client.go

v0.1.0
Doc Versions Source
1
package api
2
3
import (
4
	"net/http"
5
	"time"
6
)
7
8
// Client is a Confluence REST API client for Server/Data Center.
9
type Client struct {
10
	BaseURL    string
11
	Token      string
12
	HTTPClient *http.Client
13
}
14
15
// NewClient creates a new Confluence API client.
16
func NewClient(baseURL, token string) *Client {
17
	return &Client{
18
		BaseURL: baseURL,
19
		Token:   token,
20
		HTTPClient: &http.Client{
21
			Timeout: 30 * time.Second,
22
		},
23
	}
24
}
25
26
func (c *Client) newRequest(method, path string) (*http.Request, error) {
27
	req, err := http.NewRequest(method, c.BaseURL+path, nil)
28
	if err != nil {
29
		return nil, err
30
	}
31
	req.Header.Set("Authorization", "Bearer "+c.Token)
32
	req.Header.Set("Content-Type", "application/json")
33
	req.Header.Set("Accept", "application/json")
34
	return req, nil
35
}
36

Source Files