From 7a82927f639484d73cb828edca1df9eb2ef1e4c8 Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Fri, 1 May 2015 10:57:49 +1000 Subject: [PATCH] commonOp.respond --- fuseops/common_op.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/fuseops/common_op.go b/fuseops/common_op.go index 640a180..c93e46d 100644 --- a/fuseops/common_op.go +++ b/fuseops/common_op.go @@ -15,6 +15,7 @@ package fuseops import ( + "reflect" "sync" "github.com/jacobsa/bazilfuse" @@ -71,3 +72,24 @@ func (o *commonOp) respondErr(err error) { o.r.RespondError(err) } + +// Respond with the supplied response struct, which must be accepted by a +// method called Respond on o.r. +// +// Special case: nil means o.r.Respond accepts no parameters. +func (o *commonOp) respond(resp interface{}) { + // Find the Respond method. + v := reflect.ValueOf(o.r) + respond := v.MethodByName("Respond") + + // Special case: handle successful ops with no response struct. + if resp == nil { + o.Logf("-> (%s) OK", o.opType) + respond.Call([]reflect.Value{}) + return + } + + // Otherwise, pass along the response struct. + o.Logf("-> %v", resp) + respond.Call([]reflect.Value{reflect.ValueOf(resp)}) +}