From cfc692da07ea1d317824af84db6378ca57b2393f Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Tue, 24 Mar 2015 16:08:42 +1100 Subject: [PATCH] Made Server an interface, for expandability. --- mounted_file_system.go | 10 ++++++---- samples/hellofs/hello_fs.go | 5 ++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/mounted_file_system.go b/mounted_file_system.go index 27bc17c..ec98517 100644 --- a/mounted_file_system.go +++ b/mounted_file_system.go @@ -22,9 +22,11 @@ import ( "golang.org/x/net/context" ) -// A Server is a function that reads ops from the supplied Connection, -// responding to them as appropriate. -type Server func(*Connection) +// A type that knows how to serve ops read from a connection. +type Server interface { + // Read and serve ops from the supplied connection until EOF. + ServeOps(*Connection) +} // A struct representing the status of a mount operation, with a method that // waits for unmounting. @@ -130,7 +132,7 @@ func Mount( // Serve the connection in the background. When done, set the join status. go func() { - server(connection) + server.ServeOps(connection) mfs.joinStatus = connection.close() close(mfs.joinStatusAvailable) }() diff --git a/samples/hellofs/hello_fs.go b/samples/hellofs/hello_fs.go index 378cde5..11104c2 100644 --- a/samples/hellofs/hello_fs.go +++ b/samples/hellofs/hello_fs.go @@ -33,11 +33,10 @@ import ( // // Each file contains the string "Hello, world!". func NewHelloFS(clock timeutil.Clock) (server fuse.Server, err error) { - fs := &helloFS{ + server = &helloFS{ Clock: clock, } - server = fuse.Server(fs.serve) return } @@ -45,7 +44,7 @@ type helloFS struct { Clock timeutil.Clock } -func (fs *helloFS) serve(c *fuse.Connection) { +func (fs *helloFS) ServeOps(c *fuse.Connection) { for { op, err := c.ReadOp() if err == io.EOF {