Borg/examples/inspect_datanode/main.go
google-labs-jules[bot] 757a12086c feat: Add programmatic examples for matrix creation and execution
This commit adds two new Go programs to the `examples` directory to
demonstrate how to use the `pkg/matrix` and `pkg/datanode` packages
programmatically:

- `examples/create_matrix_programmatically`: Shows how to create a
  `.matrix` file from scratch.
- `examples/run_matrix_programmatically`: Shows how to unpack and execute
  a `.matrix` file using `runc`.

The `examples` directory has been reorganized to place each runnable
example in its own subdirectory, which is the standard Go practice for
handling multiple `main` packages.
2025-11-13 19:27:12 +00:00

50 lines
934 B
Go

package main
import (
"fmt"
"io/fs"
"os"
"github.com/Snider/Borg/pkg/compress"
"github.com/Snider/Borg/pkg/datanode"
)
func main() {
if len(os.Args) != 2 {
fmt.Println("Usage: go run inspect_datanode.go <path to .dat file>")
os.Exit(1)
}
datFile := os.Args[1]
rawData, err := os.ReadFile(datFile)
if err != nil {
fmt.Printf("Error reading .dat file: %v\n", err)
os.Exit(1)
}
data, err := compress.Decompress(rawData)
if err != nil {
fmt.Printf("Error decompressing data: %v\n", err)
os.Exit(1)
}
dn, err := datanode.FromTar(data)
if err != nil {
fmt.Printf("Error creating DataNode from tarball: %v\n", err)
os.Exit(1)
}
fmt.Printf("Contents of %s:\n", datFile)
err = dn.Walk(".", func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
fmt.Println(path)
return nil
})
if err != nil {
fmt.Printf("Error walking DataNode: %v\n", err)
os.Exit(1)
}
}