From 4a5469cda8a6c58d85d55c947ca6eaacfb3c2f3a Mon Sep 17 00:00:00 2001 From: mkvolkov Date: Mon, 22 Aug 2022 07:17:36 +0300 Subject: [PATCH] first example --- rclonefs/example/README.md | 55 ++++++++++++++++++++++++++++++++++++ rclonefs/example/call.json | 13 +++++++++ rclonefs/example/cloud.txt | 1 + rclonefs/example/example.go | 39 +++++++++++++++++++++++++ rclonefs/example/object.json | 13 +++++++++ rclonefs/example/person.json | 10 +++++++ 6 files changed, 131 insertions(+) create mode 100644 rclonefs/example/README.md create mode 100644 rclonefs/example/call.json create mode 100644 rclonefs/example/cloud.txt create mode 100644 rclonefs/example/example.go create mode 100644 rclonefs/example/object.json create mode 100644 rclonefs/example/person.json diff --git a/rclonefs/example/README.md b/rclonefs/example/README.md new file mode 100644 index 0000000..91d18b7 --- /dev/null +++ b/rclonefs/example/README.md @@ -0,0 +1,55 @@ +### How to pass this test + +This test can be used with any cloud storage, +which is available in RClone. + +You must have installed RClone on your computer. + +### Example: how to run this test with PCloud + +1. Create PCloud account. +2. Create rclone configuration using this instruction: + +https://rclone.org/pcloud/ + +Let's presume that the name of your remote storage, which +you put during the first step, is pcloud1. + +``` +name> pcloud +``` + +3. Put the file person.json or any other to the root +directory of your PCloud storage. +4. Make sure that your configuration works. For example, +run this command: + +``` +rclone cat pcloud1:person.json +``` + +pcloud1 is the name of your remote storage: +(2. name> pcloud1), person.json is in the root folder. + +- you will see the content of the file in your console. + +If your cloud storage contains buckets (Amazon S3, +minio, Backblaze B2) and the file mock.json is put into +the bucket1, the access to the file is: + +```go +TODO +``` + +5. Put the name of your remote storage with the full +path '/cfg/json' to the file 'cloud.txt' + +``` +pcloud_mv1:/cfg/json +``` + +6. Run the example: + +``` +go run example.go +``` diff --git a/rclonefs/example/call.json b/rclonefs/example/call.json new file mode 100644 index 0000000..0d49567 --- /dev/null +++ b/rclonefs/example/call.json @@ -0,0 +1,13 @@ +{ + "call": 12, + "call_inline_function": 25, + "call_method1": 9, + "call_multiline_function": [8, 9], + "len": [ + 5, + 3 + ], + "named_params": 12, + "named_params2": 5, + "standard_lib": "foo bar" +} diff --git a/rclonefs/example/cloud.txt b/rclonefs/example/cloud.txt new file mode 100644 index 0000000..86a0700 --- /dev/null +++ b/rclonefs/example/cloud.txt @@ -0,0 +1 @@ +pcloud_mv1:/cfg/json diff --git a/rclonefs/example/example.go b/rclonefs/example/example.go new file mode 100644 index 0000000..a7d193e --- /dev/null +++ b/rclonefs/example/example.go @@ -0,0 +1,39 @@ +package main + +import ( + "fmt" + "os" + "log" + "strings" + + "github.com/spf13/afero" + "github.com/spf13/afero/rclonefs" +) + +func main() { + rawpath, err := os.ReadFile("cloud.txt") + if err != nil { + log.Fatalf("Error in ReadFile: %v\n", err) + } + + path := strings.TrimSpace(string(rawpath)) + + RFS, err := rclonefs.CreateRCFS(path, "") + if err != nil { + log.Fatalf("Error in CreateRCFS: %v\n", err) + } + + // Create() test + file1, err := RFS.Create("/cfg/json/file1.json") // absolute path + if err != nil { + log.Fatal("Create() test FAILED\n") + } + file1.Close() + ok, err := afero.Exists(RFS, "file1.json") // relative path + if err != nil { + log.Fatal("Error in Exists(): %v\n") + } + if ok { + fmt.Printf("Create() test passed.\n") + } +} diff --git a/rclonefs/example/object.json b/rclonefs/example/object.json new file mode 100644 index 0000000..c3abef4 --- /dev/null +++ b/rclonefs/example/object.json @@ -0,0 +1,13 @@ +{ + "object": { + "f": 1, + "g": 2 + }, + "test1": [ + { + "kind": "Whiskey", + "qty": 1 + } + ], + "test2": 7 +} diff --git a/rclonefs/example/person.json b/rclonefs/example/person.json new file mode 100644 index 0000000..9956beb --- /dev/null +++ b/rclonefs/example/person.json @@ -0,0 +1,10 @@ +{ + "person1": { + "name": "Alice", + "welcome": "Hello Alice!" + }, + "person2": { + "name": "Bob", + "welcome": "Hello Bob!" + } +}