Skip to content

Golang client library for communicating with ttyzero/minibus servers

License

Notifications You must be signed in to change notification settings

ttyzero/minibus-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Golang client library for communicating with ttyzero/minibus servers

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages