Go语言发送 - PubSub (Websocket)
本节内容为Go语言实现GoEasy Rest接口发送消息, 使用时,可参阅Rest接口的详细介绍
Go语言
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
func publishMessage(channel string, content string) {
url := "https://rest-hz.goeasy.io/v2/pubsub/publish"
data := map[string]string{
"appkey": "您的appkey",
"channel": channel,
"content": content,
}
jsonValue, _ := json.Marshal(data)
response, err := http.Post(url, "application/json", bytes.NewBuffer(jsonValue))
if err != nil {
fmt.Printf("The HTTP request failed with error %s", err)
} else {
fmt.Println(response.Status)
}
}
func main() {
publishMessage("test_channel", "Hello, GoEasy!")
}
REST Host
杭州: rest-hz.goeasy.io
新加坡: rest-singapore.goeasy.io