Created
January 14, 2013 06:54
-
-
Save anujb/4528263 to your computer and use it in GitHub Desktop.
Gorilla json-rpc sample
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
package main | |
import ( | |
"github.com/gorilla/rpc" | |
"github.com/gorilla/rpc/json" | |
"net/http" | |
) | |
type HelloArgs struct { | |
Who string | |
} | |
type HelloReply struct { | |
Message string | |
} | |
type HelloService struct{} | |
func (h *HelloService) Say(r *http.Request, args *HelloArgs, reply *HelloReply) error { | |
reply.Message = "Hello, " + args.Who + "!" | |
return nil | |
} | |
func main() { | |
server := rpc.NewServer() | |
codec := json.NewCodec() | |
server.RegisterCodec(codec, "application/json") | |
server.RegisterCodec(codec, "application/json; charset=UTF-8") // For firefox 11 and other browsers which append the charset=UTF-8 | |
server.RegisterService(new(HelloService), "") | |
http.Handle("/api", server) | |
http.ListenAndServe("127.0.0.1:8080", nil) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment