Skip to content

Commit 09b36d8

Browse files
committed
updates regarding review
1 parent 1bb0fba commit 09b36d8

File tree

5 files changed

+22
-22
lines changed

5 files changed

+22
-22
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ tests/tmp
1717
# exception to the rule
1818
!examples/.gitkeep
1919

20-
.DS_Store
20+
**/.DS_Store
2121
templates/swift/example/.build
2222
templates/swift/example/Example.xcodeproj/project.xcworkspace/xcuserdata
2323
templates/swift/example/Example.xcodeproj/xcuserdata

templates/go/client.go.twig

+12-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222

2323
const (
2424
fileNameKey = "file"
25+
defaultTimeout = 10 * time.Second
2526
)
2627

2728
// {{ spec.title | caseUcfirst }}Error represents an error of a client request
@@ -60,19 +61,19 @@ type Client struct {
6061
}
6162

6263
// NewClient initializes a new {{ spec.title | caseUcfirst }} client with a given timeout
63-
func NewClient(timeout time.Duration) Client {
64+
func NewClient() Client {
6465
headers := map[string]string{
6566
{% for key,header in spec.global.defaultHeaders %}
6667
"{{key}}" : "{{header}}",
6768
"x-sdk-version": "{{ sdk.gitUserName|url_encode }}:go:{{sdk.version}}",
6869
{% endfor %}
6970
}
70-
httpClient, err := getDefaultClient(timeout)
71+
httpClient, err := getDefaultClient(defaultTimeout)
7172
if err != nil { panic(err) }
7273
return Client {
7374
endpoint: "https://{{ sdk.gitUserName|url_encode }}.io/v1",
7475
client: httpClient,
75-
timeout: timeout,
76+
timeout: defaultTimeout,
7677
headers: headers,
7778
}
7879
}
@@ -92,6 +93,14 @@ func getDefaultClient(timeout time.Duration) (*http.Client, error) {
9293
}, nil
9394
}
9495

96+
func (clt *Client) SetTimeout(timeout time.Duration) error {
97+
clt.timeout = timeout
98+
httpClient, err := getDefaultClient(timeout)
99+
if err != nil { return err }
100+
clt.client = httpClient
101+
return nil
102+
}
103+
95104
// SetEndpoint sets the default endpoint to which the Client connects to
96105
func (clt *Client) SetEndpoint(endpoint string) {
97106
clt.endpoint = endpoint

templates/go/docs/example.md.twig

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
)
88

99
func main() {
10-
var client := {{ spec.title | caseLower }}.NewClient(10 * time.Second)
10+
client := {{ spec.title | caseLower }}.NewClient()
1111

1212
{% if method.security|length > 0 %}
1313
client.SetEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint

templates/go/main.go.twig

+3-16
Original file line numberDiff line numberDiff line change
@@ -14,38 +14,25 @@ const (
1414
EmptyParentPropertyType = ""
1515
)
1616

17-
const (
18-
EmptyParentDocument = ""
19-
EmptyParentProperty = ""
20-
EmptyParentPropertyType = ""
21-
)
22-
23-
const (
24-
EmptyParentDocument = ""
25-
EmptyParentProperty = ""
26-
EmptyParentPropertyType = ""
27-
)
28-
2917
func main() {
3018
var EmptyArray = []interface{}{}
3119

32-
client := {{ sdk.gitUserName|url_encode }}.NewClient(10 * time.Second)
20+
client := {{ sdk.gitUserName|url_encode }}.NewClient()
3321
client.SetEndpoint(os.Getenv("YOUR_ENDPOINT"))
3422
client.SetProject(os.Getenv("YOUR_PROJECT_ID"))
3523
client.SetKey(os.Getenv("YOUR_KEY"))
24+
client.SetTimeout(10 * time.Second)
3625

3726
db := {{ sdk.gitUserName|url_encode }}.NewDatabase(client)
3827
data := map[string]string{
3928
"hello": "world",
4029
}
4130
doc, err := db.CreateDocument(
4231
os.Getenv("COLLECTION_ID"),
32+
EmptyParentDocument,
4333
data,
4434
EmptyArray,
4535
EmptyArray,
46-
EmptyParentDocument,
47-
EmptyParentProperty,
48-
EmptyParentPropertyType,
4936
)
5037
if err != nil {
5138
log.Printf("Error creating document: %v", err)

tests/languages/go/tests.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ import (
1111
func main() {
1212
stringInArray := []interface{}{"string in array"}
1313

14-
client := appwrite.NewClient(10 * time.Second)
14+
client := appwrite.NewClient()
15+
err := client.SetTimeout(10 * time.Second)
16+
if err != nil {
17+
panic(err)
18+
}
1519
client.SetEndpoint("https://appwrite.io/v1")
1620
client.AddHeader("Origin", "http://localhost")
1721
fmt.Print("\n\nTest Started\n")

0 commit comments

Comments
 (0)