Skip to content

Commit 79cb7e7

Browse files
committed
fix and improve readme for go sdk
1 parent 6497464 commit 79cb7e7

File tree

1 file changed

+56
-43
lines changed

1 file changed

+56
-43
lines changed

templates/go/README.md.twig

Lines changed: 56 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222

2323
## Installation
2424

25+
Initialize your go module if you haven't already:
26+
27+
```bash
28+
go mod init <YOUR_MODULE_NAME>
29+
```
30+
2531
To install using `go get`:
2632

2733
```bash
@@ -30,65 +36,72 @@ go get github.com/{{ sdk.gitUserName }}/{{ sdk.gitRepoName }}
3036

3137
## Testing the SDK
3238

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`.
3642
* Then inject these environment variables:
3743

3844
```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
4350
```
4451

45-
Create `main.go` file with:
46-
47-
```go
48-
package main
52+
* Create `main.go` file with:
4953

50-
import (
51-
"log"
52-
"os"
53-
"time"
54+
```go
55+
package main
5456

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"
5861

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"
6464
)
6565

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)
7989
}
80-
81-
log.Printf("Created document: %v", doc)
82-
}
83-
```
90+
```
8491

8592
* After that, run the following
8693

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+
```
8997

90-
{% if sdk.gettingStarted %}
98+
* You should see the following output:
9199

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 %}
92105
{{ sdk.gettingStarted|raw }}
93106
{% endif %}
94107

0 commit comments

Comments
 (0)