-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.go
42 lines (35 loc) · 901 Bytes
/
server.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
package directus
import (
"context"
"fmt"
"net/http"
"github.com/perimeterx/marshmallow"
)
type clientServer struct {
client *Client
}
type ServerInfo struct {
Version string `json:"version"`
Unknown map[string]any `json:"-"`
}
func (server *ServerInfo) UnmarshalJSON(data []byte) error {
values, err := marshmallow.Unmarshal(data, server, marshmallow.WithExcludeKnownFieldsFromMap(true))
if err != nil {
return err
}
server.Unknown = values
return nil
}
func (cr *clientServer) Info(ctx context.Context) (*ServerInfo, error) {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, cr.client.urlf("/server/info"), nil)
if err != nil {
return nil, fmt.Errorf("directus: cannot prepare request: %v", err)
}
reply := struct {
Data *ServerInfo `json:"data"`
}{}
if err := cr.client.sendRequest(req, &reply); err != nil {
return nil, err
}
return reply.Data, nil
}