Skip to content

Instantly share code, notes, and snippets.

@faxm0dem
Created January 28, 2020 07:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save faxm0dem/48ef01ad4e0c2d71c74d30962c62861a to your computer and use it in GitHub Desktop.
Save faxm0dem/48ef01ad4e0c2d71c74d30962c62861a to your computer and use it in GitHub Desktop.
riemann websocket client in Golang
package main
import (
"fmt"
"log"
"golang.org/x/net/websocket"
)
func main() {
origin := "http://localhost/"
url := "ws://ccrtmon:443/index?subscribe=true&query=tagged%20%22syslog%22"
ws, err := websocket.Dial(url, "", origin)
if err != nil {
log.Fatal(err)
}
var msg = make([]byte, 4096)
var n int
for {
n, err = ws.Read(msg)
if err != nil {
log.Fatal(err)
}
// if err := json.Unmarshal(msg[:n]
//fmt.Printf("Received: %s.\n", msg[:n])
fmt.Printf("%s\n", msg[:n])
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment