-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetRolls.go
37 lines (33 loc) · 1 KB
/
getRolls.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package main
import (
"encoding/json"
"net/http"
)
// Index
//func getClients(w http.ResponseWriter, r *http.Request) {
// w.Header().Set("Content-Type", "application/json")
//
// // Handle errors in getting clients
// if err := json.NewEncoder(w).Encode(clients); err != nil {
// w.WriteHeader(http.StatusInternalServerError) // Set the status code to 500
// message := "Unable to get clients"
// json.NewEncoder(w).Encode(map[string]string{"error": message})
// return
// }
//}
func getClients(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
// Handle errors in getting clients
err := json.NewEncoder(w).Encode(clients)
if err != nil {
w.WriteHeader(http.StatusInternalServerError) // Set the status code to 500
message := "Unable to get clients"
errorRes := map[string]string{"error": message}
jsonErr := json.NewEncoder(w).Encode(errorRes)
if jsonErr != nil {
http.Error(w, jsonErr.Error(), http.StatusInternalServerError)
return
}
return
}
}