docs: Fix quick start is not runnable
@@ -80,26 +80,40 @@ Optional metadata
## Quick Start
```go
+package main
+
import (
+ "bytes"
"log"
- "github.com/aos-dev/go-storage/v3"
"github.com/aos-dev/go-storage/v3/pairs"
"github.com/aos-dev/go-service-fs/v2"
)
+func main() {
// Init a service.
store, err := fs.NewStorager(pairs.WithWorkDir("/tmp"))
if err != nil {
log.Fatalf("service init failed: %v", err)
}
-// Use Storager API to maintain data.
+ content := []byte("Hello, world!")
+ length := int64(len(content))
+ r := bytes.NewReader(content)
+
+ _, err = store.Write("hello", r, length)
+ if err != nil {
+ log.Fatalf("write failed: %v", err)
+ }
+
var buf bytes.Buffer
-n, err := store.Read("path/to/file", &buf)
+ _, err = store.Read("hello", &buf)
if err != nil {
- log.Printf("storager read: %v", err)
+ log.Fatalf("storager read: %v", err)
+ }
+
+ log.Printf("%s", buf.String())
}
```
