Skip to content

Instantly share code, notes, and snippets.

@zeisss
Created September 16, 2013 12:18
Show Gist options
  • Select an option

  • Save zeisss/6579990 to your computer and use it in GitHub Desktop.

Select an option

Save zeisss/6579990 to your computer and use it in GitHub Desktop.
type Args struct {
Values []string `json:values`
}
type Service int
// {"id": 1, "method": "echo2.Echo2", "params": {"values": ["hello", "world"]}}
func (this *Service) Echo2(params *Args, response *string) error {
*response = "Hello World"
return nil
}
// {"id": 2, "method": "echo2.Echo", "params": ["hello", "world"]}
func (this *Service) Echo(args []string, response *int) error {
fmt.Printf("Input(%v): %v\n", len(args), args)
for _, s := range(args) {
fmt.Println(s)
}
*response = 1
return nil
}
// {"id": [2], "method": "echo2.Error", "params":[]}
func (this *Service) Error(nothing interface{}, response *int) error {
return errors.New("Bad Boy!")
}
func main() {
service := new(Service)
rpc.RegisterName("echo2", service)
jsonrpc.ListenAndServeForever("tcp", ":1234")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment