Skip to content

Latest commit

 

History

History
74 lines (52 loc) · 1.8 KB

README.md

File metadata and controls

74 lines (52 loc) · 1.8 KB

minibus-go

Minibus-go is a Golang client library for communicating via the ttyzero/minibus message bus. You can use this to both listen for and send messages to minibus channels.

Creating a client

Creating a client is very simple, use New and pass in the fully qualified path to the minibus working dir, or minibus.Default to connect to the default location provided by os.UserCacheDir() + /minibus. This is a non-blocking operation.

mb := minibus.New(minibus.Default)

Sending Messages

Sending messages is very straight forward, call Send with a channel and a message (string).

err := mb.Send("channel", "This is my message")
if err != nil {
  fmt.Println("Failed to send", err)
}

Listening for messages

Listen by opening a channel, this creates a background goroutine that will connect to the minibus service and begin outputting messages on the returned chan string

exampleChan := mb.OpenChannel("example-channel")

for {
  select {
    msg, open := <- exampleChan:
    if !open {
      break 
    }
    fmt.Printf("(example-chan): %s", msg)
  }
}

closing a channel

To close a channel, simply close() the chan string returned by OpenChannel, this will cause the background goroutine to terminate.

mb := minibus.Client("default")
exampleChan := mb.OpenChannel("example-channel")
close(exampleChan)



ttyZero Logo

Minibus-go is part of the ttyZero Project

Minibus-go is (c) 2019 ttyZero authors
and is available under the MIT license.