fix: total clients
This commit is contained in:
parent
305f46ccbe
commit
dcc522bc7f
|
@ -61,12 +61,12 @@ func handleClients(r *http.Request, w http.ResponseWriter, s *state) {
|
|||
}
|
||||
|
||||
// Collect necessary information.
|
||||
clients := s.GetClients(reqdata.Offset, reqdata.Limit)
|
||||
clients, totalClients := s.GetClients(reqdata.Offset, reqdata.Limit)
|
||||
|
||||
// Build response data.
|
||||
data, err := json.Marshal(map[string]any{
|
||||
"clients": clients,
|
||||
"total": len(clients),
|
||||
"total": totalClients,
|
||||
})
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("error while generating `clients` API response: %v", err))
|
||||
|
|
|
@ -76,9 +76,9 @@ func (l *clientList) Get(id string) (*client, bool) {
|
|||
return c, ok
|
||||
}
|
||||
|
||||
func (l *clientList) GetPage(offset, limit int) []*client {
|
||||
if offset > len(l.clients) {
|
||||
return []*client{}
|
||||
func (l *clientList) GetPage(offset, limit int) ([]*client, int) {
|
||||
if totalClients := len(l.clients); offset > totalClients {
|
||||
return []*client{}, totalClients
|
||||
}
|
||||
|
||||
// If the remainder of the client list after the offset is
|
||||
|
@ -101,7 +101,7 @@ func (l *clientList) GetPage(offset, limit int) []*client {
|
|||
|
||||
current = current.next
|
||||
}
|
||||
return page
|
||||
return page, len(l.clients)
|
||||
}
|
||||
|
||||
type request struct {
|
||||
|
@ -199,7 +199,7 @@ func (s *state) Prune() {
|
|||
wg.Wait()
|
||||
}
|
||||
|
||||
func (s *state) GetClients(offset, limit int) []*client {
|
||||
func (s *state) GetClients(offset, limit int) ([]*client, int) {
|
||||
s.clientsMutex.Lock()
|
||||
defer s.clientsMutex.Unlock()
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user