watcher

package
v0.0.0-...-4686cbe Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2020 License: MIT Imports: 7 Imported by: 0

README

Watcher

Watcher is a package leveraging fsnotify to watch events in an OnionTree repository and emitting them to a channel.

Example

package main

import (
    "fmt"
    "context"
    "github.com/oniontree-org/go-oniontree"
    "github.com/oniontree-org/go-oniontree/watcher"
)

func main() {
    ot, err := oniontree.Open(".")
    if err != nil {
        panic(err)
    }
    w := watcher.NewWatcher(ot)

    eventCh := make(chan watcher.Event)

    go func(){
        if err := w.Watch(context.TODO(), eventCh); err != nil {
            panic(err)
        }
    }()

    for {
        select {
        case e := <-eventCh:
            switch e.(type) {
            case watcher.ServiceAdded:
                fmt.Println("service added!")
            case watcher.ServiceRemoved:
                fmt.Println("service removed!")
            }
        }
    }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event interface{}

type ServiceAdded

type ServiceAdded struct {
	ID string
}

type ServiceRemoved

type ServiceRemoved struct {
	ID string
}

type ServiceTagged

type ServiceTagged struct {
	ID  string
	Tag string
}

type ServiceUntagged

type ServiceUntagged struct {
	ID  string
	Tag string
}

type ServiceUpdated

type ServiceUpdated struct {
	ID string
}

type Watcher

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

func NewWatcher

func NewWatcher(ot *oniontree.OnionTree) *Watcher

NewWatcher returns a new Watcher.

func (*Watcher) Watch

func (w *Watcher) Watch(
	ctx context.Context,
	eventCh chan<- Event,
) error

Watch watches for events, emitting them to channel `eventCh`. The call to Watch blocks until there's an error, or the context `ctx` is canceled.

Jump to

Keyboard shortcuts

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