...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package server
16
17 import (
18 "net/http"
19
20 "github.com/go-chi/chi/v5"
21 "gitlab.com/flimzy/httpe"
22
23 "github.com/go-kivik/kivik/v4"
24 )
25
26 func (s *Server) getSecurity() httpe.HandlerWithError {
27 return httpe.HandlerWithErrorFunc(func(w http.ResponseWriter, r *http.Request) error {
28 dbName := chi.URLParam(r, "db")
29 security, err := s.client.DB(dbName).Security(r.Context())
30 if err != nil {
31 return err
32 }
33 return serveJSON(w, http.StatusOK, security)
34 })
35 }
36
37 func (s *Server) putSecurity() httpe.HandlerWithError {
38 return httpe.HandlerWithErrorFunc(func(w http.ResponseWriter, r *http.Request) error {
39 dbName := chi.URLParam(r, "db")
40 var security kivik.Security
41 if err := s.bind(r, &security); err != nil {
42 return err
43 }
44 if err := s.client.DB(dbName).SetSecurity(r.Context(), &security); err != nil {
45 return err
46 }
47 return serveJSON(w, http.StatusOK, map[string]bool{
48 "ok": true,
49 })
50 })
51 }
52
View as plain text