forked from ctreminiom/go-atlassian
/
server_impl.go
57 lines (45 loc) · 1.4 KB
/
server_impl.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
package internal
import (
"context"
"fmt"
model "github.com/ctreminiom/go-atlassian/pkg/infra/models"
"github.com/ctreminiom/go-atlassian/service"
"github.com/ctreminiom/go-atlassian/service/jira"
"net/http"
)
func NewServerService(client service.Client, version string) (*ServerService, error) {
if version == "" {
return nil, model.ErrNoVersionProvided
}
return &ServerService{
internalClient: &internalServerServiceImpl{c: client, version: version},
}, nil
}
type ServerService struct {
internalClient jira.ServerConnector
}
// Info returns information about the Jira instance
//
// GET /rest/api/{2-3}/serverInfo
//
// https://docs.go-atlassian.io/jira-software-cloud/server#get-jira-instance-info
func (s *ServerService) Info(ctx context.Context) (*model.ServerInformationScheme, *model.ResponseScheme, error) {
return s.internalClient.Info(ctx)
}
type internalServerServiceImpl struct {
c service.Client
version string
}
func (i *internalServerServiceImpl) Info(ctx context.Context) (*model.ServerInformationScheme, *model.ResponseScheme, error) {
endpoint := fmt.Sprintf("rest/api/%v/serverInfo", i.version)
request, err := i.c.NewRequest(ctx, http.MethodGet, endpoint, nil)
if err != nil {
return nil, nil, err
}
server := new(model.ServerInformationScheme)
response, err := i.c.Call(request, server)
if err != nil {
return nil, response, err
}
return server, response, nil
}