chirp

package module
v0.0.0-...-f4794cf Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 16, 2016 License: MIT Imports: 14 Imported by: 0

README

GoDoc Go Report Card

Chirp (Go)

Chirp is a network service discovery protocol. In short, it's a simpler and more reliable alternative to mDNS/Bonjour. For more information about the protocol and libraries for different languages, see the official Chirp homepage.

Installation

Install with:

go get github.com/arashpayan/chirp

Usage

Publishing a service:

// Create and start a publisher
publisher, _ := chirp.NewPublisher("tld.domain.service").Start()

// Stop the publisher when you're done
publisher.Stop()

// Optionally, you can specify a map with arbitrary
// keys and values that will be broadcasted along
// with your service.
payload := map[string]interface{}{
    "port": 22,
    "display_name": "My Awesome SSH"
    "anotherkey": []{"fizz", "buzz"},
    "andanotherkey": map[string]{}{
        "something": "blah",
        "else": "haha"
    }
}
publisher, _ := chirp.NewPublisher("tld.domain.service").
                      SetPayload(payload).
                      Start()

Listening for services:

// Start the listener. You can pass '*' for the service name
// to listen for all services.
listener, _ := chirp.NewListener("service.to.listen.for")

// Start a goroutine to handle all the incoming service events
for event := range listener.ServiceEvents {
    switch se.EventType {
        case chirp.ServicePublished:
            // handle a newly found service
        case chirp.ServiceUpdated:
            // one of the IPs (v4 or v6) was updated on the service
        case chirp.ServiceRemoved:
            // the service is no longer being published
    }
}

// Stop the listener when you're done
listener.Stop()

Documentation

Index

Constants

View Source
const (
	ServicePublished EventType = "service_published"
	ServiceUpdated             = "service_updated"
	ServiceRemoved             = "service_removed"
)

events

View Source
const MaxPayloadBytes = 32 * 1024

MaxPayloadBytes is the maximum allowed size of a payload when serialized into JSON

Variables

This section is empty.

Functions

func ValidateServiceName

func ValidateServiceName(name string) error

ValidateServiceName ...

Types

type EventType

type EventType string

EventType ...

type Listener

type Listener struct {
	ServiceEvents <-chan ServiceEvent
	// contains filtered or unexported fields
}

Listener ...

func NewListener

func NewListener(serviceName string) (*Listener, error)

NewListener ...

func (*Listener) Stop

func (l *Listener) Stop()

Stop listening. The Listener can't be reused after this is called.

type Publisher

type Publisher struct {
	// contains filtered or unexported fields
}

Publisher ...

func NewPublisher

func NewPublisher(service string) *Publisher

NewPublisher ...

func (*Publisher) SetPayload

func (p *Publisher) SetPayload(payload map[string]interface{}) *Publisher

SetPayload ...

func (*Publisher) SetTTL

func (p *Publisher) SetTTL(ttl uint) *Publisher

SetTTL ..

func (*Publisher) Start

func (p *Publisher) Start() (*Publisher, error)

Start ...

func (*Publisher) Stop

func (p *Publisher) Stop()

Stop ...

type Service

type Service struct {
	Name    string
	Payload map[string]interface{}
	// contains filtered or unexported fields
}

Service ...

func (Service) IPv4

func (s Service) IPv4() net.IP

IPv4 returns the IPv4 address of the service publisher. If there is no v4 IP associated with the publisher, returns nil.

func (Service) IPv6

func (s Service) IPv6() net.IP

IPv6 returns the IPv6 address of the service publisher. If there is no v6 IP associated with the publisher, returns nil.

func (Service) String

func (s Service) String() string

type ServiceEvent

type ServiceEvent struct {
	Service
	EventType
}

ServiceEvent ...

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL