Add GO Templates to the SDK Generator
We need help adding GO templates to this project to allow easy generation of GO SDKs for Appwrite server.
A full guide on how to add new language support to the Appwrite SDK generator is located here: https://github.com/appwrite/sdk-generator/blob/master/CONTRIBUTING.md
Hi @eldadfux ,
I'd like to do this task.
Hey @panz3r that will be great. Let me know if you need any help with it. Also, feel free to reach out on our Gitter community or just DM me!
https://gitter.im/appwrite/community
@panz3r assigned you to this issue, please let me know if you need any help.
@panz3r, I finally had some time to play around with the Go implementation. I have generate a demo SDK using the Appwrite API spec in this demo repo: https://github.com/aw-tests/sdk-for-go
When I run this example code:
package main
import (
"fmt"
"os"
"github.com/aw-tests/sdk-for-go"
)
func main() {
var client := appwrite.Client{}
client.SetProject("")
client.SetKey("")
var service := appwrite.Avatars{
client: &client
}
var response, error := service.GetBrowser("aa")
if error != nil {
panic(error)
}
fmt.Println(response)
}
I get the following errors:
go: finding github.com/aw-tests/sdk-for-go latest
go: downloading github.com/aw-tests/sdk-for-go v0.0.0-20200128164133-02ad4443fc25
go: extracting github.com/aw-tests/sdk-for-go v0.0.0-20200128164133-02ad4443fc25
# command-line-arguments
./main.go:10:16: syntax error: unexpected :=, expecting =
./main.go:15:17: syntax error: unexpected :=, expecting =
./main.go:16:24: syntax error: unexpected newline, expecting comma or }
./main.go:19:25: syntax error: unexpected :=, expecting =
Any idea how can we fix this?
Hi @eldadfux ,
package main import ( "fmt" "os" "github.com/aw-tests/sdk-for-go" ) func main() { var client := appwrite.Client{}
This line should be
client := appwrite.Client{}
client.SetProject("") client.SetKey("") var service := appwrite.Avatars{
This one should be:
service := appwrite.Avatars{
but there's an issue with the generated SDK, since client is a private field of the Avatars struct it cannot be set this way, to fix this there are 2 ways:
- Add a method
New{{ServiceName}}Service(clt *Client)to the generated SDK - make the
clientfield public
I'd advice for the first one. The method would look like this
func NewAvatars(clt *Client) *Avatars {
return &Avatars{
client: clt,
}
}
client: &client } var response, error := service.GetBrowser("aa")
This one also should be
response, error := service.GetBrowser("aa", 100, 100, 80)
N.B: All 4 params are required.
if error != nil { panic(error) } fmt.Println(response) }
@eldadfux Can I work on this?
@Suven-p Just do it. I implemented some more functions. One big thing that is missing, is the http streaming client support.
Where is streaming used?
Ah… not streaming. I mean chunked/resumable uploads. See https://github.com/appwrite/sdk-generator/pull/353#discussion_r844861313
https://github.com/appwrite/sdk-generator/blob/55f8d82d90287a4f69b26297d559822e1d9475c7/templates/go/client.go.twig#L311 There doesn't seem to be a result field in current version of appwrite. Was it present in older versions of appwrite?
@phaus https://github.com/appwrite/sdk-generator/pull/647 is getting quite large. Should I split the PR?
My PR was also quite big: https://github.com/appwrite/sdk-generator/pull/353 Maybe @lohanidamodar or @abnegate can have a look and provide some feedback :-)
This doesn't work with appwrite 1.3.1 because optional parameters do not accept falsy values. For example: when creating string attribute on a collection without a default value, older version allowed using empty string as default value. But in appwrite 1.3.1 if the parameter is sent it should be a valid value ie not an empty string. I am not sure how to filter out those values.
@phaus When creating an integer attribute on a collection, the user has to pass in argument for default since Go does not have optional arguments. For string arguments it can be ignored if it is an empty string. However for integer and float the user might have meant no default argument or default argument of 0. How should this be handled?
@Suven-p If I found some time again, I can have a look. Do you have any specific code where is issue is located?
I dont have an example in Go but here's the equivalent method in python
def create_float_attribute(self, database_id, collection_id, key, required, min = None, max = None, default = None, array = None):
Here the default value for min, max and default parameters is None which means user doesn't want to specify them I don't see any way to implement this in Go.
@Suven-p We can use optional variadics like "..." or use a pointer I guess
Variadics would need to be of type interface{} and that would forego typechecking. Pointers don't allow literals like 23. I was thinking of doing functional options. It would be a struct for each endpoint but that's probably the best way.
Hey @eldadfux , plz assign it to me i would really love to work on this 😄
Me and @mirkobrombin are happy to take care of the Go SDK generator ✌🏼
Any update on this?