doc: cleanup and improve for recently moved pkgs (#354)
* chore(atomicx): review docs and add usage example * chore(fsx): improve docs, return value, add examples * fix(kvstore): correct typo and add example * fix(multierror): add basic example * doc: revamp ooapi documentation
This commit is contained in:
parent
33de701263
commit
acd4ffff35
12 changed files with 172 additions and 26 deletions
34
internal/fsx/example_test.go
Normal file
34
internal/fsx/example_test.go
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
package fsx_test
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
|
||||
"github.com/ooni/probe-cli/v3/internal/fsx"
|
||||
)
|
||||
|
||||
func ExampleOpenFile_openingDir() {
|
||||
filep, err := fsx.OpenFile("testdata")
|
||||
if !errors.Is(err, syscall.ENOENT) {
|
||||
log.Fatal("unexpected error", err)
|
||||
}
|
||||
if filep != nil {
|
||||
log.Fatal("expected nil fp")
|
||||
}
|
||||
}
|
||||
|
||||
func ExampleOpenFile_openingFile() {
|
||||
filep, err := fsx.OpenFile(filepath.Join("testdata", "testfile.txt"))
|
||||
if err != nil {
|
||||
log.Fatal("unexpected error", err)
|
||||
}
|
||||
data, err := io.ReadAll(filep)
|
||||
if err != nil {
|
||||
log.Fatal("unexpected error", err)
|
||||
}
|
||||
fmt.Printf("%d\n", len(data))
|
||||
}
|
||||
Loading…
Reference in a new issue