specifying multiple routes

29 views
Skip to first unread message

Christopher Hobbs

unread,
Aug 26, 2012, 1:58:48 AM8/26/12
to golang...@googlegroups.com
How would I go about specifying multiple routes in goweb?  In my case, I'd like to have /api/binstore and /api/reports exposed, each with GET/POST options.  Here's my main():

func main() {

        goweb.ConfigureDefaultFormatters() // default to JSON

        binController := new(SampleBinController)
        goweb.MapRest("/api/binstore", binController)

        reportController := new(ReportController)
        goweb.MapRest("/api/reports", reportController)

        goweb.ListenAndServe(":8080")
}

What am I missing?

Thanks! 

matryer

unread,
Aug 26, 2012, 3:20:55 PM8/26/12
to golang...@googlegroups.com
Christopher, you nailed it.

Check to be sure your controllers implement one or more of the interfaces defined in http://code.google.com/p/goweb/source/browse/goweb/rest_controller.go 

This code works:

    package main

    import (
    )

    type SampleBinController struct {}
    func (c *SampleBinController) ReadMany(cx *goweb.Context) {
cx.RespondWithData("BIN")
    }

    type ReportController struct {}
    func (c *ReportController) ReadMany(cx *goweb.Context) {
cx.RespondWithData("REPORT")
    }

    func main() {

        goweb.ConfigureDefaultFormatters() // default to JSON

        binController := new(SampleBinController)
        goweb.MapRest("/api/binstore", binController)

        reportController := new(ReportController)
        goweb.MapRest("/api/reports", reportController)

        goweb.ListenAndServe(":8080")
    }

Mat
Reply all
Reply to author
Forward
0 new messages