-
Notifications
You must be signed in to change notification settings - Fork 138
Expand file tree
/
Copy pathtools.go
More file actions
31 lines (25 loc) · 716 Bytes
/
tools.go
File metadata and controls
31 lines (25 loc) · 716 Bytes
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
package lhttp
import (
"net/http"
"strings"
)
var (
lhttpHost = "localhost"
lhttpPort = "8081"
)
// Publish message to channel using http
func Publish(channelID []string, command string, header map[string]string, body string) (err error) {
//HTTP Client
//Connect to Terminal Module
//URL:"/message?channel=channelID&channel=channelID&cmd=cmdID
//from default.toml HOST : terminal_host
msg := "LHTTP/1.0 " + command + "\r\n"
msg += "publish:" + strings.Join(channelID, " ") + "\r\n"
for k, v := range header {
msg += k + ":" + v + "\r\n"
}
msg += "\r\n" + body
url := "http://" + lhttpHost + ":" + lhttpPort + "/publish"
_, err = http.Post(url, "text/plain", strings.NewReader(msg))
return
}