1
0
Fork 0
mirror of synced 2024-09-29 08:51:28 +13:00

Updated GO lib

This commit is contained in:
Eldad Fux 2020-01-28 16:22:13 +02:00
parent 3560bbebde
commit 95fa33ff04
59 changed files with 2319 additions and 0 deletions

12
app/sdks/go/LICENSE Normal file
View file

@ -0,0 +1,12 @@
Copyright (c) 2019 Appwrite (https://appwrite.io) and individual contributors.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name Appwrite nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

24
app/sdks/go/README.md Normal file
View file

@ -0,0 +1,24 @@
# Appwrite SDK for Go
![License](https://img.shields.io/github/license/appwrite/sdk-for-go.svg?v=1)
![Version](https://img.shields.io/badge/api%20version-0.4.0-blue.svg?v=1)
**This SDK is compatible with Appwrite server version . For older versions, please check previous releases.**
Appwrite backend as a service cuts up to 70% of the time and costs required for building a modern application. We abstract and simplify common development tasks behind a REST APIs, to help you develop your app in a fast and secure way. For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs)
![Appwrite](https://appwrite.io/images/github.png)
## Installation
To install using `go get`:
```bash
go get github.com/appwrite/sdk-for-go
```
## License
Please see the [BSD-3-Clause license](https://raw.githubusercontent.com/appwrite/appwrite/master/LICENSE) file for more information.

103
app/sdks/go/avatars.go Normal file
View file

@ -0,0 +1,103 @@
package appwrite
import (
"strings"
)
// Avatars service
type Avatars struct {
client *Client
}
// GetBrowser you can use this endpoint to show different browser icons to
// your users. The code argument receives the browser code as it appears in
// your user /account/sessions endpoint. Use width, height and quality
// arguments to change the output settings.
func (srv *Avatars) GetBrowser(Code string, Width int, Height int, Quality int) (map[string]interface{}, error) {
r := strings.NewReplacer("{code}", Code)
path := r.Replace("/avatars/browsers/{code}")
params := map[string]interface{}{
"width": Width,
"height": Height,
"quality": Quality,
}
return srv.client.Call("GET", path, nil, params)
}
// GetCreditCard need to display your users with your billing method or their
// payment methods? The credit card endpoint will return you the icon of the
// credit card provider you need. Use width, height and quality arguments to
// change the output settings.
func (srv *Avatars) GetCreditCard(Code string, Width int, Height int, Quality int) (map[string]interface{}, error) {
r := strings.NewReplacer("{code}", Code)
path := r.Replace("/avatars/credit-cards/{code}")
params := map[string]interface{}{
"width": Width,
"height": Height,
"quality": Quality,
}
return srv.client.Call("GET", path, nil, params)
}
// GetFavicon use this endpoint to fetch the favorite icon (AKA favicon) of a
// any remote website URL.
func (srv *Avatars) GetFavicon(Url string) (map[string]interface{}, error) {
path := "/avatars/favicon"
params := map[string]interface{}{
"url": Url,
}
return srv.client.Call("GET", path, nil, params)
}
// GetFlag you can use this endpoint to show different country flags icons to
// your users. The code argument receives the 2 letter country code. Use
// width, height and quality arguments to change the output settings.
func (srv *Avatars) GetFlag(Code string, Width int, Height int, Quality int) (map[string]interface{}, error) {
r := strings.NewReplacer("{code}", Code)
path := r.Replace("/avatars/flags/{code}")
params := map[string]interface{}{
"width": Width,
"height": Height,
"quality": Quality,
}
return srv.client.Call("GET", path, nil, params)
}
// GetImage use this endpoint to fetch a remote image URL and crop it to any
// image size you want. This endpoint is very useful if you need to crop and
// display remote images in your app or in case you want to make sure a 3rd
// party image is properly served using a TLS protocol.
func (srv *Avatars) GetImage(Url string, Width int, Height int) (map[string]interface{}, error) {
path := "/avatars/image"
params := map[string]interface{}{
"url": Url,
"width": Width,
"height": Height,
}
return srv.client.Call("GET", path, nil, params)
}
// GetQR converts a given plain text to a QR code image. You can use the query
// parameters to change the size and style of the resulting image.
func (srv *Avatars) GetQR(Text string, Size int, Margin int, Download int) (map[string]interface{}, error) {
path := "/avatars/qr"
params := map[string]interface{}{
"text": Text,
"size": Size,
"margin": Margin,
"download": Download,
}
return srv.client.Call("GET", path, nil, params)
}

119
app/sdks/go/client.go Normal file
View file

@ -0,0 +1,119 @@
package appwrite
import (
"encoding/json"
"io/ioutil"
"net/http"
"net/url"
"strings"
)
// Client is the client struct to access Appwrite services
type Client struct {
client *http.Client
endpoint string
headers map[string]string
selfSigned bool
}
// SetEndpoint sets the default endpoint to which the Client connects to
func (clt *Client) SetEndpoint(endpoint string) {
clt.endpoint = endpoint
}
// SetSelfSigned sets the condition that specify if the Client should allow connections to a server using a self-signed certificate
func (clt *Client) SetSelfSigned(status bool) {
clt.selfSigned = status
}
// AddHeader add a new custom header that the Client should send on each request
func (clt *Client) AddHeader(key string, value string) {
clt.headers[key] = value
}
// SetProjectHeader add the 'X-Appwrite-Project' header for the Client. Your Appwrite project ID
func (clt *Client) SetProjectHeader(value string) {
clt.headers["X-Appwrite-Project"] = value
}
// SetKeyHeader add the 'X-Appwrite-Key' header for the Client. Your Appwrite project secret key
func (clt *Client) SetKeyHeader(value string) {
clt.headers["X-Appwrite-Key"] = value
}
// SetLocaleHeader add the 'X-Appwrite-Locale' header for the Client.
func (clt *Client) SetLocaleHeader(value string) {
clt.headers["X-Appwrite-Locale"] = value
}
// SetModeHeader add the 'X-Appwrite-Mode' header for the Client.
func (clt *Client) SetModeHeader(value string) {
clt.headers["X-Appwrite-Mode"] = value
}
// Call an API using Client
func (clt *Client) Call(method string, path string, headers map[string]interface{}, params map[string]interface{}) (map[string]interface{}, error) {
if clt.client == nil {
// Create HTTP client
clt.client = &http.Client{}
}
if clt.selfSigned {
// Allow self signed requests
}
urlPath := clt.endpoint + path
isGet := strings.ToUpper(method) == "GET"
var reqBody *strings.Reader
if !isGet {
frm := url.Values{}
for key, val := range params {
frm.Add(key, ToString(val))
}
reqBody = strings.NewReader(frm.Encode())
}
// Create and modify HTTP request before sending
req, err := http.NewRequest(method, urlPath, reqBody)
if err != nil {
return nil, err
}
// Set Client headers
for key, val := range clt.headers {
req.Header.Set(key, ToString(val))
}
// Set Custom headers
for key, val := range headers {
req.Header.Set(key, ToString(val))
}
if isGet {
q := req.URL.Query()
for key, val := range params {
q.Add(key, ToString(val))
}
req.URL.RawQuery = q.Encode()
}
// Make request
response, err := clt.client.Do(req)
if err != nil {
return nil, err
}
// Handle response
defer response.Body.Close()
responseData, err := ioutil.ReadAll(response.Body)
if err != nil {
return nil, err
}
var jsonResponse map[string]interface{}
json.Unmarshal(responseData, &jsonResponse)
return jsonResponse, nil
}

159
app/sdks/go/database.go Normal file
View file

@ -0,0 +1,159 @@
package appwrite
import (
"strings"
)
// Database service
type Database struct {
client *Client
}
// ListCollections get a list of all the user collections. You can use the
// query params to filter your results. On admin mode, this endpoint will
// return a list of all of the project collections. [Learn more about
// different API modes](/docs/admin).
func (srv *Database) ListCollections(Search string, Limit int, Offset int, OrderType string) (map[string]interface{}, error) {
path := "/database"
params := map[string]interface{}{
"search": Search,
"limit": Limit,
"offset": Offset,
"orderType": OrderType,
}
return srv.client.Call("GET", path, nil, params)
}
// CreateCollection create a new Collection.
func (srv *Database) CreateCollection(Name string, Read []interface{}, Write []interface{}, Rules []interface{}) (map[string]interface{}, error) {
path := "/database"
params := map[string]interface{}{
"name": Name,
"read": Read,
"write": Write,
"rules": Rules,
}
return srv.client.Call("POST", path, nil, params)
}
// GetCollection get collection by its unique ID. This endpoint response
// returns a JSON object with the collection metadata.
func (srv *Database) GetCollection(CollectionId string) (map[string]interface{}, error) {
r := strings.NewReplacer("{collectionId}", CollectionId)
path := r.Replace("/database/{collectionId}")
params := map[string]interface{}{
}
return srv.client.Call("GET", path, nil, params)
}
// UpdateCollection update collection by its unique ID.
func (srv *Database) UpdateCollection(CollectionId string, Name string, Read []interface{}, Write []interface{}, Rules []interface{}) (map[string]interface{}, error) {
r := strings.NewReplacer("{collectionId}", CollectionId)
path := r.Replace("/database/{collectionId}")
params := map[string]interface{}{
"name": Name,
"read": Read,
"write": Write,
"rules": Rules,
}
return srv.client.Call("PUT", path, nil, params)
}
// DeleteCollection delete a collection by its unique ID. Only users with
// write permissions have access to delete this resource.
func (srv *Database) DeleteCollection(CollectionId string) (map[string]interface{}, error) {
r := strings.NewReplacer("{collectionId}", CollectionId)
path := r.Replace("/database/{collectionId}")
params := map[string]interface{}{
}
return srv.client.Call("DELETE", path, nil, params)
}
// ListDocuments get a list of all the user documents. You can use the query
// params to filter your results. On admin mode, this endpoint will return a
// list of all of the project documents. [Learn more about different API
// modes](/docs/admin).
func (srv *Database) ListDocuments(CollectionId string, Filters []interface{}, Offset int, Limit int, OrderField string, OrderType string, OrderCast string, Search string, First int, Last int) (map[string]interface{}, error) {
r := strings.NewReplacer("{collectionId}", CollectionId)
path := r.Replace("/database/{collectionId}/documents")
params := map[string]interface{}{
"filters": Filters,
"offset": Offset,
"limit": Limit,
"order-field": OrderField,
"order-type": OrderType,
"order-cast": OrderCast,
"search": Search,
"first": First,
"last": Last,
}
return srv.client.Call("GET", path, nil, params)
}
// CreateDocument create a new Document.
func (srv *Database) CreateDocument(CollectionId string, Data string, Read []interface{}, Write []interface{}, ParentDocument string, ParentProperty string, ParentPropertyType string) (map[string]interface{}, error) {
r := strings.NewReplacer("{collectionId}", CollectionId)
path := r.Replace("/database/{collectionId}/documents")
params := map[string]interface{}{
"data": Data,
"read": Read,
"write": Write,
"parentDocument": ParentDocument,
"parentProperty": ParentProperty,
"parentPropertyType": ParentPropertyType,
}
return srv.client.Call("POST", path, nil, params)
}
// GetDocument get document by its unique ID. This endpoint response returns a
// JSON object with the document data.
func (srv *Database) GetDocument(CollectionId string, DocumentId string) (map[string]interface{}, error) {
r := strings.NewReplacer("{collectionId}", CollectionId, "{documentId}", DocumentId)
path := r.Replace("/database/{collectionId}/documents/{documentId}")
params := map[string]interface{}{
}
return srv.client.Call("GET", path, nil, params)
}
// UpdateDocument
func (srv *Database) UpdateDocument(CollectionId string, DocumentId string, Data string, Read []interface{}, Write []interface{}) (map[string]interface{}, error) {
r := strings.NewReplacer("{collectionId}", CollectionId, "{documentId}", DocumentId)
path := r.Replace("/database/{collectionId}/documents/{documentId}")
params := map[string]interface{}{
"data": Data,
"read": Read,
"write": Write,
}
return srv.client.Call("PATCH", path, nil, params)
}
// DeleteDocument delete document by its unique ID. This endpoint deletes only
// the parent documents, his attributes and relations to other documents.
// Child documents **will not** be deleted.
func (srv *Database) DeleteDocument(CollectionId string, DocumentId string) (map[string]interface{}, error) {
r := strings.NewReplacer("{collectionId}", CollectionId, "{documentId}", DocumentId)
path := r.Replace("/database/{collectionId}/documents/{documentId}")
params := map[string]interface{}{
}
return srv.client.Call("DELETE", path, nil, params)
}

View file

@ -0,0 +1,29 @@
package main
import (
"fmt"
"os"
"github.com/appwrite/sdk-for-go"
)
func main() {
// Create a Client
var client := appwrite.Client{}
// Set Client required headers
client.SetProject("")
client.SetKey("")
// Create a new Avatars service passing Client
var srv := appwrite.Avatars{
client: &client
}
// Call GetBrowser method and handle results
var res, err := srv.GetBrowser("aa")
if err != nil {
panic(err)
}
fmt.Println(res)
}

View file

@ -0,0 +1,29 @@
package main
import (
"fmt"
"os"
"github.com/appwrite/sdk-for-go"
)
func main() {
// Create a Client
var client := appwrite.Client{}
// Set Client required headers
client.SetProject("")
client.SetKey("")
// Create a new Avatars service passing Client
var srv := appwrite.Avatars{
client: &client
}
// Call GetCreditCard method and handle results
var res, err := srv.GetCreditCard("amex")
if err != nil {
panic(err)
}
fmt.Println(res)
}

View file

@ -0,0 +1,29 @@
package main
import (
"fmt"
"os"
"github.com/appwrite/sdk-for-go"
)
func main() {
// Create a Client
var client := appwrite.Client{}
// Set Client required headers
client.SetProject("")
client.SetKey("")
// Create a new Avatars service passing Client
var srv := appwrite.Avatars{
client: &client
}
// Call GetFavicon method and handle results
var res, err := srv.GetFavicon("https://example.com")
if err != nil {
panic(err)
}
fmt.Println(res)
}

View file

@ -0,0 +1,29 @@
package main
import (
"fmt"
"os"
"github.com/appwrite/sdk-for-go"
)
func main() {
// Create a Client
var client := appwrite.Client{}
// Set Client required headers
client.SetProject("")
client.SetKey("")
// Create a new Avatars service passing Client
var srv := appwrite.Avatars{
client: &client
}
// Call GetFlag method and handle results
var res, err := srv.GetFlag("af")
if err != nil {
panic(err)
}
fmt.Println(res)
}

View file

@ -0,0 +1,29 @@
package main
import (
"fmt"
"os"
"github.com/appwrite/sdk-for-go"
)
func main() {
// Create a Client
var client := appwrite.Client{}
// Set Client required headers
client.SetProject("")
client.SetKey("")
// Create a new Avatars service passing Client
var srv := appwrite.Avatars{
client: &client
}
// Call GetImage method and handle results
var res, err := srv.GetImage("https://example.com")
if err != nil {
panic(err)
}
fmt.Println(res)
}

View file

@ -0,0 +1,29 @@
package main
import (
"fmt"
"os"
"github.com/appwrite/sdk-for-go"
)
func main() {
// Create a Client
var client := appwrite.Client{}
// Set Client required headers
client.SetProject("")
client.SetKey("")
// Create a new Avatars service passing Client
var srv := appwrite.Avatars{
client: &client
}
// Call GetQR method and handle results
var res, err := srv.GetQR("[TEXT]")
if err != nil {
panic(err)
}
fmt.Println(res)
}

View file

@ -0,0 +1,29 @@
package main
import (
"fmt"
"os"
"github.com/appwrite/sdk-for-go"
)
func main() {
// Create a Client
var client := appwrite.Client{}
// Set Client required headers
client.SetProject("")
client.SetKey("")
// Create a new Database service passing Client
var srv := appwrite.Database{
client: &client
}
// Call CreateCollection method and handle results
var res, err := srv.CreateCollection("[NAME]", [], [], [])
if err != nil {
panic(err)
}
fmt.Println(res)
}

View file

@ -0,0 +1,29 @@
package main
import (
"fmt"
"os"
"github.com/appwrite/sdk-for-go"
)
func main() {
// Create a Client
var client := appwrite.Client{}
// Set Client required headers
client.SetProject("")
client.SetKey("")
// Create a new Database service passing Client
var srv := appwrite.Database{
client: &client
}
// Call CreateDocument method and handle results
var res, err := srv.CreateDocument("[COLLECTION_ID]", "{}", [], [])
if err != nil {
panic(err)
}
fmt.Println(res)
}

View file

@ -0,0 +1,29 @@
package main
import (
"fmt"
"os"
"github.com/appwrite/sdk-for-go"
)
func main() {
// Create a Client
var client := appwrite.Client{}
// Set Client required headers
client.SetProject("")
client.SetKey("")
// Create a new Database service passing Client
var srv := appwrite.Database{
client: &client
}
// Call DeleteCollection method and handle results
var res, err := srv.DeleteCollection("[COLLECTION_ID]")
if err != nil {
panic(err)
}
fmt.Println(res)
}

View file

@ -0,0 +1,29 @@
package main
import (
"fmt"
"os"
"github.com/appwrite/sdk-for-go"
)
func main() {
// Create a Client
var client := appwrite.Client{}
// Set Client required headers
client.SetProject("")
client.SetKey("")
// Create a new Database service passing Client
var srv := appwrite.Database{
client: &client
}
// Call DeleteDocument method and handle results
var res, err := srv.DeleteDocument("[COLLECTION_ID]", "[DOCUMENT_ID]")
if err != nil {
panic(err)
}
fmt.Println(res)
}

View file

@ -0,0 +1,29 @@
package main
import (
"fmt"
"os"
"github.com/appwrite/sdk-for-go"
)
func main() {
// Create a Client
var client := appwrite.Client{}
// Set Client required headers
client.SetProject("")
client.SetKey("")
// Create a new Database service passing Client
var srv := appwrite.Database{
client: &client
}
// Call GetCollection method and handle results
var res, err := srv.GetCollection("[COLLECTION_ID]")
if err != nil {
panic(err)
}
fmt.Println(res)
}

View file

@ -0,0 +1,29 @@
package main
import (
"fmt"
"os"
"github.com/appwrite/sdk-for-go"
)
func main() {
// Create a Client
var client := appwrite.Client{}
// Set Client required headers
client.SetProject("")
client.SetKey("")
// Create a new Database service passing Client
var srv := appwrite.Database{
client: &client
}
// Call GetDocument method and handle results
var res, err := srv.GetDocument("[COLLECTION_ID]", "[DOCUMENT_ID]")
if err != nil {
panic(err)
}
fmt.Println(res)
}

View file

@ -0,0 +1,29 @@
package main
import (
"fmt"
"os"
"github.com/appwrite/sdk-for-go"
)
func main() {
// Create a Client
var client := appwrite.Client{}
// Set Client required headers
client.SetProject("")
client.SetKey("")
// Create a new Database service passing Client
var srv := appwrite.Database{
client: &client
}
// Call ListCollections method and handle results
var res, err := srv.ListCollections()
if err != nil {
panic(err)
}
fmt.Println(res)
}

View file

@ -0,0 +1,29 @@
package main
import (
"fmt"
"os"
"github.com/appwrite/sdk-for-go"
)
func main() {
// Create a Client
var client := appwrite.Client{}
// Set Client required headers
client.SetProject("")
client.SetKey("")
// Create a new Database service passing Client
var srv := appwrite.Database{
client: &client
}
// Call ListDocuments method and handle results
var res, err := srv.ListDocuments("[COLLECTION_ID]")
if err != nil {
panic(err)
}
fmt.Println(res)
}

View file

@ -0,0 +1,29 @@
package main
import (
"fmt"
"os"
"github.com/appwrite/sdk-for-go"
)
func main() {
// Create a Client
var client := appwrite.Client{}
// Set Client required headers
client.SetProject("")
client.SetKey("")
// Create a new Database service passing Client
var srv := appwrite.Database{
client: &client
}
// Call UpdateCollection method and handle results
var res, err := srv.UpdateCollection("[COLLECTION_ID]", "[NAME]", [], [])
if err != nil {
panic(err)
}
fmt.Println(res)
}

View file

@ -0,0 +1,29 @@
package main
import (
"fmt"
"os"
"github.com/appwrite/sdk-for-go"
)
func main() {
// Create a Client
var client := appwrite.Client{}
// Set Client required headers
client.SetProject("")
client.SetKey("")
// Create a new Database service passing Client
var srv := appwrite.Database{
client: &client
}
// Call UpdateDocument method and handle results
var res, err := srv.UpdateDocument("[COLLECTION_ID]", "[DOCUMENT_ID]", "{}", [], [])
if err != nil {
panic(err)
}
fmt.Println(res)
}

View file

@ -0,0 +1,29 @@
package main
import (
"fmt"
"os"
"github.com/appwrite/sdk-for-go"
)
func main() {
// Create a Client
var client := appwrite.Client{}
// Set Client required headers
client.SetProject("")
client.SetKey("")
// Create a new Locale service passing Client
var srv := appwrite.Locale{
client: &client
}
// Call GetContinents method and handle results
var res, err := srv.GetContinents()
if err != nil {
panic(err)
}
fmt.Println(res)
}

View file

@ -0,0 +1,29 @@
package main
import (
"fmt"
"os"
"github.com/appwrite/sdk-for-go"
)
func main() {
// Create a Client
var client := appwrite.Client{}
// Set Client required headers
client.SetProject("")
client.SetKey("")
// Create a new Locale service passing Client
var srv := appwrite.Locale{
client: &client
}
// Call GetCountriesEU method and handle results
var res, err := srv.GetCountriesEU()
if err != nil {
panic(err)
}
fmt.Println(res)
}

View file

@ -0,0 +1,29 @@
package main
import (
"fmt"
"os"
"github.com/appwrite/sdk-for-go"
)
func main() {
// Create a Client
var client := appwrite.Client{}
// Set Client required headers
client.SetProject("")
client.SetKey("")
// Create a new Locale service passing Client
var srv := appwrite.Locale{
client: &client
}
// Call GetCountriesPhones method and handle results
var res, err := srv.GetCountriesPhones()
if err != nil {
panic(err)
}
fmt.Println(res)
}

View file

@ -0,0 +1,29 @@
package main
import (
"fmt"
"os"
"github.com/appwrite/sdk-for-go"
)
func main() {
// Create a Client
var client := appwrite.Client{}
// Set Client required headers
client.SetProject("")
client.SetKey("")
// Create a new Locale service passing Client
var srv := appwrite.Locale{
client: &client
}
// Call GetCountries method and handle results
var res, err := srv.GetCountries()
if err != nil {
panic(err)
}
fmt.Println(res)
}

View file

@ -0,0 +1,29 @@
package main
import (
"fmt"
"os"
"github.com/appwrite/sdk-for-go"
)
func main() {
// Create a Client
var client := appwrite.Client{}
// Set Client required headers
client.SetProject("")
client.SetKey("")
// Create a new Locale service passing Client
var srv := appwrite.Locale{
client: &client
}
// Call GetCurrencies method and handle results
var res, err := srv.GetCurrencies()
if err != nil {
panic(err)
}
fmt.Println(res)
}

View file

@ -0,0 +1,29 @@
package main
import (
"fmt"
"os"
"github.com/appwrite/sdk-for-go"
)
func main() {
// Create a Client
var client := appwrite.Client{}
// Set Client required headers
client.SetProject("")
client.SetKey("")
// Create a new Locale service passing Client
var srv := appwrite.Locale{
client: &client
}
// Call GetLocale method and handle results
var res, err := srv.GetLocale()
if err != nil {
panic(err)
}
fmt.Println(res)
}

View file

@ -0,0 +1,29 @@
package main
import (
"fmt"
"os"
"github.com/appwrite/sdk-for-go"
)
func main() {
// Create a Client
var client := appwrite.Client{}
// Set Client required headers
client.SetProject("")
client.SetKey("")
// Create a new Storage service passing Client
var srv := appwrite.Storage{
client: &client
}
// Call CreateFile method and handle results
var res, err := srv.CreateFile(file, [], [])
if err != nil {
panic(err)
}
fmt.Println(res)
}

View file

@ -0,0 +1,29 @@
package main
import (
"fmt"
"os"
"github.com/appwrite/sdk-for-go"
)
func main() {
// Create a Client
var client := appwrite.Client{}
// Set Client required headers
client.SetProject("")
client.SetKey("")
// Create a new Storage service passing Client
var srv := appwrite.Storage{
client: &client
}
// Call DeleteFile method and handle results
var res, err := srv.DeleteFile("[FILE_ID]")
if err != nil {
panic(err)
}
fmt.Println(res)
}

View file

@ -0,0 +1,29 @@
package main
import (
"fmt"
"os"
"github.com/appwrite/sdk-for-go"
)
func main() {
// Create a Client
var client := appwrite.Client{}
// Set Client required headers
client.SetProject("")
client.SetKey("")
// Create a new Storage service passing Client
var srv := appwrite.Storage{
client: &client
}
// Call GetFileDownload method and handle results
var res, err := srv.GetFileDownload("[FILE_ID]")
if err != nil {
panic(err)
}
fmt.Println(res)
}

View file

@ -0,0 +1,29 @@
package main
import (
"fmt"
"os"
"github.com/appwrite/sdk-for-go"
)
func main() {
// Create a Client
var client := appwrite.Client{}
// Set Client required headers
client.SetProject("")
client.SetKey("")
// Create a new Storage service passing Client
var srv := appwrite.Storage{
client: &client
}
// Call GetFilePreview method and handle results
var res, err := srv.GetFilePreview("[FILE_ID]")
if err != nil {
panic(err)
}
fmt.Println(res)
}

View file

@ -0,0 +1,29 @@
package main
import (
"fmt"
"os"
"github.com/appwrite/sdk-for-go"
)
func main() {
// Create a Client
var client := appwrite.Client{}
// Set Client required headers
client.SetProject("")
client.SetKey("")
// Create a new Storage service passing Client
var srv := appwrite.Storage{
client: &client
}
// Call GetFileView method and handle results
var res, err := srv.GetFileView("[FILE_ID]")
if err != nil {
panic(err)
}
fmt.Println(res)
}

View file

@ -0,0 +1,29 @@
package main
import (
"fmt"
"os"
"github.com/appwrite/sdk-for-go"
)
func main() {
// Create a Client
var client := appwrite.Client{}
// Set Client required headers
client.SetProject("")
client.SetKey("")
// Create a new Storage service passing Client
var srv := appwrite.Storage{
client: &client
}
// Call GetFile method and handle results
var res, err := srv.GetFile("[FILE_ID]")
if err != nil {
panic(err)
}
fmt.Println(res)
}

View file

@ -0,0 +1,29 @@
package main
import (
"fmt"
"os"
"github.com/appwrite/sdk-for-go"
)
func main() {
// Create a Client
var client := appwrite.Client{}
// Set Client required headers
client.SetProject("")
client.SetKey("")
// Create a new Storage service passing Client
var srv := appwrite.Storage{
client: &client
}
// Call ListFiles method and handle results
var res, err := srv.ListFiles()
if err != nil {
panic(err)
}
fmt.Println(res)
}

View file

@ -0,0 +1,29 @@
package main
import (
"fmt"
"os"
"github.com/appwrite/sdk-for-go"
)
func main() {
// Create a Client
var client := appwrite.Client{}
// Set Client required headers
client.SetProject("")
client.SetKey("")
// Create a new Storage service passing Client
var srv := appwrite.Storage{
client: &client
}
// Call UpdateFile method and handle results
var res, err := srv.UpdateFile("[FILE_ID]", [], [])
if err != nil {
panic(err)
}
fmt.Println(res)
}

View file

@ -0,0 +1,29 @@
package main
import (
"fmt"
"os"
"github.com/appwrite/sdk-for-go"
)
func main() {
// Create a Client
var client := appwrite.Client{}
// Set Client required headers
client.SetProject("")
client.SetKey("")
// Create a new Teams service passing Client
var srv := appwrite.Teams{
client: &client
}
// Call CreateTeamMembership method and handle results
var res, err := srv.CreateTeamMembership("[TEAM_ID]", "email@example.com", [], "https://example.com")
if err != nil {
panic(err)
}
fmt.Println(res)
}

View file

@ -0,0 +1,29 @@
package main
import (
"fmt"
"os"
"github.com/appwrite/sdk-for-go"
)
func main() {
// Create a Client
var client := appwrite.Client{}
// Set Client required headers
client.SetProject("")
client.SetKey("")
// Create a new Teams service passing Client
var srv := appwrite.Teams{
client: &client
}
// Call CreateTeam method and handle results
var res, err := srv.CreateTeam("[NAME]")
if err != nil {
panic(err)
}
fmt.Println(res)
}

View file

@ -0,0 +1,29 @@
package main
import (
"fmt"
"os"
"github.com/appwrite/sdk-for-go"
)
func main() {
// Create a Client
var client := appwrite.Client{}
// Set Client required headers
client.SetProject("")
client.SetKey("")
// Create a new Teams service passing Client
var srv := appwrite.Teams{
client: &client
}
// Call DeleteTeamMembership method and handle results
var res, err := srv.DeleteTeamMembership("[TEAM_ID]", "[INVITE_ID]")
if err != nil {
panic(err)
}
fmt.Println(res)
}

View file

@ -0,0 +1,29 @@
package main
import (
"fmt"
"os"
"github.com/appwrite/sdk-for-go"
)
func main() {
// Create a Client
var client := appwrite.Client{}
// Set Client required headers
client.SetProject("")
client.SetKey("")
// Create a new Teams service passing Client
var srv := appwrite.Teams{
client: &client
}
// Call DeleteTeam method and handle results
var res, err := srv.DeleteTeam("[TEAM_ID]")
if err != nil {
panic(err)
}
fmt.Println(res)
}

View file

@ -0,0 +1,29 @@
package main
import (
"fmt"
"os"
"github.com/appwrite/sdk-for-go"
)
func main() {
// Create a Client
var client := appwrite.Client{}
// Set Client required headers
client.SetProject("")
client.SetKey("")
// Create a new Teams service passing Client
var srv := appwrite.Teams{
client: &client
}
// Call GetTeamMemberships method and handle results
var res, err := srv.GetTeamMemberships("[TEAM_ID]")
if err != nil {
panic(err)
}
fmt.Println(res)
}

View file

@ -0,0 +1,29 @@
package main
import (
"fmt"
"os"
"github.com/appwrite/sdk-for-go"
)
func main() {
// Create a Client
var client := appwrite.Client{}
// Set Client required headers
client.SetProject("")
client.SetKey("")
// Create a new Teams service passing Client
var srv := appwrite.Teams{
client: &client
}
// Call GetTeam method and handle results
var res, err := srv.GetTeam("[TEAM_ID]")
if err != nil {
panic(err)
}
fmt.Println(res)
}

View file

@ -0,0 +1,29 @@
package main
import (
"fmt"
"os"
"github.com/appwrite/sdk-for-go"
)
func main() {
// Create a Client
var client := appwrite.Client{}
// Set Client required headers
client.SetProject("")
client.SetKey("")
// Create a new Teams service passing Client
var srv := appwrite.Teams{
client: &client
}
// Call ListTeams method and handle results
var res, err := srv.ListTeams()
if err != nil {
panic(err)
}
fmt.Println(res)
}

View file

@ -0,0 +1,29 @@
package main
import (
"fmt"
"os"
"github.com/appwrite/sdk-for-go"
)
func main() {
// Create a Client
var client := appwrite.Client{}
// Set Client required headers
client.SetProject("")
client.SetKey("")
// Create a new Teams service passing Client
var srv := appwrite.Teams{
client: &client
}
// Call UpdateTeam method and handle results
var res, err := srv.UpdateTeam("[TEAM_ID]", "[NAME]")
if err != nil {
panic(err)
}
fmt.Println(res)
}

View file

@ -0,0 +1,29 @@
package main
import (
"fmt"
"os"
"github.com/appwrite/sdk-for-go"
)
func main() {
// Create a Client
var client := appwrite.Client{}
// Set Client required headers
client.SetProject("")
client.SetKey("")
// Create a new Users service passing Client
var srv := appwrite.Users{
client: &client
}
// Call CreateUser method and handle results
var res, err := srv.CreateUser("email@example.com", "password")
if err != nil {
panic(err)
}
fmt.Println(res)
}

View file

@ -0,0 +1,29 @@
package main
import (
"fmt"
"os"
"github.com/appwrite/sdk-for-go"
)
func main() {
// Create a Client
var client := appwrite.Client{}
// Set Client required headers
client.SetProject("")
client.SetKey("")
// Create a new Users service passing Client
var srv := appwrite.Users{
client: &client
}
// Call DeleteUserSession method and handle results
var res, err := srv.DeleteUserSession("[USER_ID]", "[SESSION_ID]")
if err != nil {
panic(err)
}
fmt.Println(res)
}

View file

@ -0,0 +1,29 @@
package main
import (
"fmt"
"os"
"github.com/appwrite/sdk-for-go"
)
func main() {
// Create a Client
var client := appwrite.Client{}
// Set Client required headers
client.SetProject("")
client.SetKey("")
// Create a new Users service passing Client
var srv := appwrite.Users{
client: &client
}
// Call DeleteUserSessions method and handle results
var res, err := srv.DeleteUserSessions("[USER_ID]")
if err != nil {
panic(err)
}
fmt.Println(res)
}

View file

@ -0,0 +1,29 @@
package main
import (
"fmt"
"os"
"github.com/appwrite/sdk-for-go"
)
func main() {
// Create a Client
var client := appwrite.Client{}
// Set Client required headers
client.SetProject("")
client.SetKey("")
// Create a new Users service passing Client
var srv := appwrite.Users{
client: &client
}
// Call GetUserLogs method and handle results
var res, err := srv.GetUserLogs("[USER_ID]")
if err != nil {
panic(err)
}
fmt.Println(res)
}

View file

@ -0,0 +1,29 @@
package main
import (
"fmt"
"os"
"github.com/appwrite/sdk-for-go"
)
func main() {
// Create a Client
var client := appwrite.Client{}
// Set Client required headers
client.SetProject("")
client.SetKey("")
// Create a new Users service passing Client
var srv := appwrite.Users{
client: &client
}
// Call GetUserPrefs method and handle results
var res, err := srv.GetUserPrefs("[USER_ID]")
if err != nil {
panic(err)
}
fmt.Println(res)
}

View file

@ -0,0 +1,29 @@
package main
import (
"fmt"
"os"
"github.com/appwrite/sdk-for-go"
)
func main() {
// Create a Client
var client := appwrite.Client{}
// Set Client required headers
client.SetProject("")
client.SetKey("")
// Create a new Users service passing Client
var srv := appwrite.Users{
client: &client
}
// Call GetUserSessions method and handle results
var res, err := srv.GetUserSessions("[USER_ID]")
if err != nil {
panic(err)
}
fmt.Println(res)
}

View file

@ -0,0 +1,29 @@
package main
import (
"fmt"
"os"
"github.com/appwrite/sdk-for-go"
)
func main() {
// Create a Client
var client := appwrite.Client{}
// Set Client required headers
client.SetProject("")
client.SetKey("")
// Create a new Users service passing Client
var srv := appwrite.Users{
client: &client
}
// Call GetUser method and handle results
var res, err := srv.GetUser("[USER_ID]")
if err != nil {
panic(err)
}
fmt.Println(res)
}

View file

@ -0,0 +1,29 @@
package main
import (
"fmt"
"os"
"github.com/appwrite/sdk-for-go"
)
func main() {
// Create a Client
var client := appwrite.Client{}
// Set Client required headers
client.SetProject("")
client.SetKey("")
// Create a new Users service passing Client
var srv := appwrite.Users{
client: &client
}
// Call ListUsers method and handle results
var res, err := srv.ListUsers()
if err != nil {
panic(err)
}
fmt.Println(res)
}

View file

@ -0,0 +1,29 @@
package main
import (
"fmt"
"os"
"github.com/appwrite/sdk-for-go"
)
func main() {
// Create a Client
var client := appwrite.Client{}
// Set Client required headers
client.SetProject("")
client.SetKey("")
// Create a new Users service passing Client
var srv := appwrite.Users{
client: &client
}
// Call UpdateUserPrefs method and handle results
var res, err := srv.UpdateUserPrefs("[USER_ID]", "")
if err != nil {
panic(err)
}
fmt.Println(res)
}

View file

@ -0,0 +1,29 @@
package main
import (
"fmt"
"os"
"github.com/appwrite/sdk-for-go"
)
func main() {
// Create a Client
var client := appwrite.Client{}
// Set Client required headers
client.SetProject("")
client.SetKey("")
// Create a new Users service passing Client
var srv := appwrite.Users{
client: &client
}
// Call UpdateUserStatus method and handle results
var res, err := srv.UpdateUserStatus("[USER_ID]", "1")
if err != nil {
panic(err)
}
fmt.Println(res)
}

80
app/sdks/go/locale.go Normal file
View file

@ -0,0 +1,80 @@
package appwrite
import (
)
// Locale service
type Locale struct {
client *Client
}
// GetLocale get the current user location based on IP. Returns an object with
// user country code, country name, continent name, continent code, ip address
// and suggested currency. You can use the locale header to get the data in a
// supported language.
//
// ([IP Geolocation by DB-IP](https://db-ip.com))
func (srv *Locale) GetLocale() (map[string]interface{}, error) {
path := "/locale"
params := map[string]interface{}{
}
return srv.client.Call("GET", path, nil, params)
}
// GetContinents list of all continents. You can use the locale header to get
// the data in a supported language.
func (srv *Locale) GetContinents() (map[string]interface{}, error) {
path := "/locale/continents"
params := map[string]interface{}{
}
return srv.client.Call("GET", path, nil, params)
}
// GetCountries list of all countries. You can use the locale header to get
// the data in a supported language.
func (srv *Locale) GetCountries() (map[string]interface{}, error) {
path := "/locale/countries"
params := map[string]interface{}{
}
return srv.client.Call("GET", path, nil, params)
}
// GetCountriesEU list of all countries that are currently members of the EU.
// You can use the locale header to get the data in a supported language.
func (srv *Locale) GetCountriesEU() (map[string]interface{}, error) {
path := "/locale/countries/eu"
params := map[string]interface{}{
}
return srv.client.Call("GET", path, nil, params)
}
// GetCountriesPhones list of all countries phone codes. You can use the
// locale header to get the data in a supported language.
func (srv *Locale) GetCountriesPhones() (map[string]interface{}, error) {
path := "/locale/countries/phones"
params := map[string]interface{}{
}
return srv.client.Call("GET", path, nil, params)
}
// GetCurrencies list of all currencies, including currency symol, name,
// plural, and decimal digits for all major and minor currencies. You can use
// the locale header to get the data in a supported language.
func (srv *Locale) GetCurrencies() (map[string]interface{}, error) {
path := "/locale/currencies"
params := map[string]interface{}{
}
return srv.client.Call("GET", path, nil, params)
}

6
app/sdks/go/main.go Normal file
View file

@ -0,0 +1,6 @@
package appwrite
// NewClient initializes a new Appwrite client
func NewClient() Client {
return Client{}
}

126
app/sdks/go/storage.go Normal file
View file

@ -0,0 +1,126 @@
package appwrite
import (
"strings"
)
// Storage service
type Storage struct {
client *Client
}
// ListFiles get a list of all the user files. You can use the query params to
// filter your results. On admin mode, this endpoint will return a list of all
// of the project files. [Learn more about different API modes](/docs/admin).
func (srv *Storage) ListFiles(Search string, Limit int, Offset int, OrderType string) (map[string]interface{}, error) {
path := "/storage/files"
params := map[string]interface{}{
"search": Search,
"limit": Limit,
"offset": Offset,
"orderType": OrderType,
}
return srv.client.Call("GET", path, nil, params)
}
// CreateFile create a new file. The user who creates the file will
// automatically be assigned to read and write access unless he has passed
// custom values for read and write arguments.
func (srv *Storage) CreateFile(File string, Read []interface{}, Write []interface{}) (map[string]interface{}, error) {
path := "/storage/files"
params := map[string]interface{}{
"file": File,
"read": Read,
"write": Write,
}
return srv.client.Call("POST", path, nil, params)
}
// GetFile get file by its unique ID. This endpoint response returns a JSON
// object with the file metadata.
func (srv *Storage) GetFile(FileId string) (map[string]interface{}, error) {
r := strings.NewReplacer("{fileId}", FileId)
path := r.Replace("/storage/files/{fileId}")
params := map[string]interface{}{
}
return srv.client.Call("GET", path, nil, params)
}
// UpdateFile update file by its unique ID. Only users with write permissions
// have access to update this resource.
func (srv *Storage) UpdateFile(FileId string, Read []interface{}, Write []interface{}) (map[string]interface{}, error) {
r := strings.NewReplacer("{fileId}", FileId)
path := r.Replace("/storage/files/{fileId}")
params := map[string]interface{}{
"read": Read,
"write": Write,
}
return srv.client.Call("PUT", path, nil, params)
}
// DeleteFile delete a file by its unique ID. Only users with write
// permissions have access to delete this resource.
func (srv *Storage) DeleteFile(FileId string) (map[string]interface{}, error) {
r := strings.NewReplacer("{fileId}", FileId)
path := r.Replace("/storage/files/{fileId}")
params := map[string]interface{}{
}
return srv.client.Call("DELETE", path, nil, params)
}
// GetFileDownload get file content by its unique ID. The endpoint response
// return with a 'Content-Disposition: attachment' header that tells the
// browser to start downloading the file to user downloads directory.
func (srv *Storage) GetFileDownload(FileId string) (map[string]interface{}, error) {
r := strings.NewReplacer("{fileId}", FileId)
path := r.Replace("/storage/files/{fileId}/download")
params := map[string]interface{}{
}
return srv.client.Call("GET", path, nil, params)
}
// GetFilePreview get a file preview image. Currently, this method supports
// preview for image files (jpg, png, and gif), other supported formats, like
// pdf, docs, slides, and spreadsheets, will return the file icon image. You
// can also pass query string arguments for cutting and resizing your preview
// image.
func (srv *Storage) GetFilePreview(FileId string, Width int, Height int, Quality int, Background string, Output string) (map[string]interface{}, error) {
r := strings.NewReplacer("{fileId}", FileId)
path := r.Replace("/storage/files/{fileId}/preview")
params := map[string]interface{}{
"width": Width,
"height": Height,
"quality": Quality,
"background": Background,
"output": Output,
}
return srv.client.Call("GET", path, nil, params)
}
// GetFileView get file content by its unique ID. This endpoint is similar to
// the download method but returns with no 'Content-Disposition: attachment'
// header.
func (srv *Storage) GetFileView(FileId string, As string) (map[string]interface{}, error) {
r := strings.NewReplacer("{fileId}", FileId)
path := r.Replace("/storage/files/{fileId}/view")
params := map[string]interface{}{
"as": As,
}
return srv.client.Call("GET", path, nil, params)
}

132
app/sdks/go/teams.go Normal file
View file

@ -0,0 +1,132 @@
package appwrite
import (
"strings"
)
// Teams service
type Teams struct {
client *Client
}
// ListTeams get a list of all the current user teams. You can use the query
// params to filter your results. On admin mode, this endpoint will return a
// list of all of the project teams. [Learn more about different API
// modes](/docs/admin).
func (srv *Teams) ListTeams(Search string, Limit int, Offset int, OrderType string) (map[string]interface{}, error) {
path := "/teams"
params := map[string]interface{}{
"search": Search,
"limit": Limit,
"offset": Offset,
"orderType": OrderType,
}
return srv.client.Call("GET", path, nil, params)
}
// CreateTeam create a new team. The user who creates the team will
// automatically be assigned as the owner of the team. The team owner can
// invite new members, who will be able add new owners and update or delete
// the team from your project.
func (srv *Teams) CreateTeam(Name string, Roles []interface{}) (map[string]interface{}, error) {
path := "/teams"
params := map[string]interface{}{
"name": Name,
"roles": Roles,
}
return srv.client.Call("POST", path, nil, params)
}
// GetTeam get team by its unique ID. All team members have read access for
// this resource.
func (srv *Teams) GetTeam(TeamId string) (map[string]interface{}, error) {
r := strings.NewReplacer("{teamId}", TeamId)
path := r.Replace("/teams/{teamId}")
params := map[string]interface{}{
}
return srv.client.Call("GET", path, nil, params)
}
// UpdateTeam update team by its unique ID. Only team owners have write access
// for this resource.
func (srv *Teams) UpdateTeam(TeamId string, Name string) (map[string]interface{}, error) {
r := strings.NewReplacer("{teamId}", TeamId)
path := r.Replace("/teams/{teamId}")
params := map[string]interface{}{
"name": Name,
}
return srv.client.Call("PUT", path, nil, params)
}
// DeleteTeam delete team by its unique ID. Only team owners have write access
// for this resource.
func (srv *Teams) DeleteTeam(TeamId string) (map[string]interface{}, error) {
r := strings.NewReplacer("{teamId}", TeamId)
path := r.Replace("/teams/{teamId}")
params := map[string]interface{}{
}
return srv.client.Call("DELETE", path, nil, params)
}
// GetTeamMemberships get team members by the team unique ID. All team members
// have read access for this list of resources.
func (srv *Teams) GetTeamMemberships(TeamId string) (map[string]interface{}, error) {
r := strings.NewReplacer("{teamId}", TeamId)
path := r.Replace("/teams/{teamId}/memberships")
params := map[string]interface{}{
}
return srv.client.Call("GET", path, nil, params)
}
// CreateTeamMembership use this endpoint to invite a new member to your team.
// An email with a link to join the team will be sent to the new member email
// address. If member doesn't exists in the project it will be automatically
// created.
//
// Use the 'url' parameter to redirect the user from the invitation email back
// to your app. When the user is redirected, use the [Update Team Membership
// Status](/docs/teams#updateTeamMembershipStatus) endpoint to finally join
// the user to the team.
//
// Please note that in order to avoid a [Redirect
// Attacks](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md)
// the only valid redirect URL's are the once from domains you have set when
// added your platforms in the console interface.
func (srv *Teams) CreateTeamMembership(TeamId string, Email string, Roles []interface{}, Url string, Name string) (map[string]interface{}, error) {
r := strings.NewReplacer("{teamId}", TeamId)
path := r.Replace("/teams/{teamId}/memberships")
params := map[string]interface{}{
"email": Email,
"name": Name,
"roles": Roles,
"url": Url,
}
return srv.client.Call("POST", path, nil, params)
}
// DeleteTeamMembership this endpoint allows a user to leave a team or for a
// team owner to delete the membership of any other team member. You can also
// use this endpoint to delete a user membership even if he didn't accept it.
func (srv *Teams) DeleteTeamMembership(TeamId string, InviteId string) (map[string]interface{}, error) {
r := strings.NewReplacer("{teamId}", TeamId, "{inviteId}", InviteId)
path := r.Replace("/teams/{teamId}/memberships/{inviteId}")
params := map[string]interface{}{
}
return srv.client.Call("DELETE", path, nil, params)
}

130
app/sdks/go/users.go Normal file
View file

@ -0,0 +1,130 @@
package appwrite
import (
"strings"
)
// Users service
type Users struct {
client *Client
}
// ListUsers get a list of all the project users. You can use the query params
// to filter your results.
func (srv *Users) ListUsers(Search string, Limit int, Offset int, OrderType string) (map[string]interface{}, error) {
path := "/users"
params := map[string]interface{}{
"search": Search,
"limit": Limit,
"offset": Offset,
"orderType": OrderType,
}
return srv.client.Call("GET", path, nil, params)
}
// CreateUser create a new user.
func (srv *Users) CreateUser(Email string, Password string, Name string) (map[string]interface{}, error) {
path := "/users"
params := map[string]interface{}{
"email": Email,
"password": Password,
"name": Name,
}
return srv.client.Call("POST", path, nil, params)
}
// GetUser get user by its unique ID.
func (srv *Users) GetUser(UserId string) (map[string]interface{}, error) {
r := strings.NewReplacer("{userId}", UserId)
path := r.Replace("/users/{userId}")
params := map[string]interface{}{
}
return srv.client.Call("GET", path, nil, params)
}
// GetUserLogs get user activity logs list by its unique ID.
func (srv *Users) GetUserLogs(UserId string) (map[string]interface{}, error) {
r := strings.NewReplacer("{userId}", UserId)
path := r.Replace("/users/{userId}/logs")
params := map[string]interface{}{
}
return srv.client.Call("GET", path, nil, params)
}
// GetUserPrefs get user preferences by its unique ID.
func (srv *Users) GetUserPrefs(UserId string) (map[string]interface{}, error) {
r := strings.NewReplacer("{userId}", UserId)
path := r.Replace("/users/{userId}/prefs")
params := map[string]interface{}{
}
return srv.client.Call("GET", path, nil, params)
}
// UpdateUserPrefs update user preferences by its unique ID. You can pass only
// the specific settings you wish to update.
func (srv *Users) UpdateUserPrefs(UserId string, Prefs string) (map[string]interface{}, error) {
r := strings.NewReplacer("{userId}", UserId)
path := r.Replace("/users/{userId}/prefs")
params := map[string]interface{}{
"prefs": Prefs,
}
return srv.client.Call("PATCH", path, nil, params)
}
// GetUserSessions get user sessions list by its unique ID.
func (srv *Users) GetUserSessions(UserId string) (map[string]interface{}, error) {
r := strings.NewReplacer("{userId}", UserId)
path := r.Replace("/users/{userId}/sessions")
params := map[string]interface{}{
}
return srv.client.Call("GET", path, nil, params)
}
// DeleteUserSessions delete all user sessions by its unique ID.
func (srv *Users) DeleteUserSessions(UserId string) (map[string]interface{}, error) {
r := strings.NewReplacer("{userId}", UserId)
path := r.Replace("/users/{userId}/sessions")
params := map[string]interface{}{
}
return srv.client.Call("DELETE", path, nil, params)
}
// DeleteUserSession delete user sessions by its unique ID.
func (srv *Users) DeleteUserSession(UserId string, SessionId string) (map[string]interface{}, error) {
r := strings.NewReplacer("{userId}", UserId)
path := r.Replace("/users/{userId}/sessions/:session")
params := map[string]interface{}{
"sessionId": SessionId,
}
return srv.client.Call("DELETE", path, nil, params)
}
// UpdateUserStatus update user status by its unique ID.
func (srv *Users) UpdateUserStatus(UserId string, Status string) (map[string]interface{}, error) {
r := strings.NewReplacer("{userId}", UserId)
path := r.Replace("/users/{userId}/status")
params := map[string]interface{}{
"status": Status,
}
return srv.client.Call("PATCH", path, nil, params)
}

36
app/sdks/go/utils.go Normal file
View file

@ -0,0 +1,36 @@
package appwrite
import (
"fmt"
"reflect"
"strconv"
)
// ToString changes arg to string
func ToString(arg interface{}) string {
var tmp = reflect.Indirect(reflect.ValueOf(arg)).Interface()
switch v := tmp.(type) {
case int:
return strconv.Itoa(v)
case int8:
return strconv.FormatInt(int64(v), 10)
case int16:
return strconv.FormatInt(int64(v), 10)
case int32:
return strconv.FormatInt(int64(v), 10)
case int64:
return strconv.FormatInt(v, 10)
case string:
return v
case float32:
return strconv.FormatFloat(float64(v), 'f', -1, 32)
case float64:
return strconv.FormatFloat(v, 'f', -1, 64)
case fmt.Stringer:
return v.String()
case reflect.Value:
return ToString(v.Interface())
default:
return ""
}
}