mirror of
https://github.com/niusmallnan/steve.git
synced 2025-08-23 07:18:33 +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"`
|
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 {
|
type ItemCount struct {
|
||||||
Summary Summary `json:"summary,omitempty"`
|
Summary Summary `json:"summary,omitempty"`
|
||||||
Namespaces map[string]Summary `json:"namespaces,omitempty"`
|
Namespaces map[string]Summary `json:"namespaces,omitempty"`
|
||||||
Revision int `json:"revision,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 {
|
type Store struct {
|
||||||
empty.Store
|
empty.Store
|
||||||
ccache clustercache.ClusterCache
|
ccache clustercache.ClusterCache
|
||||||
@ -157,15 +180,7 @@ func (s *Store) Watch(apiOp *types.APIRequest, schema *types.APISchema, w types.
|
|||||||
counts[schema.ID] = itemCount
|
counts[schema.ID] = itemCount
|
||||||
countsCopy := map[string]ItemCount{}
|
countsCopy := map[string]ItemCount{}
|
||||||
for k, v := range counts {
|
for k, v := range counts {
|
||||||
ns := map[string]Summary{}
|
countsCopy[k] = *v.DeepCopy()
|
||||||
for i, j := range v.Namespaces {
|
|
||||||
ns[i] = j
|
|
||||||
}
|
|
||||||
countsCopy[k] = ItemCount{
|
|
||||||
Summary: v.Summary,
|
|
||||||
Revision: v.Revision,
|
|
||||||
Namespaces: ns,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
result <- types.APIEvent{
|
result <- types.APIEvent{
|
||||||
|
Loading…
Reference in New Issue
Block a user