solidarity-transport-2 #2

Merged
adelcasse merged 69 commits from solidarity-transport-2 into main 2026-01-05 16:52:36 +00:00
72 changed files with 50 additions and 30 deletions
Showing only changes of commit 46a72e1aef - Show all commits
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
+30 -12
View File
@@ -12,17 +12,41 @@ import (
func (h APIHandler) GetCache(w http.ResponseWriter, r *http.Request) { func (h APIHandler) GetCache(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r) vars := mux.Vars(r)
cacheid := vars["cacheid"] cacheid := vars["cacheid"]
// Use a channel to synchronize the goroutines
ch := make(chan []byte)
// Fetch data from cache asynchronously
go func() {
d, err := h.cache.Get(cacheid) d, err := h.cache.Get(cacheid)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
w.WriteHeader(http.StatusNotFound) w.WriteHeader(http.StatusNotFound)
ch <- nil
return return
} }
var data []any
if val, ok := d.([]any); ok {
data = val
} else {
data = []any{d}
}
j := toJSON(data, w, r)
ch <- j // Signal that the data has been fetched successfully
close(ch)
}()
// wait for the JSON marshaling goroutine to finish
j := <-ch
if j == nil {
return // Stop processing if an error occurred
}
// Send the JSON response to the client
w.WriteHeader(http.StatusOK)
w.Header().Set("Content-Type", "application/json")
w.Write(j)
result := d <-ch
}
if data, ok := d.([]any); ok { func toJSON(data []any, w http.ResponseWriter, r *http.Request) []byte {
result := data
if limitsmin, ok := r.URL.Query()["limits.min"]; ok { if limitsmin, ok := r.URL.Query()["limits.min"]; ok {
min, _ := strconv.Atoi(limitsmin[0]) min, _ := strconv.Atoi(limitsmin[0])
if limitsmax, ok := r.URL.Query()["limits.max"]; ok { if limitsmax, ok := r.URL.Query()["limits.max"]; ok {
@@ -36,16 +60,10 @@ func (h APIHandler) GetCache(w http.ResponseWriter, r *http.Request) {
result = data[min:] result = data[min:]
} }
} }
}
j, err := json.Marshal(result) j, err := json.Marshal(result)
if err != nil { if err != nil {
w.WriteHeader(http.StatusNotFound) w.WriteHeader(http.StatusNotFound)
return return nil
} }
return j
w.WriteHeader(http.StatusOK)
w.Header().Set("Content-Type", "application/json")
w.Write(j)
} }
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
View File
Regular → Executable
View File
View File
View File
View File
View File
Regular → Executable
View File
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Submodule
+1
Submodule themes added at d6de19d8e2
View File
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
+1
View File
@@ -74,6 +74,7 @@ func NewEtcdHandler(cfg *viper.Viper) (*EtcdHandler, error) {
Password: password, Password: password,
DialTimeout: 5 * time.Second, DialTimeout: 5 * time.Second,
}) })
fmt.Println(endpoints,prefix,username,password)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
return nil, err return nil, err
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File