$ go get -d github.com/Alluxio/alluxio-go
package main
import (
"fmt"
"io/ioutil"
"log"
"strings"
"time"
alluxio "github.com/alluxio/alluxio-go"
"github.com/alluxio/alluxio-go/option"
)
func write(fs *alluxio.Client, path, s string) error {
id, err := fs.CreateFile(path, &option.CreateFile{})
if err != nil {
return err
}
defer fs.Close(id)
_, err = fs.Write(id, strings.NewReader(s))
return err
}
func read(fs *alluxio.Client, path string) (string, error) {
id, err := fs.OpenFile(path, &option.OpenFile{})
if err != nil {
return "", err
}
defer fs.Close(id)
r, err := fs.Read(id)
if err != nil {
return "", err
}
defer r.Close()
content, err := ioutil.ReadAll(r)
if err != nil {
return "", err
}
return string(content), err
}
func main() {
fs := alluxio.NewClient("localhost", 39999, 10*time.Second)
path := "/test_path"
exists, err := fs.Exists(path, &option.Exists{})
if err != nil {
log.Fatal(err)
}
if exists {
if err := fs.Delete(path, &option.Delete{}); err != nil {
log.Fatal(err)
}
}
if err := write(fs, path, "Success"); err != nil {
log.Fatal(err)
}
content, err := read(fs, path)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Result: %v\n", content)
}