...

Source file src/github.com/go-kivik/kivik/v4/couchdb/version.go

Documentation: github.com/go-kivik/kivik/v4/couchdb

     1  // Licensed under the Apache License, Version 2.0 (the "License"); you may not
     2  // use this file except in compliance with the License. You may obtain a copy of
     3  // the License at
     4  //
     5  //  http://www.apache.org/licenses/LICENSE-2.0
     6  //
     7  // Unless required by applicable law or agreed to in writing, software
     8  // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
     9  // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
    10  // License for the specific language governing permissions and limitations under
    11  // the License.
    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  // Version returns the server's version info.
    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