lux rpc response type
This commit is contained in:
parent
76d49d57b8
commit
1ac1c88644
2 changed files with 69 additions and 6 deletions
|
|
@ -2,16 +2,44 @@ package rpc
|
|||
|
||||
import "encoding/xml"
|
||||
|
||||
type LuxRpcHost struct {
|
||||
XMLName xml.Name `xml:"host"`
|
||||
HostID string `xml:"id,attr"`
|
||||
Hostname string `xml:"hostname,attr"`
|
||||
StateBlob string `xml:"state"`
|
||||
}
|
||||
|
||||
type LuxRpcRequest struct {
|
||||
XMLName xml.Name `xml:"request"`
|
||||
RequestID int `xml:"id,attr"`
|
||||
Controller string `xml:"controller,attr"`
|
||||
Command string `xml:"command,attr"`
|
||||
|
||||
// Commands specific fields
|
||||
Hosts []struct {
|
||||
XMLName xml.Name `xml:"host"`
|
||||
HostID string `xml:"id,attr"`
|
||||
Hostname string `xml:"hostname,attr"`
|
||||
} `xml:"host"`
|
||||
// Command-specific fields
|
||||
Hosts []LuxRpcHost `xml:"host"`
|
||||
}
|
||||
|
||||
type LuxRpcRoute struct {
|
||||
XMLName xml.Name `xml:"route"`
|
||||
Type int `xml:"type,attr"`
|
||||
Target string `xml:"target"`
|
||||
Source string `xml:"source"`
|
||||
Destination string `xml:"destination"`
|
||||
}
|
||||
|
||||
type LuxRpcResponse struct {
|
||||
XMLName xml.Name `xml:"response"`
|
||||
RequestID int `xml:"id,attr"`
|
||||
|
||||
// Command-specific fields
|
||||
KeyStoreBlob string `xml:"keystore"`
|
||||
Routes []LuxRpcRoute `xml:"route"`
|
||||
Hosts []LuxRpcHost `xml:"host"`
|
||||
}
|
||||
|
||||
type LuxRpcError struct {
|
||||
XMLName xml.Name `xml:"error"`
|
||||
RequestID int `xml:"id,attr"`
|
||||
ErrorCode int `xml:"code,attr"`
|
||||
Message string `xml:",innerxml"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,3 +40,38 @@ func TestRequestDecoding(t *testing.T) {
|
|||
}
|
||||
t.Log(request)
|
||||
}
|
||||
|
||||
func TestResponseEncoding(t *testing.T) {
|
||||
xmlBytes, err := xml.Marshal(rpc.LuxRpcResponse{
|
||||
RequestID: 1,
|
||||
KeyStoreBlob: "*base64 keystore*",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(string(xmlBytes))
|
||||
|
||||
xmlBytes, err = xml.Marshal(rpc.LuxRpcResponse{
|
||||
RequestID: 2,
|
||||
Routes: []rpc.LuxRpcRoute{
|
||||
{Type: 1, Target: "1111", Source: "0001", Destination: "127.0.0.1:1234"},
|
||||
{Type: 2, Target: "1112", Source: "0001", Destination: "127.0.0.1:4321"},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(string(xmlBytes))
|
||||
|
||||
xmlBytes, err = xml.Marshal(rpc.LuxRpcResponse{
|
||||
RequestID: 3,
|
||||
Hosts: []rpc.LuxRpcHost{
|
||||
{HostID: "0001", Hostname: "test-host1"},
|
||||
{HostID: "0002", Hostname: "test-host2"},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(string(xmlBytes))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue