Skip to content

Commit 4a3cf9a

Browse files
Merge pull request #353 from phaus/go-templates-update
2 parents 96e2c9b + 3c525da commit 4a3cf9a

File tree

19 files changed

+677
-113
lines changed

19 files changed

+677
-113
lines changed

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,19 @@
88
.env
99
.envrc
1010
.hatch
11+
1112
# exclude everything
1213
examples/*
14+
tests/tmp
15+
.phpunit.result.cache
1316

1417
# exception to the rule
15-
!examples/.gitkeep
18+
!examples/.gitkeep
19+
1620
**/.DS_Store
1721
templates/swift/example/.build
1822
templates/swift/example/Example.xcodeproj/project.xcworkspace/xcuserdata
1923
templates/swift/example/Example.xcodeproj/xcuserdata
2024
**/xcuserdata
25+
# exclude go checksum files
26+
go.sum

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ env:
2525
- SDK=DartStable
2626
- SDK=Deno1171
2727
- SDK=FlutterStable
28+
- SDK=Go112
29+
- SDK=Go118
2830
- SDK=FlutterBeta
2931
- SDK=KotlinJava8
3032
- SDK=KotlinJava11

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ $sdk->generate(__DIR__ . '/examples/php'); // Generate source code
100100
| Ruby | 2.4+ | [Ruby Style Guide] | GEM | [@eldadfux] [@abnegate] |
101101
| Python | 3.5+ | [PEP8] | PIP | [@eldadfux] [@abnegate] |
102102
| Dart | 2.7+ | [Effective Dart] | pub | [@lohanidamodar] |
103-
| Go | | [Effective Go] | go get | [@panz3r] |
103+
| Go | | [Effective Go] | go get | [@panz3r] [@phaus] |
104104
| .NET | .NET core 3.1 | [C# Coding Conventions]| NuGet | [@komemi] [@TorstenDittmann] |
105105
| D | | | ? | [You?](https://github.com/appwrite/sdk-generator/issues/20) |
106106
| Kotlin | 1.4.31+ | [Kotlin style guide] | Gradle, Maven | [@abnegate] |

example.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,9 @@ function getSSLPage($url) {
299299
->setDescription('Repo description goes here')
300300
->setShortDescription('Repo short description goes here')
301301
->setURL('https://example.com')
302+
->setVersion('0.0.1')
302303
->setGitUserName('appwrite')
303-
->setGitRepoName('go-sdk')
304+
->setGitRepoName('sdk-for-go')
304305
->setLogo('https://appwrite.io/v1/images/console.png')
305306
->setLicenseContent('test test test')
306307
->setWarning('**WORK IN PROGRESS - NOT READY FOR USAGE**')

src/SDK/Language/Go.php

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,13 @@ public function getFiles()
5959
return [
6060
[
6161
'scope' => 'default',
62-
'destination' => 'main.go',
62+
'destination' => 'go.mod',
63+
'template' => 'go/go.mod.twig',
64+
'minify' => false,
65+
],
66+
[
67+
'scope' => 'default',
68+
'destination' => 'example/main.go',
6369
'template' => 'go/main.go.twig',
6470
'minify' => false,
6571
],
@@ -83,19 +89,13 @@ public function getFiles()
8389
],
8490
[
8591
'scope' => 'default',
86-
'destination' => 'client.go',
92+
'destination' => '{{ spec.title | caseLower}}/client.go',
8793
'template' => 'go/client.go.twig',
8894
'minify' => false,
8995
],
90-
[
91-
'scope' => 'default',
92-
'destination' => 'utils.go',
93-
'template' => 'go/utils.go.twig',
94-
'minify' => false,
95-
],
9696
[
9797
'scope' => 'service',
98-
'destination' => '{{service.name | caseDash}}.go',
98+
'destination' => '{{ spec.title | caseLower}}/{{service.name | caseDash}}.go',
9999
'template' => 'go/services/service.go.twig',
100100
'minify' => false,
101101
],
@@ -117,19 +117,18 @@ public function getTypeName($type)
117117
switch ($type) {
118118
case self::TYPE_INTEGER:
119119
return 'int';
120-
break;
120+
case self::TYPE_NUMBER:
121+
return 'float64';
121122
case self::TYPE_STRING:
122123
return 'string';
123-
break;
124124
case self::TYPE_FILE:
125125
return 'string'; // '*os.File';
126-
break;
127126
case self::TYPE_BOOLEAN:
128127
return 'bool';
129-
break;
128+
case self::TYPE_OBJECT:
129+
return 'interface{}';
130130
case self::TYPE_ARRAY:
131-
return '[]interface{}';
132-
break;
131+
return '[]interface{}';
133132
}
134133

135134
return $type;
@@ -161,6 +160,9 @@ public function getParamDefault(array $param)
161160
case self::TYPE_STRING:
162161
$output .= '""';
163162
break;
163+
case self::TYPE_OBJECT:
164+
$output .= 'nil';
165+
break;
164166
case self::TYPE_ARRAY:
165167
$output .= '[]';
166168
break;
@@ -173,11 +175,14 @@ public function getParamDefault(array $param)
173175
case self::TYPE_ARRAY:
174176
$output .= $default;
175177
break;
178+
case self::TYPE_OBJECT:
179+
$output .= "\"$default\"";
180+
break;
176181
case self::TYPE_BOOLEAN:
177182
$output .= ($default) ? 'true' : 'false';
178183
break;
179184
case self::TYPE_STRING:
180-
$output .= "\"{$default}\"";
185+
$output .= "nil";
181186
break;
182187
}
183188
}
@@ -206,6 +211,9 @@ public function getParamExample(array $param)
206211
case self::TYPE_STRING:
207212
$output .= '""';
208213
break;
214+
case self::TYPE_OBJECT:
215+
$output .= 'nil';
216+
break;
209217
case self::TYPE_ARRAY:
210218
$output .= '[]';
211219
break;
@@ -221,6 +229,9 @@ public function getParamExample(array $param)
221229
case self::TYPE_ARRAY:
222230
$output .= $example;
223231
break;
232+
case self::TYPE_OBJECT:
233+
$output .= 'nil';
234+
break;
224235
case self::TYPE_BOOLEAN:
225236
$output .= ($example) ? 'true' : 'false';
226237
break;

templates/go/CHANGELOG.md.twig

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
{{sdk.changelog}}
1+
# {{sdk.changelog}}
2+
3+
## {{sdk.version}}
4+

templates/go/README.md.twig

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
![License](https://img.shields.io/github/license/{{ sdk.gitUserName|url_encode }}/{{ sdk.gitRepoName|url_encode }}.svg?style=flat-square)
44
![Version](https://img.shields.io/badge/api%20version-{{ spec.version|url_encode }}-blue.svg?style=flat-square)
5-
[![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator)
5+
[![Build Status](https://img.shields.io/travis/com/{{ sdk.gitUserName|url_encode }}/sdk-generator?style=flat-square)](https://travis-ci.com/{{ sdk.gitUserName|url_encode }}/sdk-generator)
66
{% if sdk.twitterHandle %}
77
[![Twitter Account](https://img.shields.io/twitter/follow/{{ sdk.twitterHandle }}?color=00acee&label=twitter&style=flat-square)](https://twitter.com/{{ sdk.twitterHandle }})
88
{% endif %}
@@ -25,18 +25,77 @@
2525
To install using `go get`:
2626

2727
```bash
28-
go get github.com/{{ sdk.gitUserName|url_encode }}/{{ sdk.gitRepoName|url_encode }}
28+
go get github.com/{{ sdk.gitUserName }}/{{ sdk.gitRepoName }}
2929
```
3030

31+
## Testing the SDK
32+
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__.
36+
* Then inject these environment variables:
37+
38+
```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
43+
```
44+
45+
Create `main.go` file with:
46+
47+
```go
48+
package main
49+
50+
import (
51+
"log"
52+
"os"
53+
"time"
54+
55+
"github.com/{{sdk.gitUserName}}/sdk-for-go/{{ sdk.gitRepoName|url_encode }}"
56+
)
57+
58+
func main() {
59+
client := {{ sdk.gitRepoName|url_encode }}.NewClient(10 * time.Second)
60+
client.SetEndpoint(os.Getenv("YOUR_ENDPOINT"))
61+
client.SetProject(os.Getenv("YOUR_PROJECT_ID"))
62+
client.SetKey(os.Getenv("YOUR_KEY"))
63+
64+
db := {{ sdk.gitRepoName|url_encode }}.NewDatabase(client)
65+
data := map[string]string{
66+
"hello": "world",
67+
}
68+
var EmptyArray = []interface{}{}
69+
doc, err := db.CreateDocument(
70+
os.Getenv("COLLECTION_ID"),
71+
data,
72+
EmptyArray,
73+
EmptyArray,
74+
"",
75+
"",
76+
"",
77+
)
78+
if err != nil {
79+
log.Printf("Error creating document: %v", err)
80+
}
81+
log.Printf("Created document: %v", doc)
82+
}
83+
```
84+
85+
* After that, run the following
86+
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]
89+
3190
{% if sdk.gettingStarted %}
3291

3392
{{ sdk.gettingStarted|raw }}
3493
{% endif %}
3594

3695
## Contribution
3796

38-
This library is auto-generated by Appwrite custom [SDK Generator](https://github.com/appwrite/sdk-generator). To learn more about how you can help us improve this SDK, please check the [contribution guide](https://github.com/appwrite/sdk-generator/blob/master/CONTRIBUTING.md) before sending a pull-request.
97+
This library is auto-generated by {{ spec.title }} custom [SDK Generator](https://github.com/{{ sdk.gitUserName|url_encode }}/sdk-generator). To learn more about how you can help us improve this SDK, please check the [contribution guide](https://github.com/{{ sdk.gitUserName|url_encode }}/sdk-generator/blob/master/CONTRIBUTING.md) before sending a pull-request.
3998

4099
## License
41100

42-
Please see the [{{spec.licenseName}} license]({{spec.licenseURL}}) file for more information.
101+
Please see the [{{spec.licenseName}} license]({{spec.licenseURL}}) file for more information.

0 commit comments

Comments
 (0)