mirror of
https://github.com/tobychui/zoraxy.git
synced 2025-08-06 13:18:30 +02:00
sort list of loaded certificates by ExpireDate
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -101,6 +102,13 @@ func handleListCertificate(w http.ResponseWriter, r *http.Request) {
|
|||||||
results = append(results, &thisCertInfo)
|
results = append(results, &thisCertInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// convert ExpireDate to date object and sort asc
|
||||||
|
sort.Slice(results, func(i, j int) bool {
|
||||||
|
date1, _ := time.Parse("2006-01-02 15:04:05", results[i].ExpireDate)
|
||||||
|
date2, _ := time.Parse("2006-01-02 15:04:05", results[j].ExpireDate)
|
||||||
|
return date1.Before(date2)
|
||||||
|
})
|
||||||
|
|
||||||
js, _ := json.Marshal(results)
|
js, _ := json.Marshal(results)
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
w.Write(js)
|
w.Write(js)
|
||||||
|
Reference in New Issue
Block a user