diff --git a/go.mod b/go.mod index ebc9d12ee..dac5e0c56 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.13 require ( github.com/apparentlymart/go-textseg v1.0.0 - github.com/creachadair/jrpc2 v0.7.0 + github.com/creachadair/jrpc2 v0.8.1 github.com/fsnotify/fsnotify v1.4.9 github.com/google/go-cmp v0.4.0 github.com/hashicorp/go-version v1.2.0 diff --git a/go.sum b/go.sum index 70534cc2b..8378a0304 100644 --- a/go.sum +++ b/go.sum @@ -13,8 +13,8 @@ github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310 h1:BUAU3CGlLvorLI26 github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQkY= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= -github.com/creachadair/jrpc2 v0.7.0 h1:y6RIGw69axGeWI3JBaNPFWTFJ3sAoUgkVH5Gr4ND47Q= -github.com/creachadair/jrpc2 v0.7.0/go.mod h1:yMFI6NwXGITWoWDEEdmZESIHp13SAuSkGCTBz9bSGBg= +github.com/creachadair/jrpc2 v0.8.1 h1:YX27WgtXa9v7g0kn3oYe7gmxt7e5M3miVgEgTXoTqcY= +github.com/creachadair/jrpc2 v0.8.1/go.mod h1:yMFI6NwXGITWoWDEEdmZESIHp13SAuSkGCTBz9bSGBg= github.com/creachadair/staticfile v0.1.2/go.mod h1:a3qySzCIXEprDGxk6tSxSI+dBBdLzqeBOMhZ+o2d3pM= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/vendor/github.com/creachadair/jrpc2/doc.go b/vendor/github.com/creachadair/jrpc2/doc.go index 2f69ad3c4..4afdc8c04 100644 --- a/vendor/github.com/creachadair/jrpc2/doc.go +++ b/vendor/github.com/creachadair/jrpc2/doc.go @@ -119,7 +119,7 @@ sends them to the server, but the server does not reply. A jrpc2.Client supports sending notifications as follows: - err := cli.Notify(ctx, "Alert", map[string]string{ + err := cli.Notify(ctx, "Alert", handler.Obj{ "message": "A fire is burning!", }) diff --git a/vendor/github.com/creachadair/jrpc2/handler/handler.go b/vendor/github.com/creachadair/jrpc2/handler/handler.go index 9ecf08587..a913a1c70 100644 --- a/vendor/github.com/creachadair/jrpc2/handler/handler.go +++ b/vendor/github.com/creachadair/jrpc2/handler/handler.go @@ -301,26 +301,13 @@ func (a Args) MarshalJSON() ([]byte, error) { return json.Marshal([]interface{}(a)) } -// Obj is a wrapper that decodes object fields into concrete locations. +// Obj is a wrapper that maps object fields into concrete locations. // // Unmarshaling a JSON text into an Obj value v succeeds if the JSON encodes an // object, and unmarshaling the value for each key k of the object into v[k] // succeeds. If k does not exist in v, it is ignored. // -// Usage example: -// -// var x, y int -// var s string -// -// if err := req.UnmarshalParams(handler.Obj{ -// "left": &x, -// "right": &x, -// "tag": &s, -// }); err != nil { -// return nil, err -// } -// // do useful work with x, y, and s -// +// Marshaling an Obj into JSON works as for an ordinary map. type Obj map[string]interface{} // UnmarshalJSON supports JSON unmarshaling into o. diff --git a/vendor/github.com/creachadair/jrpc2/server/simple.go b/vendor/github.com/creachadair/jrpc2/server/simple.go new file mode 100644 index 000000000..39e9f144a --- /dev/null +++ b/vendor/github.com/creachadair/jrpc2/server/simple.go @@ -0,0 +1,43 @@ +package server + +import ( + "errors" + + "github.com/creachadair/jrpc2" + "github.com/creachadair/jrpc2/channel" +) + +// A Simple server manages execution of a server for a single service instance. +type Simple struct { + running bool + svc Service + opts *jrpc2.ServerOptions +} + +// NewSimple constructs a new, unstarted *Simple instance for the given +// service. When run, the server will use the specified options. +func NewSimple(svc Service, opts *jrpc2.ServerOptions) *Simple { + return &Simple{svc: svc, opts: opts} +} + +// Run starts a server on the given channel, and blocks until it returns. The +// server exit status is reported to the service, and the error value returned. +// Once Run returns, it can be run again with a new channel. +// +// If the caller does not need the error value and does not want to wait for +// the server to complete, call Run in a goroutine. +func (s *Simple) Run(ch channel.Channel) error { + if s.running { // sanity check + return errors.New("server is already running") + } + assigner, err := s.svc.Assigner() + if err != nil { + return err + } + s.running = true + srv := jrpc2.NewServer(assigner, s.opts).Start(ch) + stat := srv.WaitStatus() + s.svc.Finish(stat) + s.running = false + return stat.Err +} diff --git a/vendor/modules.txt b/vendor/modules.txt index b863074d1..f6ae76321 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -10,7 +10,7 @@ github.com/apparentlymart/go-textseg/v12/textseg github.com/armon/go-radix # github.com/bgentry/speakeasy v0.1.0 github.com/bgentry/speakeasy -# github.com/creachadair/jrpc2 v0.7.0 +# github.com/creachadair/jrpc2 v0.8.1 github.com/creachadair/jrpc2 github.com/creachadair/jrpc2/channel github.com/creachadair/jrpc2/code