A golang library for sending messages & navigating channels.
This is v.01 -- it has no tests, performance is probably awful and it's not proven safe in production anywhere. But maybe it'll scratch an itch?
Moitessier
is an opinionated message/dispatch pattern that aims to make it easy to aggregate messages into a listener.
go get -u github.com/likestripes/moitessier
import (
"github.com/likestripes/moitessier"
)
Moitessier
uses likestripes/pacific as an opinionated ORM, and likestripes/kolkata to handle user identities. Kolkata
likely doesn't have to be a hard dependency, there's not a lot special about it relative to Moitessier
if you're so inclined.
Pacific
currently supports AppEngine and Postgres:
Google AppEngine: goapp serve
works out of the box (they include the buildtag for you)
Postgres: go run -tags 'postgres' main.go
-- details in the pacific/Readme.
moitessier.Shared // support many subscribers on a listener; only deprecate/delete when the last subscriber has terminated
moitessier.Private // listener's owner's eyes only
moitessier.Handler // up to you & your func
conditions := moitessier.Conditions{state.Context, src_person, moitessier.Shared, "scoped string"}
listener := conditions.NewListener()
since := time.Now()
interval := 1000 //in ms
time_out := 150000 //in ms
args := ws_state{conn} //OPTIONAL args for the listener_func & responder_fund
listener.ListenUntil(listener_func, responder_func, since, interval, time_out, args)
Use your listener_func
& responder_func
to control/act in the listener's loop.
func listener_func(listener *moitessier.Listener, args []interface{}) error {
// make sure the listener is still active (i.e. is the websocket connection still open?)
}
func responder_func(msgs []moitessier.Message, args []interface{}) error {
// do something with the message (...post it to the websocket connection)
}
Use moitessier.Dispatch
to create messages for each Listener
that's shares the scope and type. Note that you can use the same moitessier.Dispacth
for basic messages and custom handlers by including all arguments.
moitessier.Dispatch(&state.Context, state.Person, "scoped string", "response string (required for Private and Shared listeners)")
type Handler func(string, Message) interface{}
func saver_func(listener_id string, message moitessier.Message) (interface{}) {
return "saver was called for: "+listener_id
}
messages, _, _ := moitessier.Dispatch(&state.Context, state.Person, "scoped string", "response string (leave blank if this should be Handler only)", saver_func)
- scope as interface{}, i.e. string, []string, func
- listeners should be unique to client instead of uniq to person
- out of band GC
- tests, docs.