Skip to content
/ gomet Public

Simple HTTP client & server long poll library for Go

License

Notifications You must be signed in to change notification settings

didip/gomet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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:https://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:https://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.

About

Simple HTTP client & server long poll library for Go

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages