github.com/go-kivik/kivik/v4@v4.3.2/x/server/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 //go:build !js 14 15 package server 16 17 import ( 18 "net/http" 19 20 "gitlab.com/flimzy/httpe" 21 ) 22 23 func (s *Server) clusterStatus() httpe.HandlerWithError { 24 return httpe.HandlerWithErrorFunc(func(w http.ResponseWriter, r *http.Request) error { 25 status, err := s.client.ClusterStatus(r.Context(), options(r)) 26 if err != nil { 27 return err 28 } 29 return serveJSON(w, http.StatusOK, map[string]string{ 30 "state": status, 31 }) 32 }) 33 } 34 35 func (s *Server) clusterSetup() httpe.HandlerWithError { 36 return httpe.HandlerWithErrorFunc(func(w http.ResponseWriter, r *http.Request) error { 37 var req struct { 38 Action string `json:"action"` 39 } 40 if err := s.bindJSON(r, &req); err != nil { 41 return err 42 } 43 if err := s.client.ClusterSetup(r.Context(), req.Action); err != nil { 44 return err 45 } 46 return serveJSON(w, http.StatusOK, map[string]bool{ 47 "ok": true, 48 }) 49 }) 50 }