@@ -115,7 +115,7 @@ func (c *Connection) Query(q Query) (*Response, *Cursor, error) {
115115 }
116116
117117 // Add token if query is a START/NOREPLY_WAIT
118- if q .Type == p .Query_START || q .Type == p .Query_NOREPLY_WAIT {
118+ if q .Type == p .Query_START || q .Type == p .Query_NOREPLY_WAIT || q . Type == p . Query_SERVER_INFO {
119119 q .Token = c .nextToken ()
120120 if c .opts .Database != "" {
121121 var err error
@@ -154,6 +154,33 @@ func (c *Connection) Query(q Query) (*Response, *Cursor, error) {
154154 }
155155}
156156
157+ type ServerResponse struct {
158+ ID string `gorethink:"id"`
159+ Name string `gorethink:"name"`
160+ }
161+
162+ // Server returns the server name and server UUID being used by a connection.
163+ func (c * Connection ) Server () (ServerResponse , error ) {
164+ var response ServerResponse
165+
166+ _ , cur , err := c .Query (Query {
167+ Type : p .Query_SERVER_INFO ,
168+ })
169+ if err != nil {
170+ return response , err
171+ }
172+
173+ if err = cur .One (& response ); err != nil {
174+ return response , err
175+ }
176+
177+ if err = cur .Close (); err != nil {
178+ return response , err
179+ }
180+
181+ return response , nil
182+ }
183+
157184// sendQuery marshals the Query and sends the JSON to the server.
158185func (c * Connection ) sendQuery (q Query ) error {
159186 // Build query
@@ -231,7 +258,7 @@ func (c *Connection) processResponse(q Query, response *Response) (*Response, *C
231258 return c .processErrorResponse (q , response , RQLCompileError {rqlResponseError {response , q .Term }})
232259 case p .Response_RUNTIME_ERROR :
233260 return c .processErrorResponse (q , response , RQLRuntimeError {rqlResponseError {response , q .Term }})
234- case p .Response_SUCCESS_ATOM :
261+ case p .Response_SUCCESS_ATOM , p . Response_SERVER_INFO :
235262 return c .processAtomResponse (q , response )
236263 case p .Response_SUCCESS_PARTIAL :
237264 return c .processPartialResponse (q , response )
0 commit comments