Coder Social home page Coder Social logo

gomet's Introduction

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.

gomet's People

Contributors

didip avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.