Skip to content

Commit

Permalink
minor revise data structure
Browse files Browse the repository at this point in the history
  • Loading branch information
CMGS committed Feb 3, 2023
1 parent 87caf1c commit 816b66d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion resource3/plugins/binary/types/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type GetNodeResourceInfoRequest struct {

// SetNodeResourceInfoRequest .
type SetNodeResourceInfoRequest struct {
Nodename string `json:"node" mapstructure:"node"`
Nodename string `json:"nodename" mapstructure:"nodename"`
Capacity *plugintypes.NodeResource `json:"capacity" mapstructure:"capacity"`
Usage *plugintypes.NodeResource `json:"usage" mapstructure:"usage"`
}
Expand Down
13 changes: 8 additions & 5 deletions types/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ func (r RawParams) Bool(key string) bool {

// RawParams .
func (r RawParams) RawParams(key string) *RawParams {
n := &RawParams{}
var n *RawParams
if r.IsSet(key) {
if m, ok := r[key].(map[string]interface{}); ok {
n = &RawParams{}
_ = mapstructure.Decode(m, n)
return n
}
}
return n
Expand All @@ -105,11 +105,14 @@ func sliceHelper[T any](r RawParams, key string) []T {
if s, ok := r[key].([]T); ok {
return s
}
res := []T{}
var res []T
if s, ok := r[key].([]interface{}); ok {
for _, v := range s {
res = make([]T, len(s))
for i, v := range s {
if r, ok := v.(T); ok {
res = append(res, r)
res[i] = r
} else {
return nil
}
}
}
Expand Down

0 comments on commit 816b66d

Please sign in to comment.