manage http timeout to allow long poll
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
8
http.go
8
http.go
@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
func HttpGetId(url string) (response map[string]string, err error) {
|
||||
@ -25,8 +26,11 @@ func HttpGetId(url string) (response map[string]string, err error) {
|
||||
return srvId, nil
|
||||
}
|
||||
|
||||
func HttpPostMessage(url string, msg []byte) (response []byte, err error) {
|
||||
resp, err := http.Post(url+"/msg",
|
||||
func HttpPostMessage(url string, msg []byte, timeout int) (response []byte, err error) {
|
||||
client := http.Client{
|
||||
Timeout: time.Duration(timeout) * time.Second,
|
||||
}
|
||||
resp, err := client.Post(url+"/msg",
|
||||
"application/octet-stream", bytes.NewBuffer(msg))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
Reference in New Issue
Block a user