Skip to content
/ pipein Public

Library for go to read from a fifo and push the data in.

License

Notifications You must be signed in to change notification settings

chrhlnd/pipein

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pipein

Small library to capture input on a named pipe.

Makes it easy to take input on pipe, and shut it down.

package main

import (
	"fmt"
	"os"
	"os/signal"

	"github.com/chrhlnd/pipein"
)

func main() {
	shutdown := make(chan bool)
	output := make(chan []byte, 5)

	errs := pipein.NewPipeIn().Connect("/tmp/incomming", output, shutdown)

	sig := make(chan os.Signal, 1)
	signal.Notify(sig, os.Interrupt)

WORK:
	for {
		select {
		case d := <-output:
			fmt.Printf("%v", string(d))
		case e := <-errs:
			fmt.Printf("ERR: %v\n", e)
		case <-sig:
			signal.Notify(sig)
			shutdown <- true
		DRAIN:
			for {
				select {
				case <-sig:
				default:
					break DRAIN
				}
			}
			break WORK
		}
	}

	<-shutdown
	fmt.Printf("Shutdown clean\n")
}

Echo program sample. It captures data piped to the fifo. Then prints it.

On interrupt it cleanly shuts down.

The shutdown channel is bi directional.. Send to it to cause shutdown. Read from it to know its shutdown.

About

Library for go to read from a fifo and push the data in.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published