]>
Commit | Line | Data |
---|---|---|
15c0b25d AP |
1 | package tfdiags |
2 | ||
3 | import ( | |
4 | "encoding/gob" | |
5 | ) | |
6 | ||
7 | type rpcFriendlyDiag struct { | |
8 | Severity_ Severity | |
9 | Summary_ string | |
10 | Detail_ string | |
11 | Subject_ *SourceRange | |
12 | Context_ *SourceRange | |
13 | } | |
14 | ||
15 | // rpcFriendlyDiag transforms a given diagnostic so that is more friendly to | |
16 | // RPC. | |
17 | // | |
18 | // In particular, it currently returns an object that can be serialized and | |
19 | // later re-inflated using gob. This definition may grow to include other | |
20 | // serializations later. | |
21 | func makeRPCFriendlyDiag(diag Diagnostic) Diagnostic { | |
22 | desc := diag.Description() | |
23 | source := diag.Source() | |
24 | return &rpcFriendlyDiag{ | |
25 | Severity_: diag.Severity(), | |
26 | Summary_: desc.Summary, | |
27 | Detail_: desc.Detail, | |
28 | Subject_: source.Subject, | |
29 | Context_: source.Context, | |
30 | } | |
31 | } | |
32 | ||
33 | func (d *rpcFriendlyDiag) Severity() Severity { | |
34 | return d.Severity_ | |
35 | } | |
36 | ||
37 | func (d *rpcFriendlyDiag) Description() Description { | |
38 | return Description{ | |
39 | Summary: d.Summary_, | |
40 | Detail: d.Detail_, | |
41 | } | |
42 | } | |
43 | ||
44 | func (d *rpcFriendlyDiag) Source() Source { | |
45 | return Source{ | |
46 | Subject: d.Subject_, | |
47 | Context: d.Context_, | |
48 | } | |
49 | } | |
50 | ||
51 | func init() { | |
52 | gob.Register((*rpcFriendlyDiag)(nil)) | |
53 | } |