https://github.com/mushroomsir/jsonrpc
Move to https://github.com/teambition/jsonrpc-go
https://github.com/mushroomsir/jsonrpc
simple-api
Last synced: about 1 month ago
JSON representation
Move to https://github.com/teambition/jsonrpc-go
- Host: GitHub
- URL: https://github.com/mushroomsir/jsonrpc
- Owner: mushroomsir
- License: mit
- Created: 2017-02-22T10:31:23.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-02-28T03:22:25.000Z (almost 9 years ago)
- Last Synced: 2024-06-20T13:30:52.011Z (over 1 year ago)
- Topics: simple-api
- Language: Go
- Homepage:
- Size: 14.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# jsonrpc
[](https://travis-ci.org/mushroomsir/jsonrpc)
[](https://coveralls.io/r/mushroomsir/jsonrpc)
[](https://raw.githubusercontent.com/mushroomsir/jsonrpc/master/LICENSE)
[](http://godoc.org/github.com/mushroomsir/jsonrpc)
jsonrpc is an golang implementation just for parse and serialize JSON-RPC2 messages, it's easy to integration with your any application.
Inspired by [https://github.com/teambition/jsonrpc-lite](https://github.com/teambition/jsonrpc-lite) and [JSON-RPC 2.0 specifications](http://jsonrpc.org/specification)
## Installation
```go
go get github.com/mushroomsir/jsonrpc
```
## API
#### jsonrpc.Request(id, method[, params])
Creates a JSON-RPC 2.0 message structures
- `id`: {String|Int|nil}
- `method`: {String}
- `params`: {interface{}}, optional
```go
val, err := jsonrpc.Request(123, "update")
{
"jsonrpc": "2.0",
"method": "update",
"id": 123
}
```
#### jsonrpc.Request2(method[, params])
Creates a JSON-RPC 2.0 message structures, the id is automatic generation by strconv.FormatInt(rand.Int63(), 10)
- `method`: {String}
- `params`: {interface{}}, optional
```go
val, err := jsonrpc.Request("update")
{
"jsonrpc": "2.0",
"method": "update",
"id": randnum
}
```
#### jsonrpc.Notification(method[, params])
Creates a JSON-RPC 2.0 notification message structures
- `method`: {String}
- `params`: {interface{}}, optional
```go
val, err = jsonrpc.Notification("update")
{
"jsonrpc": "2.0",
"method": "update"
}
```