...

Source file src/github.com/go-kivik/kivik/v4/x/server/stats.go

Documentation: github.com/go-kivik/kivik/v4/x/server

     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) allDBsStats() httpe.HandlerWithError {
    24  	return httpe.HandlerWithErrorFunc(func(w http.ResponseWriter, r *http.Request) error {
    25  		stats, err := s.client.AllDBsStats(r.Context(), options(r))
    26  		if err != nil {
    27  			return err
    28  		}
    29  		return serveJSON(w, http.StatusOK, stats)
    30  	})
    31  }
    32  
    33  func (s *Server) dbsStats() httpe.HandlerWithError {
    34  	return httpe.HandlerWithErrorFunc(func(w http.ResponseWriter, r *http.Request) error {
    35  		var req struct {
    36  			Keys []string `json:"keys"`
    37  		}
    38  		if err := s.bind(r, &req); err != nil {
    39  			return err
    40  		}
    41  		stats, err := s.client.DBsStats(r.Context(), req.Keys)
    42  		if err != nil {
    43  			return err
    44  		}
    45  		return serveJSON(w, http.StatusOK, stats)
    46  	})
    47  }
    48  

View as plain text