mirror of https://github.com/spf13/afero.git
first example
This commit is contained in:
parent
51ab5597d6
commit
4a5469cda8
|
@ -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
|
||||
```
|
|
@ -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"
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
pcloud_mv1:/cfg/json
|
|
@ -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")
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"object": {
|
||||
"f": 1,
|
||||
"g": 2
|
||||
},
|
||||
"test1": [
|
||||
{
|
||||
"kind": "Whiskey",
|
||||
"qty": 1
|
||||
}
|
||||
],
|
||||
"test2": 7
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"person1": {
|
||||
"name": "Alice",
|
||||
"welcome": "Hello Alice!"
|
||||
},
|
||||
"person2": {
|
||||
"name": "Bob",
|
||||
"welcome": "Hello Bob!"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue