Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save humorless/48dc720db139793e4e79eae4177965b9 to your computer and use it in GitHub Desktop.
Save humorless/48dc720db139793e4e79eae4177965b9 to your computer and use it in GitHub Desktop.
package main
import (
"encoding/json"
"fmt"
"github.com/powerman/rpc-codec/jsonrpc2"
"net/http"
"net/rpc"
)
// Svc is an RPC service for testing.
type NqmEndpoint struct{}
type Res struct {
R int `json:"code"`
}
func (*NqmEndpoint) AddIcmp(vals []interface{}, res *Res) error {
v, _ := json.Marshal(vals)
fmt.Println(string(v))
*res = Res{R: 0}
return nil
}
func main() {
_ = rpc.Register(&NqmEndpoint{})
err := http.ListenAndServe("10.20.30.40:65534", jsonrpc2.HTTPHandler(nil))
if err != nil {
fmt.Println(err.Error())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment