Golang 在我的直播中超时
Golang is timing out on my stream
我正在尝试编写一个从 http 请求接收数据流的 go 服务器。问题是它一旦收到就超时 {status: connected}
如何保持连接?
func stream() {
t := time.Now()
a := t.Format("15:03")
if a > string("08:30") && a < string("15:00") {
color.Red("Streaming. . .")
config := oauth1.NewConfig("HIDDEN", "HIDDEN")
token := oauth1.NewToken("HIDDEN", "HIDDEN")
httpClient := config.Client(oauth1.NoContext, token)
path := "https://stream.tradeking.com/v1/market/quotes.json?symbols=aapl"
resp, _ := httpClient.Get(path)
fmt.Println(resp)
body, _ := ioutil.ReadAll(resp.Body)
fmt.Printf("Raw Response Body:\n%v\n", string(body))
defer resp.Body.Close()
} else {
color.Red("%s \nMarkets are closed! Please, come back later.", t)
}
}
我在main中调用这个函数。我还收到了类似 header 的内容:
&{200 OK 200 HTTP/1.1 1 1 map[Date:[Mon, 16 Jan 2017 17:45:36 GMT] X-Powered-By:[Express] Server:[cloudflare-ngi
nx] Content-Type:[application/json] Connection:[keep-alive] Set-Cookie:[__cfduid=dcfcf86c79c56e659ce2b1bade3643c
981484588736; expires=Tue, 16-Jan-18 17:45:36 GMT; path=/; domain=.tradeking.com; HttpOnly] Vary:[Accept-Encodin
g] Cf-Ray:[322361d0efd40938-DFW]] 0xc42032e0c0 -1 [chunked] false true map[] 0xc4200d21e0 0xc42040cbb0}
原来市场因 MLK 日休市,因此服务器没有任何响应。
一定超时后,远程服务器超时。
我正在尝试编写一个从 http 请求接收数据流的 go 服务器。问题是它一旦收到就超时 {status: connected}
如何保持连接?
func stream() {
t := time.Now()
a := t.Format("15:03")
if a > string("08:30") && a < string("15:00") {
color.Red("Streaming. . .")
config := oauth1.NewConfig("HIDDEN", "HIDDEN")
token := oauth1.NewToken("HIDDEN", "HIDDEN")
httpClient := config.Client(oauth1.NoContext, token)
path := "https://stream.tradeking.com/v1/market/quotes.json?symbols=aapl"
resp, _ := httpClient.Get(path)
fmt.Println(resp)
body, _ := ioutil.ReadAll(resp.Body)
fmt.Printf("Raw Response Body:\n%v\n", string(body))
defer resp.Body.Close()
} else {
color.Red("%s \nMarkets are closed! Please, come back later.", t)
}
}
我在main中调用这个函数。我还收到了类似 header 的内容:
&{200 OK 200 HTTP/1.1 1 1 map[Date:[Mon, 16 Jan 2017 17:45:36 GMT] X-Powered-By:[Express] Server:[cloudflare-ngi
nx] Content-Type:[application/json] Connection:[keep-alive] Set-Cookie:[__cfduid=dcfcf86c79c56e659ce2b1bade3643c
981484588736; expires=Tue, 16-Jan-18 17:45:36 GMT; path=/; domain=.tradeking.com; HttpOnly] Vary:[Accept-Encodin
g] Cf-Ray:[322361d0efd40938-DFW]] 0xc42032e0c0 -1 [chunked] false true map[] 0xc4200d21e0 0xc42040cbb0}
原来市场因 MLK 日休市,因此服务器没有任何响应。
一定超时后,远程服务器超时。