Skip to content

Instantly share code, notes, and snippets.

@acheong08
Created May 18, 2024 00:38
Show Gist options
  • Save acheong08/8091a8dff256e726b0cce57e198e01ba to your computer and use it in GitHub Desktop.
Save acheong08/8091a8dff256e726b0cce57e198e01ba to your computer and use it in GitHub Desktop.
A barebones NFS client for testing
package main
import (
"context"
"fmt"
"io"
"os"
"github.com/Cyberax/go-nfs-client/nfs4"
)
const (
NumScaleThreads = 40
UploadSize = 1024 * 1024 * 5
UploadTarget = 1024 * 1024 * 1024 * 5
)
func main() {
command := os.Args[1]
path := os.Args[2]
ctx := context.Background()
hostname := "<current-hostname>"
server := "nfs_server:port"
client, err := nfs4.NewNfsClient(ctx, server, nfs4.AuthParams{
MachineName: hostname,
})
if err != nil {
panic(err)
}
defer client.Close()
var writer io.Writer = os.Stdout
switch command {
case "cat":
data, err := client.ReadFileAll(path, writer)
if err != nil {
panic(err)
}
fmt.Printf("Read %d bytes\n", data)
break
case "ls":
entries, err := client.GetFileList(path)
if err != nil {
panic(err)
}
for _, entry := range entries {
fmt.Printf("%s\n", entry.Name)
}
break
case "file":
info, err := client.GetFileInfo(path)
if err != nil {
panic(err)
}
fmt.Printf("File info: %+v\n", info)
break
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment