https://github.com/dizoftteam/jsonrpc_server
Go JSONRpc Server 2.0
https://github.com/dizoftteam/jsonrpc_server
go json jsonrpc-server jsonrpc2
Last synced: about 1 month 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 (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-08-10T15:19:45.000Z (almost 3 years ago)
- Last Synced: 2025-06-26T06:40:46.727Z (about 1 year 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: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Go JsonRpc Server
[](https://github.com/DizoftTeam/jsonrpc_server)
[](https://GitHub.com/DizoftTeam/jsonrpc_server/tags/)
[](https://GitHub.com/DizoftTeam/jsonrpc_server/stargazers/)
[](https://GitHub.com/DizoftTeam/jsonrpc_server/issues/)
[](https://lbesson.mit-license.org/)
[](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 main
import (
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)
}
}
```