id = mohttp.GetPathValues(c).Params.String("id") run = getCommander(c).GetRun(id) ) if run == nil { return nil, mohttp.HTTPError(404) } return run, nil })), ) var stdout = hateoas.NewResource( hateoas.Path("/commands/:id/stdout"), hateoas.GET( mohttp.DataResponderHandler(&middleware.DetectTypeResponder{}), mohttp.DataHandlerFunc(func(c context.Context) (interface{}, error) { var ( id = mohttp.GetPathValues(c).Params.String("id") run = getCommander(c).GetRun(id) ) if run == nil { return "", mohttp.HTTPError(404) } return run.Stdout() }), ), )
package api import ( "github.com/jonasi/mohttp" "github.com/jonasi/mohttp/hateoas" "github.com/jonasi/mohttp/middleware" "golang.org/x/net/context" ) var JSON = mohttp.DataResponderHandler(&middleware.JSONResponder{ OnError: func(c context.Context, err error) interface{} { return map[string]interface{}{ "error": err.Error(), } }, Transform: func(data interface{}) interface{} { return map[string]interface{}{ "data": data, } }, }) var AddLinkHeaders = mohttp.HandlerFunc(func(c context.Context) { res, ok := hateoas.GetResource(c) if ok { var ( rw = mohttp.GetResponseWriter(c) links = res.Links() )