intermediate

This commit is contained in:
Ben Johnson
2020-10-16 10:51:19 -06:00
parent 40d368dec5
commit c6174296ec

17
main.go
View File

@@ -1,6 +1,7 @@
package main package main
import ( import (
"encoding/json"
"errors" "errors"
"flag" "flag"
"fmt" "fmt"
@@ -63,7 +64,10 @@ func (m *Main) Run(args []string) (err error) {
m.logger.Printf("mounted") m.logger.Printf("mounted")
return fs.Serve(conn, &FS{SourcePath: m.SourcePath}) s := fs.New(conn, &fs.Config{
Debug: debug,
})
return s.Serve(&FS{SourcePath: m.SourcePath})
} }
func (m *Main) usage() { func (m *Main) usage() {
@@ -81,3 +85,14 @@ Arguments:
`[1:]) `[1:])
} }
// debug is a function that can be used for fs.Config.Debug.
// It marshals the msg to JSON and prints to the log.
func debug(msg interface{}) {
buf, err := json.Marshal(msg)
if err != nil {
println("debug: marshal error: %v", err)
return
}
log.Print("DEBUG ", string(buf))
}