1
1
# jrpc - rpc with json [ ![ Build] ( https://github.com/go-pkgz/jrpc/actions/workflows/ci.yml/badge.svg )] ( https://github.com/go-pkgz/jrpc/actions/workflows/ci.yml ) [ ![ Go Report Card] ( https://goreportcard.com/badge/github.com/go-pkgz/jrpc )] ( https://goreportcard.com/report/github.com/go-pkgz/jrpc ) [ ![ Coverage Status] ( https://coveralls.io/repos/github/go-pkgz/jrpc/badge.svg?branch=master )] ( https://coveralls.io/github/go-pkgz/jrpc?branch=master ) [ ![ godoc] ( https://godoc.org/github.com/go-pkgz/jrpc?status.svg )] ( https://godoc.org/github.com/go-pkgz/jrpc )
2
2
3
3
jrpc library provides client and server for RPC-like communication over HTTP with json encoded messages.
4
- The protocol is a somewhat simplified version of json-rpc with a single POST call sending Request json
5
- (method name and the list of parameters) moreover, receiving json Response with result data and an error string.
4
+ The protocol is a somewhat simplified version of json-rpc with a single POST call sending ` Request ` json
5
+ (method name and the list of parameters) moreover, receiving json ` Response ` with result data and an error string.
6
6
7
7
## Usage
8
8
@@ -28,29 +28,27 @@ plugin.Run(9090)
28
28
29
29
The constructor ` NewServer ` accept two parameters:
30
30
* ` API ` - a base url for rpc calls
31
- * ` Options ` - allows configure server parameters such is timeouts, logger, limits, middlewares and etc.
32
-
33
- ##### options
34
- ` jrpc.NewServer ` call accepts functional options:
35
- * ` jrpc.Auth ` - set credentials basic auth to server, accepts ` username ` and ` password `
36
- * ` jrpc.WithTimeout ` - sets global timeouts for server requests, such as read, write and idle. Call accept ` Timeouts ` struct.
37
- * ` jrpc.WithLimits ` - define limit for server call, accepts limit value in ` float64 ` type
38
- * ` jrpc.WithThrottler ` - sets throttler middleware with specify limit value
39
- * ` jrpc.WithMiddlewares ` - sets custom middlewares list to server, accepts list of handler with idiomatic type ` func(http.Handler) http.Handler `
40
- * ` jrpc.WithtSignature ` - sets server signature, accept appName, author and version. Disable by default.
41
- * ` jrpc.WithLogger ` - define custom logger (e.g. [ lgr] ( https://github.com/go-pkgz/lgr ) )
31
+ * ` Options ` - optional parameters such is timeouts, logger, limits, middlewares and etc.
32
+ * ` Auth ` - set credentials basic auth to server, accepts ` username ` and ` password `
33
+ * ` WithTimeout ` - sets global timeouts for server requests, such as read, write and idle. Call accept ` Timeouts ` struct.
34
+ * ` WithLimits ` - define limit for server call, accepts limit value in ` float64 ` type
35
+ * ` WithThrottler ` - sets throttler middleware with specify limit value
36
+ * ` WithtSignature ` - sets server signature, accept appName, author and version. Disable by default.
37
+ * ` WithLogger ` - define custom logger (e.g. [ lgr] ( https://github.com/go-pkgz/lgr ) )
38
+ * ` WithMiddlewares ` - sets custom middlewares list to server, accepts list of handler with idiomatic type ` func(http.Handler) http.Handler `
42
39
43
40
Example with options:
44
41
``` go
45
42
plugin := NewServer (" /command" ,
43
+ Auth (" user" , " password" ),
46
44
WithTimeout (Timeouts{ReadHeaderTimeout: 5 * time.Second , WriteTimeout : 5 * time.Second , IdleTimeout : 10 * time.Second }),
47
45
WithThrottler (120 ),
48
- WithLimits (100 ),
49
- WithMiddlewares (middleware.Heartbeat (' /ping' ), middleware.Profiler , middleware. StripSlashes ),
46
+ WithLimits (100 ),
47
+ WithtSignature (" the best plugin ever" , " author" , " 1.0.0" ),
48
+ WithMiddlewares (middleware.Heartbeat (' /ping' ), middleware.Profiler , middleware.StripSlashes ),
50
49
)
51
50
```
52
- ** NOTICE:**
53
- Such middlewares as ` RealIP ` ,` Recoverer ` ,` Ping ` ,` NoCache ` and ` basicAuth ` define by default.
51
+
54
52
### Application (client)
55
53
56
54
``` go
0 commit comments