Giter Site home page Giter Site logo

go-http-feeds's Introduction

go-http-feeds

This is an HTTP feeds client written in Go. HTTP feeds is a minimal specification for polling events over HTTP.

Usage

package main

import (
	"context"
	"fmt"
	"time"

	"github.com/korve/go-http-feeds"
)

func main() {
	endpoint := "http://localhost:8080/feed" // the HTTP feed endpoint to poll
	lastEventId := ""                        // empty string to get all events or a specific event id to get events after that 
	pollDelay := 5 * time.Second             // delay between polls
	timeoutDuration := 10 * time.Second      // timeout query parameter value (see https://www.http-feeds.org/#data-model)

	events := make(chan httpfeeds.Event)
	ctx := context.Background()

	// subscribe to events in a separate goroutine 
	go func() {
		client := httpfeeds.NewClient(pollDelay, timeoutDuration)
		err = client.Subscribe(endpoint, lastEventId, events, ctx)
		if err != nil {
			// ... handle error
		}
	}()

	// infinite loop to process events. The loop will receive new events when they are available.
	for event := range events {
		// access event metadata
		fmt.Println(event)

		// access event data
		fmt.Printf("SKU: %s\n", event.Data["sku"])
	}
}

CLI usage

go-http-feeds also comes with a CLI tool to subscribe to HTTP feeds. The CLI tool is available in the dist directory.

Usage: ./dist/httpfeed-subscribe [options] <endpoint>
  <endpoint>: HTTP feed endpoint to subscribe to
  -last-event-id string
        Last event ID received by the client
  -poll-delay int
        Poll delay in milliseconds between each poll to the HTTP endpoint (default 5000)
  -timeout int
        timeout in milliseconds until the server must send a response
  -verbose
        Verbose output

Build

To build the CLI tool, run the following command:

Requirements

  • Go 1.16 or higher
  • GNU Make
make build

This will create a dist directory with the httpfeed-subscribe binary in it.

Installation

To install the CLI tool, run the following command:

go install github.com/korve/go-http-feeds

Now you can run the CLI tool:

go-http-feeds https://example.http-feeds.org/inventory

License

Apache 2.0, see LICENSE

go-http-feeds's People

Contributors

korve avatar

Stargazers

 avatar  avatar

Watchers

 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.