commonOp.respond

geesefs-0-30-9
Aaron Jacobs 2015-05-01 10:57:49 +10:00
parent d599dcd23a
commit 7a82927f63
1 changed files with 22 additions and 0 deletions

View File

@ -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)})
}