forked from stmcginnis/gofish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
message.go
98 lines (84 loc) · 2.35 KB
/
message.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//
// SPDX-License-Identifier: BSD-3-Clause
//
package common
import (
"encoding/json"
)
// Message is This type shall define a Message as described in the
// Redfish specification.
type Message struct {
Entity
// Message shall contain an optional human readable message.
Message string
// MessageArgs shall contain the message substitution
// arguments for the specific message referenced by the MessageID and
// shall only be included if the MessageID is present. Number and
// integer type arguments shall be converted to strings.
MessageArgs []string
// MessageID shall be a key into message registry as described in the
// Redfish specification.
MessageID string `json:"MessageId"`
// RelatedProperties shall contain an array of JSON
// Pointers indicating the properties described by the message, if
// appropriate for the message.
RelatedProperties []string
// Resolution shall contain an override of the
// Resolution of the message in message registry, if present.
Resolution string
// Severity is The value of this property shall be the severity of the
// error, as defined in the Status section of the Redfish specification.
Severity string
}
// GetMessage will get a Message instance from the service.
func GetMessage(c Client, uri string) (*Message, error) {
resp, err := c.Get(uri)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var message Message
err = json.NewDecoder(resp.Body).Decode(&message)
if err != nil {
return nil, err
}
message.SetClient(c)
return &message, nil
}
// ListReferencedMessages gets the collection of Message from
// a provided reference.
func ListReferencedMessages(c Client, link string) ([]*Message, error) {
var result []*Message
if link == "" {
return result, nil
}
type GetResult struct {
Item *Message
Link string
Error error
}
ch := make(chan GetResult)
collectionError := NewCollectionError()
get := func(link string) {
message, err := GetMessage(c, link)
ch <- GetResult{Item: message, Link: link, Error: err}
}
go func() {
err := CollectList(get, c, link)
if err != nil {
collectionError.Failures[link] = err
}
close(ch)
}()
for r := range ch {
if r.Error != nil {
collectionError.Failures[r.Link] = r.Error
} else {
result = append(result, r.Item)
}
}
if collectionError.Empty() {
return result, nil
}
return result, collectionError
}