...
1
2
3
4
5
6
7
8
9
10
11
12
13 package couchdb
14
15 import (
16 "context"
17 "encoding/json"
18 "net/http"
19
20 "github.com/go-kivik/kivik/v4/driver"
21 )
22
23
24 func (c *client) Version(ctx context.Context) (*driver.Version, error) {
25 i := &info{}
26 err := c.DoJSON(ctx, http.MethodGet, "/", nil, i)
27 return &driver.Version{
28 Version: i.Version,
29 Vendor: i.Vendor.Name,
30 Features: i.Features,
31 RawResponse: i.Data,
32 }, err
33 }
34
35 type info struct {
36 Data json.RawMessage
37 Version string `json:"version"`
38 Features []string `json:"features"`
39 Vendor struct {
40 Name string `json:"name"`
41 } `json:"vendor"`
42 }
43
44 func (i *info) UnmarshalJSON(data []byte) error {
45 type alias info
46 var a alias
47 if err := json.Unmarshal(data, &a); err != nil {
48 return err
49 }
50 i.Data = data
51 i.Version = a.Version
52 i.Vendor = a.Vendor
53 i.Features = a.Features
54 return nil
55 }
56
View as plain text