22
22
23
23
## Installation
24
24
25
+ Initialize your go module if you haven't already:
26
+
27
+ ```bash
28
+ go mod init <YOUR _MODULE_NAME>
29
+ ```
30
+
25
31
To install using `go get`:
26
32
27
33
```bash
@@ -30,65 +36,72 @@ go get github.com/{{ sdk.gitUserName }}/{{ sdk.gitRepoName }}
30
36
31
37
## Testing the SDK
32
38
33
- * clone this repo.
34
- * create a project and within this project a collection.
35
- * configure the documents in the collection to have a _key_ = __hello__ .
39
+ * Clone this repo.
40
+ * Create a project and within this project a collection.
41
+ * Configure the documents in the collection to have a attribute `key` = `hello` .
36
42
* Then inject these environment variables:
37
43
38
44
```bash
39
- export YOUR_ENDPOINT=https://{{ sdk .gitUserName | url_encode }}.io/v1
40
- export YOUR_PROJECT_ID=6…8
41
- export YOUR_KEY="7055781…cd95"
42
- export COLLECTION_ID=616a095b20180
45
+ export YOUR_ENDPOINT=https://<REGION >.cloud.{{ sdk .gitUserName | url_encode }}.io/v1
46
+ export YOUR_PROJECT_ID=616a09..0180
47
+ export YOUR_KEY=7055781..cd95
48
+ export DATABASE_ID=616a09..0180
49
+ export COLLECTION_ID=616a09..20180
43
50
```
44
51
45
- Create `main.go` file with:
46
-
47
- ```go
48
- package main
52
+ * Create `main.go` file with:
49
53
50
- import (
51
- "log"
52
- "os"
53
- "time"
54
+ ```go
55
+ package main
54
56
55
- "github.com/{{sdk .gitUserName }}/{{ sdk .gitRepoName | url_encode }}/appwrite"
56
- "github.com/{{sdk .gitUserName }}/{{ sdk .gitRepoName | url_encode }}/id"
57
- )
57
+ import (
58
+ "log"
59
+ "os"
60
+ "time"
58
61
59
- func main() {
60
- client := appwrite.NewClient(
61
- appwrite.WithEndpoint(os.Getenv("YOUR_ENDPOINT")),
62
- appwrite.WithProject(os.Getenv("YOUR_PROJECT_ID")),
63
- appwrite.WithKey(os.Getenv("YOUR_KEY")),
62
+ "github.com/{{sdk .gitUserName }}/{{ sdk .gitRepoName | url_encode }}/appwrite"
63
+ "github.com/{{sdk .gitUserName }}/{{ sdk .gitRepoName | url_encode }}/id"
64
64
)
65
65
66
- databases := appwrite.NewDatabase(client)
67
-
68
- data := map[string]string{
69
- "hello": "world",
70
- }
71
- doc, err := databases.CreateDocument(
72
- os.Getenv("DATABASE_ID"),
73
- os.Getenv("COLLECTION_ID"),
74
- id.Unique(),
75
- data,
76
- )
77
- if err != nil {
78
- log.Printf("Error creating document: %v", err)
66
+ func main() {
67
+ client := appwrite.NewClient(
68
+ appwrite.WithEndpoint(os.Getenv("YOUR_ENDPOINT")),
69
+ appwrite.WithProject(os.Getenv("YOUR_PROJECT_ID")),
70
+ appwrite.WithKey(os.Getenv("YOUR_KEY")),
71
+ )
72
+
73
+ databases := appwrite.NewDatabases(client)
74
+
75
+ data := map[string]interface{}{
76
+ "hello": "world",
77
+ }
78
+ doc, err := databases.CreateDocument(
79
+ os.Getenv("DATABASE_ID"),
80
+ os.Getenv("COLLECTION_ID"),
81
+ id.Unique(),
82
+ data,
83
+ )
84
+ if err != nil {
85
+ log.Printf("Error creating document: %v", err)
86
+ }
87
+
88
+ log.Printf("Created document: %v", doc)
79
89
}
80
-
81
- log.Printf("Created document: %v", doc)
82
- }
83
- ```
90
+ ```
84
91
85
92
* After that, run the following
86
93
87
- > % go run main.go
88
- > 2021/10/16 03:41:17 Created document: map[$collection:616a095b20180 $id:616a2dbd4df16 $permissions:map[read:[] write:[]] hello:world]
94
+ ```bash
95
+ go run main.go
96
+ ```
89
97
90
- {% if sdk . gettingStarted %}
98
+ * You should see the following output:
91
99
100
+ ```bash
101
+ 2021/10/16 03:41:17 Created document: map[$collection:616a095b20180 $id:616a2dbd4df16 $permissions:map[read:[] write:[]] hello:world]
102
+ ```
103
+
104
+ {% if sdk .gettingStarted %}
92
105
{{ sdk .gettingStarted | raw }}
93
106
{% endif %}
94
107
0 commit comments