This SDK is compatible with Appwrite server version 1.8.x. For older versions, please check previous releases.
Appwrite is an open-source backend as a service server that abstract and simplify complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way. Use the Go SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools. For full API documentation and tutorials go to https://appwrite.io/docs
Initialize your go module if you haven't already:
go mod init <YOUR_MODULE_NAME>
To install using go get
:
go get github.com/appwrite/sdk-for-go
-
Clone this repo.
-
Create a project and within this project a collection.
-
Configure the documents in the collection to have a attribute
key
=hello
. -
Then inject these environment variables:
export YOUR_ENDPOINT=https://<REGION>.cloud.appwrite.io/v1 export YOUR_PROJECT_ID=616a09..0180 export YOUR_KEY=7055781..cd95 export DATABASE_ID=616a09..0180 export COLLECTION_ID=616a09..20180
-
Create
main.go
file with:package main import ( "log" "os" "time" "github.com/appwrite/sdk-for-go/appwrite" "github.com/appwrite/sdk-for-go/id" ) func main() { client := appwrite.NewClient( appwrite.WithEndpoint(os.Getenv("YOUR_ENDPOINT")), appwrite.WithProject(os.Getenv("YOUR_PROJECT_ID")), appwrite.WithKey(os.Getenv("YOUR_KEY")), ) databases := appwrite.NewDatabases(client) data := map[string]interface{}{ "hello": "world", } doc, err := databases.CreateDocument( os.Getenv("DATABASE_ID"), os.Getenv("COLLECTION_ID"), id.Unique(), data, ) if err != nil { log.Printf("Error creating document: %v", err) } log.Printf("Created document: %v", doc) }
-
After that, run the following
go run main.go
-
You should see the following output:
2021/10/16 03:41:17 Created document: map[$collection:616a095b20180 $id:616a2dbd4df16 $permissions:map[read:[] write:[]] hello:world]
This library is auto-generated by Appwrite custom SDK Generator. To learn more about how you can help us improve this SDK, please check the contribution guide before sending a pull-request.
Please see the BSD-3-Clause license file for more information.