Gorilla / Go Noob help on JSON/RPC handling?

515 views
Skip to first unread message

Ken GoNoob

unread,
Dec 6, 2013, 2:43:56 PM12/6/13
to golan...@googlegroups.com
Hi all,
Very noob in both Go and Gorilla. Trying to put up a basic server for sucking in a JSON-RPC request, and, for now, just dumping out the request params. Test client is an existing
application that sends over a half-dozen params as mostly strings. I was able to get the simple URL-parsing Gorilla example to work (parsing name: from the URL) but on this
project everything I want is in the JSON and I will only ever get a single URL.

I built a program "rpc.go" (I'll include in a bit) which seems like it has everything the Gorilla example has. When I "go run rpc.go" in a couple of seconds the command prompt re-appears,
and there seems to be no trace of rpc.go in the process list (running OS X, fyi). But no error exits or anything. If I run the sample client, I just get a "connection refused".

If anyone can take a look, maybe run it, and see whether I'm missing something (may not have the client set up right to call this, either), I'd appreciate this greatly.
Thanks! Ken

here's the server code (rpc.go):

package main

import (
       "net/http"
)

func Init() {
     s := rpc.NewServer()
     s.RegisterCodec(json.NewCodec(), "application/json")
     s.RegisterService(new(HelloService) , "")
     http.Handle("/pv/v1/", s)
}

type HelloArgs struct {
    // Who string
    method 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.method + "!"
    return nil
}

func main() {
     Init()
}

Kyle Lemons

unread,
Dec 6, 2013, 4:54:32 PM12/6/13
to Ken GoNoob, golang-nuts
You need to http.ListenAndServe.
 
}

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Matt Silverlock

unread,
Dec 6, 2013, 6:24:08 PM12/6/13
to golan...@googlegroups.com
The Gorilla docs assume a basic knowledge of Go's net/http package. Skim over http://golang.org/doc/articles/wiki/ which may help fill some gaps.

Ken MacDonald

unread,
Dec 8, 2013, 10:38:47 AM12/8/13
to Matt Silverlock, golan...@googlegroups.com
Thanks Kyle & Matt,
A couple of us looked at that code plus comparing to the original Gorilla example snippet. Looked complete to us :-/ ... Anyway, as a (helpful?) hint for others who are presenting "example" code, it really helps the folks who are trying to figure it out if another line or two would complete the example and allow it to actually work. Even a comment "// add listener code here" would be useful to indicate things were missing.

So, the code now listens :-) but has other problems that seem to have to do more with the sample client. Looks like Gorilla may be a bit fussier about what it accepts in JSON/RPC - we have a commercial product out (written in Python) that works fine with the sample client, but we're trying to investigate moving the beast over to Go for a variety of reasons. Anyway, one step closer, thanks again guys!
Ken


On Fri, Dec 6, 2013 at 6:24 PM, Matt Silverlock <elit...@gmail.com> wrote:
The Gorilla docs assume a basic knowledge of Go's net/http package. Skim over http://golang.org/doc/articles/wiki/ which may help fill some gaps.

Archos

unread,
Dec 8, 2013, 12:55:09 PM12/8/13
to golan...@googlegroups.com, Matt Silverlock
There is a ML for Gorilla toolkit:

https://groups.google.com/forum/#!forum/gorilla-web
Reply all
Reply to author
Forward
0 new messages