Documentation ¶
Overview ¶
Package server provides support routines for running jrpc2 servers.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Loop ¶
Loop obtains connections from lst and starts a server for each with the given assigner and options, running in a new goroutine. If accept reports an error, the loop will terminate and the error will be reported once all the servers currently active have returned.
While running, Loop maintains a pool of *jrpc2.Server values to reduce setup and memory overhead. However, it does not rate-limit connections. Instead, the listener is responsible for deciding how and whether to shed load.
Types ¶
type Local ¶
Local represents a client and server connected by an in-memory pipe.
func NewLocal ¶ added in v0.0.61
func NewLocal(assigner jrpc2.Assigner, opts *LocalOptions) Local
NewLocal constructs a *jrpc2.Server and a *jrpc2.Client connected to it via an in-memory pipe, using the specified assigner and options. If opts == nil, it behaves as if the client and server options are also nil.
Example ¶
package main import ( "context" "fmt" "log" "bitbucket.org/creachadair/jrpc2/handler" "bitbucket.org/creachadair/jrpc2/server" ) func main() { loc := server.NewLocal(handler.Map{ "Hello": handler.New(func(context.Context) (string, error) { return "Hello, world!", nil }), }, nil) defer loc.Close() var result string if err := loc.Client.CallResult(context.Background(), "Hello", nil, &result); err != nil { log.Fatalf("Call failed: %v", err) } fmt.Println(result) }
Output: Hello, world!
type LocalOptions ¶
type LocalOptions struct { ClientOptions *jrpc2.ClientOptions ServerOptions *jrpc2.ServerOptions }
LocalOptions control the behaviour of the server and client constructed by the NewLocal function.
type LoopOptions ¶
type LoopOptions struct { // If non-nil, this function is used to convert a stream connection to an // RPC channel. If this field is nil, channel.RawJSON is used. Framing channel.Framing // If non-nil, these options are used when constructing the server to // handle requests on an inbound connection. ServerOptions *jrpc2.ServerOptions }
LoopOptions control the behaviour of the Loop function. A nil *LoopOptions provides default values as described.