82 lines
1.4 KiB
Go
82 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"git.michelsen.id/phill/chron/chron-note/internal/domain"
|
|
"git.michelsen.id/phill/chron/chron-note/internal/workspace"
|
|
)
|
|
|
|
func must(err error) {
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
func main() {
|
|
root := "."
|
|
|
|
if len(os.Args) > 1 {
|
|
root = os.Args[1]
|
|
}
|
|
|
|
ws, err := workspace.Open(root)
|
|
must(err)
|
|
|
|
fmt.Println("Workspace directory:")
|
|
fmt.Println(ws.Dir)
|
|
fmt.Println()
|
|
|
|
fmt.Println("Creating objects...")
|
|
|
|
var ids []domain.ObjectID
|
|
|
|
for i := range 3 {
|
|
id, err := domain.NewObjectID()
|
|
must(err)
|
|
|
|
content := fmt.Sprintf("object %d\nid: %s\n", i, id.String())
|
|
|
|
must(ws.Write(id, []byte(content)))
|
|
|
|
ids = append(ids, id)
|
|
|
|
fmt.Printf("Created object %s\n", id)
|
|
fmt.Printf("Path: %s\n\n", ws.ObjectPath(id))
|
|
}
|
|
|
|
fmt.Println("Listing workspace objects:")
|
|
fmt.Println()
|
|
|
|
list, err := ws.ListObjectIDs()
|
|
must(err)
|
|
|
|
for _, id := range list {
|
|
fi, err := ws.Stat(id)
|
|
must(err)
|
|
|
|
fmt.Printf("Object: %s\n", id)
|
|
fmt.Printf("Size: %d bytes\n", fi.Size())
|
|
fmt.Printf("Path: %s\n", ws.ObjectPath(id))
|
|
fmt.Println()
|
|
}
|
|
|
|
fmt.Println("Reading objects back:")
|
|
fmt.Println()
|
|
|
|
for _, id := range ids {
|
|
data, err := ws.Read(id)
|
|
must(err)
|
|
|
|
fmt.Printf("Object %s contents:\n", id)
|
|
fmt.Println(string(data))
|
|
fmt.Println("---")
|
|
}
|
|
|
|
fmt.Println()
|
|
fmt.Println("Filesystem view:")
|
|
fmt.Println(filepath.Join(ws.Dir, "..."))
|
|
}
|