GitXplorerGitXplorer
d

gomet

public
27 stars
6 forks
0 issues

Commits

List of commits on branch master.
Unverified
5a66a5c3c3b82b90b17eabfc8f75ed909ee7caa3

Use 1 to N fanout channel design. This way I can avoid data-race when http response is flushing.

ddidip committed 7 years ago
Unverified
e879ac9308d02cc051a3b431b2dd2ada3263edf5

Update examples.

ddidip committed 7 years ago
Unverified
0e0dbe87742b9e279b7b24cbeacd5ef6ebe2bb14

Simple longpoll server and client library

ddidip committed 7 years ago

README

The README file for this repository.

GoDoc license

Gomet

Simple HTTP client & server long poll library for Go.

This library is useful if you cannot use websocket. If you can use websocket, you should use github.com/gorilla/websocket

Five Minute Tutorial

See: https://github.com/didip/gomet/tree/master/_examples

cd _examples
go run server.go &
go run client.go &
go run client.go &

curl -H "Content-Type: application/json" -X POST -d '{"message":"hello world"}' http://localhost:8080/

Features

  1. Server-side broadcaster conforms to regular HTTP request handler. This means it can be part of middleware stacks.

  2. Broadcaster is able to send raw binary since every payload is base64 encoded.

  3. Client automatically reconnects when disconnected.

  4. Client's HTTP client and HTTP request are customizable.

    lp, err := gomet.NewClient("https://localhost:8080/stream")
    
    lp.HTTPClient.Transport = &http.Transport{
        TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
    }
    
    req, _ := http.NewRequest("GET", "https://localhost:9090/stream", nil)
    lp.HTTPRequest = req
  5. Define your own error handling for client-side.

    lp, err := gomet.NewClient("http://localhost:8080/stream")
    
    lp.SetOnConnectError(func(err error) {
        println("ERROR: Failed to maintain HTTP connection. URL: " + lp.HTTPRequest.URL.String())
    })
    lp.SetOnReadBytesError(func(err error) {
        println("ERROR: Failed to read payload: " + err.Error())
    })
    lp.SetOnBase64DecodeError(func(err error) {
        println("ERROR: Failed to read payload: " + err.Error())
    })
    lp.SetOnPayloadReceived(func(payloadBytes []byte) {
        println("INFO: Received a line: " + string(payloadBytes))
    })

My other Go libraries

  • Tollbooth: Simple middleware to rate-limit HTTP requests.

  • Stopwatch: A small library to measure latency of things. Useful if you want to report latency data to Graphite.

  • LaborUnion: A worker pool library. It is able to dynamically resize the number of workers.