forked from ardanlabs/gotraining
-
Notifications
You must be signed in to change notification settings - Fork 0
/
request.go
32 lines (25 loc) · 874 Bytes
/
request.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
package main
import (
"log"
"time"
)
// Request represents the message structure we receive for request.
type Request struct {
URI string `json:"uri"`
Post []byte `json:"post"`
Headers map[string]interface{} `json:"headers"`
}
// Response represents the message structure we respond with.
type Response struct {
Status int `json:"status"`
JSON []map[string]interface{} `json:"json"`
}
//==============================================================================
// SendRequest sends a request and waits for the response.
func SendRequest(subject string, req Request) (Response, error) {
log.Printf("SendRequest: Subject[%s] Req[%+v]\n", subject, req)
// Send the request and wait for the response.
var resp Response
err := conn.Request(subject, req, &resp, time.Second)
return resp, err
}