Created
September 16, 2013 12:18
-
-
Save zeisss/6579990 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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