Skip to content

Latest commit

 

History

History
66 lines (49 loc) · 1.61 KB

read_WS.md

File metadata and controls

66 lines (49 loc) · 1.61 KB

Read with Websocket

Read records using websocket protocol.

GET /logs/{name}/records

Upgrade: websocket
Connection: Upgrade

Params

Name In Description Default
name path Log name.
whence query Allowed values are origin, start and end. origin
position query Whence relative position from which the records are read from. 0

Response

Status: 101 Switching protocol

Code samples

Wsdump (Requires websocket-client package.)

$ wsdump.py ws://localhost:7123/logs/myLog/records

Python (Requires websocket-client package.)

import websocket

ws = websocket.create_connection('ws://localhost:7123/logs/myLog/records')
while True:
  record = ws.recv()
  print(record)

Go (Requires github.com/gorilla/websocket package.)

import (
  "fmt"
  "log"
  "github.com/gorilla/websocket"
)

dialer := websocket.Dialer{}

conn, res, err := dialer.Dial("ws://localhost:7123/logs/myLog/records?whence=start&position=0", nil)
if err != nil {
  log.Fatal(err)
}

for {
    _, record, err := conn.ReadMessage()
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println(string(record))
}