github.com/go-kivik/kivik/v4@v4.3.2/couchdb/cluster.go (about) 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 "net/http" 18 19 "github.com/go-kivik/kivik/v4/couchdb/chttp" 20 "github.com/go-kivik/kivik/v4/driver" 21 ) 22 23 func (c *client) ClusterStatus(ctx context.Context, options driver.Options) (string, error) { 24 opts := map[string]interface{}{} 25 options.Apply(opts) 26 var result struct { 27 State string `json:"state"` 28 } 29 query, err := optionsToParams(opts) 30 if err != nil { 31 return "", err 32 } 33 err = c.DoJSON(ctx, http.MethodGet, "/_cluster_setup", &chttp.Options{Query: query}, &result) 34 return result.State, err 35 } 36 37 func (c *client) ClusterSetup(ctx context.Context, action interface{}) error { 38 options := &chttp.Options{ 39 Body: chttp.EncodeBody(action), 40 } 41 _, err := c.DoError(ctx, http.MethodPost, "/_cluster_setup", options) 42 return err 43 } 44 45 func (c *client) Membership(ctx context.Context) (*driver.ClusterMembership, error) { 46 result := new(driver.ClusterMembership) 47 err := c.DoJSON(ctx, http.MethodGet, "/_membership", nil, &result) 48 return result, err 49 }