go-res
go-res copied to clipboard
Interservice communication
Issue
The service package should support making call requests and getting resources and events from other RES services connected to NATS.
// Example of what the API might be like
// Connect client to NATS
client := res.NewClient("nats://127.0.0.1")
// Sets token used in call requests
client.SetToken(nil)
// Get resource from another
books, err := client.Get("library.books")
// Get resource type; res.TypeModel, res.TypeCollection
typ := books.Type()
// Returns a map[string]Value. Panics if books.Type() is not res.TypeModel
m := books.Model()
// Returns a []Value. Panics if books.Type() is not res.TypeCollection
c := books.Collection()
// Unmarshals the resource into the provided interface value
var b []Book
err := books.Unmarshal(&b)
// Subscribe to events
sub := book.Subscribe(func(r res.Resource, ev res.Event) {
// Handle event
})
// Unsubscribe to events
sub.Unsubscribe()