siphon

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

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

Go to latest
Published: Feb 17, 2018 License: MPL-2.0 Imports: 11 Imported by: 0

README

Siphon - Stream commands output to your browser

Siphon is an application and a library consisting of a client and a server that communicate through UDP. The client siph accepts stdin and streams it to the server. There can be as many clients streaming to the server, each with its own id.

The server emits data via websockets to any listener that connects to it

Usage

You can simply use the siphone CLI application, or use it programmatically as a library.

Command Line Usage

$ # Start a streaming client that sends command stdout output to a server.
$ # the id and adderss flags are both optional, with the id defaulting to a
$ # random string and the default server address defaulting to "127.0.0.1:1200"
$ yourprogram | siph client id="myClient" address="127.0.0.1:1200"

$ # Start a UDP/WebSockets server. The defaults for udp and websockets port are
$ # 1200 and 3000, respectively.
$ siph server --udp-port=1200 --ws-port=3000

To see other options and flags use siph --help or siph <command> --help.

As a library

To run as a server:

// NewServer signature: NewServer(udpPort int, wsPort int) *Server
server := siphon.NewServer(1200, 3000)
err := server.Init()
if err != nil {
    fmt.Println(err)
    os.Exit(ExitCodeError)
}

To run as a client:

// Init signature: Init(address string, id string, stream *bufio.Reader, emitOutput bool) error
err := siphon.Init("127.0.0.1:1200", "myclient", bufio.NewReader(os.Stdin), true)
if err != nil {
    fmt.Fprintln(os.Stderr, err)
    os.Exit(ExitCodeError)
}

How it works

License

See LICENSE

Documentation

Index

Constants

View Source
const (
	Name    = "Siphon"
	Version = "1.0"
)
View Source
const (
	DefaultChannel = "logging"
)

Variables

This section is empty.

Functions

func Init

func Init(opts ConsumerOptions, stream io.Reader, conn io.Writer) error

Listen initializes the client to start sending Chunks at the given address

func Port

func Port(port int) func(*Server)

Types

type Chunk

type Chunk struct {
	ID        string `json:"id"`
	Data      string `json:"data"`
	Timestamp int64  `json:"timestamp"`
	Host      string `json:"host"`
}

Chunk is a data structure that represents the chunks of data transferred by the client via UDP

type ConsumerOptions

type ConsumerOptions struct {
	Id         string
	Address    string
	EmitOutput bool
}

type Server

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

Server represents a UDP server that broadcasts all data chunks coming from client pipes

func NewServer

func NewServer(options ...func(*Server)) (*Server, error)

NewServer creates a new server

func (*Server) Listen

func (s *Server) Listen(conn *net.UDPConn)

func (*Server) Subscribe

func (s *Server) Subscribe(channel string) chan []byte

func (*Server) Unsubscribe

func (s *Server) Unsubscribe(channel string, sub chan []byte)

Directories

Path Synopsis
cmd
siph command
handlers
cli

Jump to

Keyboard shortcuts

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