LEFT | RIGHT |
1 package api | 1 package api |
2 | 2 |
3 import ( | 3 import ( |
4 "code.google.com/p/go.net/websocket" | 4 "code.google.com/p/go.net/websocket" |
5 "crypto/tls" | 5 "crypto/tls" |
6 "crypto/x509" | 6 "crypto/x509" |
7 "encoding/json" | 7 "encoding/json" |
8 "launchpad.net/juju-core/cert" | 8 "launchpad.net/juju-core/cert" |
9 "launchpad.net/juju-core/log" | 9 "launchpad.net/juju-core/log" |
10 "launchpad.net/juju-core/rpc" | 10 "launchpad.net/juju-core/rpc" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 RequestId uint64 | 96 RequestId uint64 |
97 Type string | 97 Type string |
98 Id string | 98 Id string |
99 Request string | 99 Request string |
100 Params interface{} | 100 Params interface{} |
101 } | 101 } |
102 | 102 |
103 type clientResp struct { | 103 type clientResp struct { |
104 RequestId uint64 | 104 RequestId uint64 |
105 Error string | 105 Error string |
| 106 ErrorCode string |
106 Response json.RawMessage | 107 Response json.RawMessage |
107 } | 108 } |
108 | 109 |
109 type clientCodec struct { | 110 type clientCodec struct { |
110 conn *websocket.Conn | 111 conn *websocket.Conn |
111 resp clientResp | 112 resp clientResp |
112 } | 113 } |
113 | 114 |
114 func (c *clientCodec) Close() error { | 115 func (c *clientCodec) Close() error { |
115 return c.conn.Close() | 116 return c.conn.Close() |
116 } | 117 } |
117 | 118 |
118 func (c *clientCodec) WriteRequest(req *rpc.Request, p interface{}) error { | 119 func (c *clientCodec) WriteRequest(req *rpc.Request, p interface{}) error { |
119 return websocket.JSON.Send(c.conn, &clientReq{ | 120 return websocket.JSON.Send(c.conn, &clientReq{ |
120 RequestId: req.RequestId, | 121 RequestId: req.RequestId, |
121 Type: req.Type, | 122 Type: req.Type, |
122 Id: req.Id, | 123 Id: req.Id, |
123 Request: req.Request, | 124 Request: req.Request, |
124 Params: p, | 125 Params: p, |
125 }) | 126 }) |
126 } | 127 } |
127 | 128 |
128 func (c *clientCodec) ReadResponseHeader(resp *rpc.Response) error { | 129 func (c *clientCodec) ReadResponseHeader(resp *rpc.Response) error { |
129 c.resp = clientResp{} | 130 c.resp = clientResp{} |
130 if err := websocket.JSON.Receive(c.conn, &c.resp); err != nil { | 131 if err := websocket.JSON.Receive(c.conn, &c.resp); err != nil { |
131 return err | 132 return err |
132 } | 133 } |
133 resp.RequestId = c.resp.RequestId | 134 resp.RequestId = c.resp.RequestId |
134 resp.Error = c.resp.Error | 135 resp.Error = c.resp.Error |
| 136 resp.ErrorCode = c.resp.ErrorCode |
135 return nil | 137 return nil |
136 } | 138 } |
137 | 139 |
138 func (c *clientCodec) ReadResponseBody(body interface{}) error { | 140 func (c *clientCodec) ReadResponseBody(body interface{}) error { |
139 if body == nil { | 141 if body == nil { |
140 return nil | 142 return nil |
141 } | 143 } |
142 return json.Unmarshal(c.resp.Response, body) | 144 return json.Unmarshal(c.resp.Response, body) |
143 } | 145 } |
LEFT | RIGHT |