Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dizoftteam/jsonrpc_server
Go JSONRpc Server 2.0
https://github.com/dizoftteam/jsonrpc_server
go json jsonrpc-server jsonrpc2
Last synced: 3 days ago
JSON representation
Go JSONRpc Server 2.0
- Host: GitHub
- URL: https://github.com/dizoftteam/jsonrpc_server
- Owner: DizoftTeam
- License: mit
- Created: 2020-05-10T08:41:04.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-08-10T15:19:45.000Z (about 1 year ago)
- Last Synced: 2024-06-20T17:46:26.090Z (5 months ago)
- Topics: go, json, jsonrpc-server, jsonrpc2
- Language: Go
- Homepage: https://pkg.go.dev/github.com/DizoftTeam/jsonrpc_server?tab=doc
- Size: 23.4 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Go JsonRpc Server
[![GitHub go.mod Go version of a Go module](https://img.shields.io/github/go-mod/go-version/DizoftTeam/jsonrpc_server.svg)](https://github.com/DizoftTeam/jsonrpc_server)
[![GitHub tag](https://img.shields.io/github/tag/DizoftTeam/jsonrpc_server.svg)](https://GitHub.com/DizoftTeam/jsonrpc_server/tags/)[![GitHub stars](https://img.shields.io/github/stars/DizoftTeam/jsonrpc_server.svg?style=social&label=Star&maxAge=2592000)](https://GitHub.com/DizoftTeam/jsonrpc_server/stargazers/)
[![GitHub issues](https://img.shields.io/github/issues/DizoftTeam/jsonrpc_server.svg)](https://GitHub.com/DizoftTeam/jsonrpc_server/issues/)
[![MIT license](https://img.shields.io/badge/License-MIT-blue.svg)](https://lbesson.mit-license.org/)
[![Open Source? Yes!](https://badgen.net/badge/Open%20Source%20%3F/Yes%21/blue?icon=github)](https://github.com/Naereen/badges/)Base implementation of JSONRpc v2.0 in Go
## Breaking changes of v2
### HttpHandler
Cause: add new handler
> Old
http.HandleFunc("/", jsonrpc.Handler)
> New
http.HandleFunc("/", jsonrpc.HttpHandler)
## How to get
Use follow command
```bash
go get github.com/DizoftTeam/jsonrpc_server
```## Example
Command example below
```go
package mainimport (
jsonrpc "github.com/DizoftTeam/jsonrpc_server""fmt"
"log"
"net/http"
)// UserLogin controller for login method
type UserLogin struct {}// Handler worker
func (u UserLogin) Handler(params interface{}) (interface{}, *jsonrpc.RPCError) {
// Some logic/magic here.
// It's like a controller
// To getting raw request you can run this
// session := jsonrpc.NewSession()// Success
return "Login ok!", nil// Fail
//return nil, &jsonrpc.RPCError{
// Code: -10,
// Message: "Cant login",
//}
}// Register methods and callbacks
func registerMethods() {
jsonrpc.Register("user.login", UserLogin{})jsonrpc.RegisterFunc("version", func(params interface{}) (interface{}, *jsonrpc.RPCError) {
return "1.0.0", nil
})
}func main() {
registerMethods()http.HandleFunc("/", jsonrpc.HttpHandler)
log.Print("\nStarting server at :8089\n")
if err := http.ListenAndServe(":8089", nil); err != nil {
log.Panic("Cant start server", err)
}
}
```