Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
# Change Log

## v0.17.0
## 0.17.0

* Fix doc examples with proper formatting
* Added new Activities service to the Go SDK with a NewActivities constructor to access Activities endpoints.
* Extended Databases attribute APIs to support encryption: introduced Encrypt option for Longtext, Mediumtext, Text, and Varchar attributes, along with corresponding New/Create option builders (WithCreateLongtextAttributeEncrypt, WithCreateMediumtextAttributeEncrypt, WithCreateTextAttributeEncrypt, WithCreateVarcharAttributeEncrypt) and wiring to send the encrypt parameter when enabled.
* Updated documentation and examples to demonstrate the new encrypt option for attribute creation (e.g., docs/examples/databases/create-longtext-attribute.md, create-mediumtext-attribute.md, create-text-attribute.md, create-varchar-attribute.md).
* Updated README to reflect compatibility with Appwrite server version 1.8.x.
* Add support for the new `Backups` service

## v0.16.1

* Fix doc examples with proper formatting

## v0.16.0

* Added ability to create columns and indexes synchronously while creating a table
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite)
[![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord)

**This SDK is compatible with Appwrite server version latest. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-go/releases).**
**This SDK is compatible with Appwrite server version 1.8.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-go/releases).**

Appwrite is an open-source backend as a service server that abstracts and simplifies 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](https://appwrite.io/docs)

Expand Down
111 changes: 111 additions & 0 deletions activities/activities.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package activities

import (
"encoding/json"
"errors"
"github.com/appwrite/sdk-for-go/client"
"github.com/appwrite/sdk-for-go/models"
"strings"
)

// Activities service
type Activities struct {
client client.Client
}

func New(clt client.Client) *Activities {
return &Activities{
client: clt,
}
}

type ListEventsOptions struct {
Queries string
enabledSetters map[string]bool
}
func (options ListEventsOptions) New() *ListEventsOptions {
options.enabledSetters = map[string]bool{
"Queries": false,
}
return &options
}
type ListEventsOption func(*ListEventsOptions)
func (srv *Activities) WithListEventsQueries(v string) ListEventsOption {
return func(o *ListEventsOptions) {
o.Queries = v
o.enabledSetters["Queries"] = true
}
}

// ListEvents list all events for selected filters.
func (srv *Activities) ListEvents(optionalSetters ...ListEventsOption)(*models.ActivityEventList, error) {
path := "/activities/events"
options := ListEventsOptions{}.New()
for _, opt := range optionalSetters {
opt(options)
}
params := map[string]interface{}{}
if options.enabledSetters["Queries"] {
params["queries"] = options.Queries
}
headers := map[string]interface{}{
}

resp, err := srv.client.Call("GET", path, headers, params)
if err != nil {
return nil, err
}
if strings.HasPrefix(resp.Type, "application/json") {
bytes := []byte(resp.Result.(string))

parsed := models.ActivityEventList{}.New(bytes)

err = json.Unmarshal(bytes, parsed)
if err != nil {
return nil, err
}

return parsed, nil
}
var parsed models.ActivityEventList
parsed, ok := resp.Result.(models.ActivityEventList)
if !ok {
return nil, errors.New("unexpected response type")
}
return &parsed, nil

}

// GetEvent get event by ID.
func (srv *Activities) GetEvent(EventId string)(*models.ActivityEvent, error) {
r := strings.NewReplacer("{eventId}", EventId)
path := r.Replace("/activities/events/{eventId}")
params := map[string]interface{}{}
params["eventId"] = EventId
headers := map[string]interface{}{
}

resp, err := srv.client.Call("GET", path, headers, params)
if err != nil {
return nil, err
}
if strings.HasPrefix(resp.Type, "application/json") {
bytes := []byte(resp.Result.(string))

parsed := models.ActivityEvent{}.New(bytes)

err = json.Unmarshal(bytes, parsed)
if err != nil {
return nil, err
}

return parsed, nil
}
var parsed models.ActivityEvent
parsed, ok := resp.Result.(models.ActivityEvent)
if !ok {
return nil, errors.New("unexpected response type")
}
return &parsed, nil

}
4 changes: 4 additions & 0 deletions appwrite/appwrite.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/appwrite/sdk-for-go/client"
"github.com/appwrite/sdk-for-go/account"
"github.com/appwrite/sdk-for-go/activities"
"github.com/appwrite/sdk-for-go/avatars"
"github.com/appwrite/sdk-for-go/backups"
"github.com/appwrite/sdk-for-go/databases"
Expand All @@ -24,6 +25,9 @@ import (
func NewAccount(clt client.Client) *account.Account {
return account.New(clt)
}
func NewActivities(clt client.Client) *activities.Activities {
return activities.New(clt)
}
func NewAvatars(clt client.Client) *avatars.Avatars {
return avatars.New(clt)
}
Expand Down
44 changes: 44 additions & 0 deletions databases/databases.go
Original file line number Diff line number Diff line change
Expand Up @@ -2278,12 +2278,14 @@ func (srv *Databases) UpdateLineAttribute(DatabaseId string, CollectionId string
type CreateLongtextAttributeOptions struct {
Default string
Array bool
Encrypt bool
enabledSetters map[string]bool
}
func (options CreateLongtextAttributeOptions) New() *CreateLongtextAttributeOptions {
options.enabledSetters = map[string]bool{
"Default": false,
"Array": false,
"Encrypt": false,
}
return &options
}
Expand All @@ -2300,6 +2302,12 @@ func (srv *Databases) WithCreateLongtextAttributeArray(v bool) CreateLongtextAtt
o.enabledSetters["Array"] = true
}
}
func (srv *Databases) WithCreateLongtextAttributeEncrypt(v bool) CreateLongtextAttributeOption {
return func(o *CreateLongtextAttributeOptions) {
o.Encrypt = v
o.enabledSetters["Encrypt"] = true
}
}

// CreateLongtextAttribute create a longtext attribute.
func (srv *Databases) CreateLongtextAttribute(DatabaseId string, CollectionId string, Key string, Required bool, optionalSetters ...CreateLongtextAttributeOption)(*models.AttributeLongtext, error) {
Expand All @@ -2320,6 +2328,9 @@ func (srv *Databases) CreateLongtextAttribute(DatabaseId string, CollectionId st
if options.enabledSetters["Array"] {
params["array"] = options.Array
}
if options.enabledSetters["Encrypt"] {
params["encrypt"] = options.Encrypt
}
headers := map[string]interface{}{
"content-type": "application/json",
}
Expand Down Expand Up @@ -2415,12 +2426,14 @@ func (srv *Databases) UpdateLongtextAttribute(DatabaseId string, CollectionId st
type CreateMediumtextAttributeOptions struct {
Default string
Array bool
Encrypt bool
enabledSetters map[string]bool
}
func (options CreateMediumtextAttributeOptions) New() *CreateMediumtextAttributeOptions {
options.enabledSetters = map[string]bool{
"Default": false,
"Array": false,
"Encrypt": false,
}
return &options
}
Expand All @@ -2437,6 +2450,12 @@ func (srv *Databases) WithCreateMediumtextAttributeArray(v bool) CreateMediumtex
o.enabledSetters["Array"] = true
}
}
func (srv *Databases) WithCreateMediumtextAttributeEncrypt(v bool) CreateMediumtextAttributeOption {
return func(o *CreateMediumtextAttributeOptions) {
o.Encrypt = v
o.enabledSetters["Encrypt"] = true
}
}

// CreateMediumtextAttribute create a mediumtext attribute.
func (srv *Databases) CreateMediumtextAttribute(DatabaseId string, CollectionId string, Key string, Required bool, optionalSetters ...CreateMediumtextAttributeOption)(*models.AttributeMediumtext, error) {
Expand All @@ -2457,6 +2476,9 @@ func (srv *Databases) CreateMediumtextAttribute(DatabaseId string, CollectionId
if options.enabledSetters["Array"] {
params["array"] = options.Array
}
if options.enabledSetters["Encrypt"] {
params["encrypt"] = options.Encrypt
}
headers := map[string]interface{}{
"content-type": "application/json",
}
Expand Down Expand Up @@ -3095,12 +3117,14 @@ func (srv *Databases) UpdateStringAttribute(DatabaseId string, CollectionId stri
type CreateTextAttributeOptions struct {
Default string
Array bool
Encrypt bool
enabledSetters map[string]bool
}
func (options CreateTextAttributeOptions) New() *CreateTextAttributeOptions {
options.enabledSetters = map[string]bool{
"Default": false,
"Array": false,
"Encrypt": false,
}
return &options
}
Expand All @@ -3117,6 +3141,12 @@ func (srv *Databases) WithCreateTextAttributeArray(v bool) CreateTextAttributeOp
o.enabledSetters["Array"] = true
}
}
func (srv *Databases) WithCreateTextAttributeEncrypt(v bool) CreateTextAttributeOption {
return func(o *CreateTextAttributeOptions) {
o.Encrypt = v
o.enabledSetters["Encrypt"] = true
}
}

// CreateTextAttribute create a text attribute.
func (srv *Databases) CreateTextAttribute(DatabaseId string, CollectionId string, Key string, Required bool, optionalSetters ...CreateTextAttributeOption)(*models.AttributeText, error) {
Expand All @@ -3137,6 +3167,9 @@ func (srv *Databases) CreateTextAttribute(DatabaseId string, CollectionId string
if options.enabledSetters["Array"] {
params["array"] = options.Array
}
if options.enabledSetters["Encrypt"] {
params["encrypt"] = options.Encrypt
}
headers := map[string]interface{}{
"content-type": "application/json",
}
Expand Down Expand Up @@ -3373,12 +3406,14 @@ func (srv *Databases) UpdateUrlAttribute(DatabaseId string, CollectionId string,
type CreateVarcharAttributeOptions struct {
Default string
Array bool
Encrypt bool
enabledSetters map[string]bool
}
func (options CreateVarcharAttributeOptions) New() *CreateVarcharAttributeOptions {
options.enabledSetters = map[string]bool{
"Default": false,
"Array": false,
"Encrypt": false,
}
return &options
}
Expand All @@ -3395,6 +3430,12 @@ func (srv *Databases) WithCreateVarcharAttributeArray(v bool) CreateVarcharAttri
o.enabledSetters["Array"] = true
}
}
func (srv *Databases) WithCreateVarcharAttributeEncrypt(v bool) CreateVarcharAttributeOption {
return func(o *CreateVarcharAttributeOptions) {
o.Encrypt = v
o.enabledSetters["Encrypt"] = true
}
}

// CreateVarcharAttribute create a varchar attribute.
func (srv *Databases) CreateVarcharAttribute(DatabaseId string, CollectionId string, Key string, Size int, Required bool, optionalSetters ...CreateVarcharAttributeOption)(*models.AttributeVarchar, error) {
Expand All @@ -3416,6 +3457,9 @@ func (srv *Databases) CreateVarcharAttribute(DatabaseId string, CollectionId str
if options.enabledSetters["Array"] {
params["array"] = options.Array
}
if options.enabledSetters["Encrypt"] {
params["encrypt"] = options.Encrypt
}
headers := map[string]interface{}{
"content-type": "application/json",
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package main
import (
"fmt"
"github.com/appwrite/sdk-for-go/client"
"github.com/appwrite/sdk-for-go/health"
"github.com/appwrite/sdk-for-go/activities"
)

client := client.New(
Expand All @@ -13,9 +13,9 @@ client := client.New(
client.WithKey("<YOUR_API_KEY>")
)

service := health.New(client)
service := activities.New(client)

response, error := service.GetQueueThreats(
health.WithGetQueueThreatsThreshold(0),
response, error := service.GetEvent(
"<EVENT_ID>",
)
```
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package main
import (
"fmt"
"github.com/appwrite/sdk-for-go/client"
"github.com/appwrite/sdk-for-go/health"
"github.com/appwrite/sdk-for-go/activities"
)

client := client.New(
Expand All @@ -13,9 +13,9 @@ client := client.New(
client.WithKey("<YOUR_API_KEY>")
)

service := health.New(client)
service := activities.New(client)

response, error := service.GetQueueRegionManager(
health.WithGetQueueRegionManagerThreshold(0),
response, error := service.ListEvents(
activities.WithListEventsQueries(""),
)
```
1 change: 1 addition & 0 deletions docs/examples/databases/create-longtext-attribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ response, error := service.CreateLongtextAttribute(
false,
databases.WithCreateLongtextAttributeDefault("<DEFAULT>"),
databases.WithCreateLongtextAttributeArray(false),
databases.WithCreateLongtextAttributeEncrypt(false),
)
```
1 change: 1 addition & 0 deletions docs/examples/databases/create-mediumtext-attribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ response, error := service.CreateMediumtextAttribute(
false,
databases.WithCreateMediumtextAttributeDefault("<DEFAULT>"),
databases.WithCreateMediumtextAttributeArray(false),
databases.WithCreateMediumtextAttributeEncrypt(false),
)
```
1 change: 1 addition & 0 deletions docs/examples/databases/create-text-attribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ response, error := service.CreateTextAttribute(
false,
databases.WithCreateTextAttributeDefault("<DEFAULT>"),
databases.WithCreateTextAttributeArray(false),
databases.WithCreateTextAttributeEncrypt(false),
)
```
1 change: 1 addition & 0 deletions docs/examples/databases/create-varchar-attribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ response, error := service.CreateVarcharAttribute(
false,
databases.WithCreateVarcharAttributeDefault("<DEFAULT>"),
databases.WithCreateVarcharAttributeArray(false),
databases.WithCreateVarcharAttributeEncrypt(false),
)
```
Loading