MCPcopy Create free account
hub / github.com/PasarGuard/node / SyncUser

Method SyncUser

controller/rest/user.go:18–52  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

16)
17
18func (s *Service) SyncUser(w http.ResponseWriter, r *http.Request) {
19 body, err := io.ReadAll(r.Body)
20 if err != nil {
21 http.Error(w, "Failed to read request body", http.StatusBadRequest)
22 return
23 }
24 defer r.Body.Close()
25
26 user := &common.User{}
27 if err = proto.Unmarshal(body, user); err != nil {
28 http.Error(w, "Failed to decode user", http.StatusBadRequest)
29 return
30 }
31
32 if user.GetEmail() == "" {
33 http.Error(w, "email is required", http.StatusBadRequest)
34 return
35 }
36
37 log.Printf("Got user: %v", user.GetEmail())
38
39 if err = s.Backend().SyncUser(r.Context(), user); err != nil {
40 log.Printf("Error syncing user: %v", err)
41 http.Error(w, err.Error(), http.StatusInternalServerError)
42 return
43 }
44
45 response, _ := proto.Marshal(&common.Empty{})
46
47 w.Header().Set("Content-Type", "application/x-protobuf")
48 if _, err = w.Write(response); err != nil {
49 http.Error(w, "Failed to write response", http.StatusInternalServerError)
50 return
51 }
52}
53
54func (s *Service) SyncUsers(w http.ResponseWriter, r *http.Request) {
55 body, err := io.ReadAll(r.Body)

Callers

nothing calls this directly

Implementers 1

Controllercontroller/controller.go

Calls 5

GetEmailMethod · 0.95
ErrorMethod · 0.80
BackendMethod · 0.80
CloseMethod · 0.65
SyncUserMethod · 0.65

Tested by

no test coverage detected