mirror of
https://github.com/niusmallnan/steve.git
synced 2025-08-22 15:05:48 +00:00
Fix panic in counts
This commit is contained in:
parent
c4fc6869f2
commit
7b434b1338
@ -54,12 +54,35 @@ type Summary struct {
|
||||
Transitioning int `json:"transitioning,omitempty"`
|
||||
}
|
||||
|
||||
func (s *Summary) DeepCopy() *Summary {
|
||||
r := *s
|
||||
if r.States != nil {
|
||||
r.States = map[string]int{}
|
||||
for k := range s.States {
|
||||
r.States[k] = s.States[k]
|
||||
}
|
||||
}
|
||||
return &r
|
||||
}
|
||||
|
||||
type ItemCount struct {
|
||||
Summary Summary `json:"summary,omitempty"`
|
||||
Namespaces map[string]Summary `json:"namespaces,omitempty"`
|
||||
Revision int `json:"revision,omitempty"`
|
||||
}
|
||||
|
||||
func (i *ItemCount) DeepCopy() *ItemCount {
|
||||
r := *i
|
||||
r.Summary = *r.Summary.DeepCopy()
|
||||
if r.Namespaces != nil {
|
||||
r.Namespaces = map[string]Summary{}
|
||||
for k, v := range i.Namespaces {
|
||||
r.Namespaces[k] = *v.DeepCopy()
|
||||
}
|
||||
}
|
||||
return &r
|
||||
}
|
||||
|
||||
type Store struct {
|
||||
empty.Store
|
||||
ccache clustercache.ClusterCache
|
||||
@ -157,15 +180,7 @@ func (s *Store) Watch(apiOp *types.APIRequest, schema *types.APISchema, w types.
|
||||
counts[schema.ID] = itemCount
|
||||
countsCopy := map[string]ItemCount{}
|
||||
for k, v := range counts {
|
||||
ns := map[string]Summary{}
|
||||
for i, j := range v.Namespaces {
|
||||
ns[i] = j
|
||||
}
|
||||
countsCopy[k] = ItemCount{
|
||||
Summary: v.Summary,
|
||||
Revision: v.Revision,
|
||||
Namespaces: ns,
|
||||
}
|
||||
countsCopy[k] = *v.DeepCopy()
|
||||
}
|
||||
|
||||
result <- types.APIEvent{
|
||||
|
Loading…
Reference in New Issue
Block a user