Git Product home page Git Product logo

go-pubcontrol's Introduction

go-pubcontrol

Author: Konstantin Bokarius [email protected]

A Go convenience library for publishing messages using the EPCP protocol.

License

go-pubcontrol is offered under the MIT license. See the LICENSE file.

Installation

go get github.com/fanout/go-pubcontrol

go-pubcontrol requires jwt-go 2.2.0. To ensure that the correct version of this dependency is installed use godeps:

go get github.com/tools/godep
cd $GOPATH/src/github.com/fanout/go-pubcontrol
$GOPATH/bin/godep restore

Usage

package main

import "github.com/fanout/go-pubcontrol"
import "encoding/base64"

type HttpResponseFormat struct {
    Body string
}
func (format *HttpResponseFormat) Name() string {
    return "http-response"
}
func (format *HttpResponseFormat) Export() interface{} {
    export := make(map[string]interface{})
    export["body"] = format.Body
    return export
}

func main() {
    // PubControl can be initialized with or without an endpoint configuration.
    // Each endpoint can include optional JWT authentication info.
    // Multiple endpoints can be included in a single configuration.

    // Initialize PubControl with a single endpoint:
    decodedKey, err := base64.StdEncoding.DecodeString("<realmkey>")
    if err != nil {
        panic("Failed to base64 decode the key")
    }
    pub := pubcontrol.NewPubControl([]map[string]interface{} {
            map[string]interface{} {
            "uri": "https://api.fanout.io/realm/<myrealm>",
            "iss": "<myrealm>", 
            "key": decodedKey}})

    // Add new endpoints by applying an endpoint configuration:
    pub.ApplyConfig([]map[string]interface{} {
            map[string]interface{} { "uri": "<myendpoint_uri_1>" },
            map[string]interface{} { "uri": "<myendpoint_uri_2>" }})

    // Remove all configured endpoints:
    pub.RemoveAllClients()

    // Explicitly add an endpoint as a PubControlClient instance:
    client := pubcontrol.NewPubControlClient("<myendpoint_uri>")
    // Optionally set JWT auth: client.SetAuthJwt(<claim>, "<key>")
    // Optionally set basic auth: client.SetAuthBasic("<user>", "<password>")
    pub.AddClient(client)

    // Create an item to publish:
    format := &HttpResponseFormat{Body: "Test Go Publish!!"} 
    item := pubcontrol.NewItem([]pubcontrol.Formatter{format}, "", "")

    // Publish across all configured endpoints:
    err = pub.Publish("<channel>", item)
    if err != nil {
        panic("Publish failed with: " + err.Error())
    }
}

go-pubcontrol's People

Contributors

drichelson avatar jkodumal 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.