directus

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 17, 2026 License: MIT Imports: 10 Imported by: 0

README

Go Directus SDK

A pure Go library for interacting with Directus CMS API. Provides type-safe client methods for CRUD operations, authentication, filtering, and aggregation.

Features

  • Type-safe: Uses Go generics for compile-time type checking
  • Complete API coverage: Supports all major Directus REST API endpoints
  • Builder pattern: Fluent API for constructing complex queries
  • Context-aware: Full support for Go contexts and cancellation
  • Authentication: Static tokens, context-based tokens, OTP, password reset
  • Filtering: Type-safe filter rules with logical operators
  • Aggregation: Built-in support for Directus aggregation functions
  • Error handling: Structured errors with HTTP status codes
  • No CGO dependencies: Pure Go implementation

Installation

go get github.com/macrox-pro/go-directus-sdk

Requires Go 1.25.0 or higher.

Quick Start

package main

import (
    "context"
    "fmt"
    "log"
    
    "github.com/macrox-pro/go-directus-sdk"
)

type User struct {
    ID   string `json:"id"`
    Name string `json:"name"`
    Email string `json:"email"`
}

func main() {
    // Create a client with static token
    client, err := directus.NewClient(
        "https://your-directus-instance.com",
        directus.WithStaticToken("your-access-token"),
    )
    if err != nil {
        log.Fatal(err)
    }
    
    // Read items (without filtering)
    ctx := context.Background()
    users, err := directus.NewReadItems[User]("users").
        SetLimit(10).
        SetOffset(0).
        SendBy(client)
    if err != nil {
        log.Fatal(err)
    }
    
    for _, user := range users {
        fmt.Printf("User: %s (%s)\n", user.Name, user.Email)
    }
}

Authentication

Static Token
client, err := directus.NewClient(
    "https://api.example.com",
    directus.WithStaticToken("your-access-token"),
)
Context-Based Token
client, err := directus.NewClient(
    "https://api.example.com",
    directus.WithExtractTokenFromContext(true),
)

ctx := directus.WithAccessTokenContext(context.Background(), "dynamic-token")
// Use ctx in requests
Login with Credentials
resp, err := client.AuthLogin(ctx, directus.AuthLoginParams{
    Email:    "admin@example.com",
    Password: "password",
})
if err != nil {
    log.Fatal(err)
}
fmt.Printf("Access token: %s\n", resp.AccessToken)
Refresh Token
resp, err := client.AuthRefresh(ctx, directus.AuthRefreshParams{
    RefreshToken: "refresh-token",
})
OTP Verification
resp, err := client.AuthOTPVerify(ctx, directus.OTPVerifyParams{
    OTP: "otp-code",
})
Password Reset Request
err := client.AuthResetPasswordRequest(ctx, directus.PasswordResetRequestParams{
    Email: "user@example.com",
})
Password Reset
err := client.AuthPasswordReset(ctx, directus.PasswordResetParams{
    Token:    "reset-token",
    Password: "new-password",
})
Auth Providers
providers, err := client.AuthProviders(ctx)
if err != nil {
    log.Fatal(err)
}
for _, provider := range providers {
    fmt.Printf("Provider: %s (%s)\n", provider.Name, provider.Driver)
}

CRUD Operations

Create Item
newUser := User{Name: "John Doe", Email: "john@example.com"}
created, err := directus.NewCreateItem[User]("users", newUser).
    SendBy(client)
Read Item
user, err := directus.NewReadItem[User]("users", "user-123").
    SendBy(client)
Read Items with Filtering
// Create a filter using ByField and Equal
filter := directus.ByField{
    Name: "status",
    Filter: directus.Equal[string]{Value: "active"},
}
users, err := directus.NewReadItems[User]("users").
    SetFilter(filter).
    SetSort("-created_at").
    SetLimit(100).
    SetOffset(0).
    SendBy(client)
Update Item
updated, err := directus.NewUpdateItem[User]("users", "user-123").
    SetChanges(map[string]any{"name": "John Updated"}).
    SendBy(client)
Update Items (Batch)
err := directus.NewUpdateItems[User]("users").
    SetFilter(directus.ByField{
        Name: "status",
        Filter: directus.Equal[string]{Value: "inactive"},
    }).
    SetChanges(map[string]any{"archived": true}).
    SendBy(client)
Delete Item
err := directus.NewDeleteItem("users", "user-123").
    SendBy(client)
Delete Items (Batch)
err := directus.NewDeleteItems[string]("users").
    SetFilter(directus.ByField{
        Name: "status",
        Filter: directus.Equal[string]{Value: "deleted"},
    }).
    SendBy(client)

Filtering

The SDK provides type-safe filter rules via structs. You can compose filters using the ByField wrapper.

Basic comparisons
// Equal
filter := directus.ByField{
    Name: "status",
    Filter: directus.Equal[string]{Value: "active"},
}

// Not equal
filter := directus.ByField{
    Name: "status",
    Filter: directus.NotEqual[string]{Value: "inactive"},
}

// Greater than
filter := directus.ByField{
    Name: "age",
    Filter: directus.GreaterThan[int]{Value: 18},
}

// Less than
filter := directus.ByField{
    Name: "price",
    Filter: directus.LessThan[float64]{Value: 100.0},
}
String operations
// Contains
filter := directus.ByField{
    Name: "title",
    Filter: directus.Contains{Value: "important"},
}

// Starts with
filter := directus.ByField{
    Name: "email",
    Filter: directus.StartsWith{Value: "admin@"},
}

// Ends with
filter := directus.ByField{
    Name: "filename",
    Filter: directus.EndsWith{Value: ".pdf"},
}
Logical operators
// AND
filter := directus.AND{
    Filters: []directus.FilterRule{
        directus.ByField{Name: "status", Filter: directus.Equal[string]{Value: "active"}},
        directus.ByField{Name: "age", Filter: directus.GreaterThan[int]{Value: 18}},
    },
}

// OR
filter := directus.OR{
    Filters: []directus.FilterRule{
        directus.ByField{Name: "role", Filter: directus.Equal[string]{Value: "admin"}},
        directus.ByField{Name: "role", Filter: directus.Equal[string]{Value: "moderator"}},
    },
}

// NOT
filter := directus.NOT{
    Filter: directus.ByField{Name: "status", Filter: directus.Equal[string]{Value: "deleted"}},
}
Null checks
filter := directus.ByField{
    Name: "deleted_at",
    Filter: directus.IsNull{},
}

filter := directus.ByField{
    Name: "updated_at",
    Filter: directus.IsNotNull{},
}
In / NotIn
filter := directus.ByField{
    Name: "category",
    Filter: directus.In[string]{Values: []string{"news", "blog", "tutorial"}},
}

filter := directus.ByField{
    Name: "status",
    Filter: directus.NotIn[string]{Values: []string{"draft", "archived"}},
}
Between
filter := directus.ByField{
    Name: "price",
    Filter: directus.Between[float64]{Low: 10.0, High: 100.0},
}

Aggregation

Aggregation is performed using directus.NewAggregate and SetAggregate with an aggregate rule.

Count
result, err := directus.NewAggregate[any]("users").
    SetAggregate(directus.Count{}).
    SetFilter(directus.ByField{
        Name: "status",
        Filter: directus.Equal[string]{Value: "active"},
    }).
    SendBy(client)
Sum
result, err := directus.NewAggregate[any]("orders").
    SetAggregate(directus.Sum{Fields: []string{"total_amount"}}).
    SetFilter(directus.ByField{
        Name: "status",
        Filter: directus.Equal[string]{Value: "completed"},
    }).
    SendBy(client)
Multiple aggregations
result, err := directus.NewAggregate[any]("products").
    SetAggregate(directus.Many{
        Rules: []directus.AggregateRule{
            directus.Count{},
            directus.Sum{Fields: []string{"stock"}},
            directus.Avg{Fields: []string{"price"}},
            directus.Min{Fields: []string{"price"}},
            directus.Max{Fields: []string{"price"}},
        },
    }).
    SendBy(client)

Note: Use directus.Many to combine multiple aggregate rules in a single request.

Server Information

Ping
ping, err := client.ServerPing(ctx)
Health
health, err := client.ServerHealth(ctx)
Info
info, err := client.ServerInfo(ctx)

Singleton Operations

Read Singleton
settings, err := directus.NewReadSingleton[Settings]("settings").
    SendBy(client)
Update Singleton

Update of singletons is currently not implemented as a separate method. Use UpdateItem with the singleton collection name.

Error Handling

The SDK returns structured errors:

items, err := directus.NewReadItems[User]("users").SendBy(client)
if err != nil {
    if errs, ok := err.(directus.Errors); ok {
        for _, e := range errs {
            fmt.Printf("Error %d: %s\n", e.Status(), e.Message)
        }
    } else {
        log.Fatal(err)
    }
}

Advanced Usage

Deep Query
users, err := directus.NewReadItems[User]("users").
    SetDeep(map[string]directus.DeepQuery{
        "posts": {
            Filter: directus.ByField{
                Name: "status",
                Filter: directus.Equal[string]{Value: "published"},
            },
            Limit: 5,
        },
    }).
    SendBy(client)
System Collections
// Access Directus system collections
roles, err := directus.NewReadItems[Role]("directus_roles").
    SetIsSystem(true).
    SendBy(client)

Configuration

Client Options
client, err := directus.NewClient(
    "https://api.example.com",
    directus.WithStaticToken("your-access-token"),
    directus.WithExtractTokenFromContext(true),
)
Custom HTTP Client

The SDK uses github.com/go-resty/resty/v2 internally. You can customize the underlying HTTP client by accessing the resty client directly:

// Create client first
client, err := directus.NewClient("https://api.example.com")
if err != nil {
    log.Fatal(err)
}

// Access the underlying resty client
restyClient := client.resty // Note: field is not exported, you need to use reflection or provide a getter.
// Currently there is no public method to access the resty client.

Requirements

  • Go 1.25.0 or higher
  • Directus API v11+

Dependencies

  • github.com/go-resty/resty/v2 - HTTP client
  • github.com/google/go-querystring - URL query parameter encoding

Testing

# Run tests
go test ./...

# Check for linting issues
go vet ./...

# Format code
go fmt ./...

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Ensure go build ./... and go test ./... pass
  6. Submit a pull request

Please follow the Go code style and ensure all exported types/functions are documented.

License

MIT License - see LICENSE file for details.

References

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AccessTokenFromContext

func AccessTokenFromContext(ctx context.Context) string

func WithAccessTokenContext

func WithAccessTokenContext(ctx context.Context, token string) context.Context

Types

type AND

type AND struct {
	Filters []FilterRule `json:"_and"`
}

type AggregateQuery

type AggregateQuery struct {
	Aggregate AggregateRule        `url:"aggregate,omitempty"`
	GroupBy   []string             `url:"groupBy,omitempty"`
	Filter    helpers.URLParamJSON `url:"filter,omitempty"`
	Sort      []string             `url:"sort,omitempty"`
	Search    string               `url:"search,omitempty"`
	Offset    int                  `url:"offset,omitempty"`
	Limit     int                  `url:"limit,omitempty"`
	Page      int                  `url:"page,omitempty"`
}

type AggregateRequest

type AggregateRequest[T any] struct {
	AggregateQuery

	Collection string
	IsSystem   bool

	Token string
	// contains filtered or unexported fields
}

func NewAggregate

func NewAggregate[T any](collection string) *AggregateRequest[T]

func (*AggregateRequest[T]) SendBy

func (r *AggregateRequest[T]) SendBy(client *Client) ([]T, error)

func (*AggregateRequest[T]) SetAggregate

func (r *AggregateRequest[T]) SetAggregate(rule AggregateRule) *AggregateRequest[T]

func (*AggregateRequest[T]) SetContext

func (r *AggregateRequest[T]) SetContext(ctx context.Context) *AggregateRequest[T]

func (*AggregateRequest[T]) SetFilter

func (r *AggregateRequest[T]) SetFilter(rule FilterRule) *AggregateRequest[T]

func (*AggregateRequest[T]) SetGroupBy

func (r *AggregateRequest[T]) SetGroupBy(groupBy []string) *AggregateRequest[T]

func (*AggregateRequest[T]) SetIsSystem

func (r *AggregateRequest[T]) SetIsSystem(v bool) *AggregateRequest[T]

func (*AggregateRequest[T]) SetLimit

func (r *AggregateRequest[T]) SetLimit(limit int) *AggregateRequest[T]

func (*AggregateRequest[T]) SetOffset

func (r *AggregateRequest[T]) SetOffset(offset int) *AggregateRequest[T]

func (*AggregateRequest[T]) SetPage

func (r *AggregateRequest[T]) SetPage(page int) *AggregateRequest[T]

func (*AggregateRequest[T]) SetSearch

func (r *AggregateRequest[T]) SetSearch(search string) *AggregateRequest[T]

func (*AggregateRequest[T]) SetSort

func (r *AggregateRequest[T]) SetSort(sort []string) *AggregateRequest[T]

func (*AggregateRequest[T]) SetToken

func (r *AggregateRequest[T]) SetToken(token string) *AggregateRequest[T]

type AggregateRule

type AggregateRule interface {
	query.Encoder
	// contains filtered or unexported methods
}

type AuthLoginParams

type AuthLoginParams struct {
	Email    string   `json:"email"`
	Password string   `json:"password"`
	Mode     AuthMode `json:"mode,omitempty"`
	OTP      string   `json:"otp,omitempty"`

	Provider string `json:"-"`
}

type AuthLogoutParams

type AuthLogoutParams struct {
	RefreshToken string   `json:"refresh_token"`
	Mode         AuthMode `json:"mode,omitempty"`
}

type AuthMode

type AuthMode string
const (
	JsonAuthMode    AuthMode = "json"
	CookieAuthMode  AuthMode = "cookie"
	SessionAuthMode AuthMode = "session"
)

type AuthProvider

type AuthProvider struct {
	Name        string            `json:"name"`
	Driver      string            `json:"driver"`
	Icon        string            `json:"icon,omitempty"`
	Label       string            `json:"label,omitempty"`
	RedirectURL string            `json:"redirect_url,omitempty"`
	AuthURL     string            `json:"auth_url,omitempty"`
	ClientID    string            `json:"client_id,omitempty"`
	Scope       []string          `json:"scope,omitempty"`
	Additional  map[string]string `json:"additional,omitempty"`
}

type AuthRefreshParams

type AuthRefreshParams struct {
	RefreshToken string   `json:"refresh_token"`
	Mode         AuthMode `json:"mode,omitempty"`
}

type AuthResponsePayload

type AuthResponsePayload struct {
	Data AuthResult `json:"data"`
}

type AuthResult

type AuthResult struct {
	RefreshToken string `json:"refresh_token"`
	AccessToken  string `json:"access_token"`
	Expires      int64  `json:"expires"`
}

type Avg

type Avg struct {
	Fields []string
}

func (Avg) EncodeValues

func (agg Avg) EncodeValues(key string, v *url.Values) error

type AvgDistinct

type AvgDistinct struct {
	Fields []string
}

func (AvgDistinct) EncodeValues

func (agg AvgDistinct) EncodeValues(key string, v *url.Values) error

type Between

type Between[T any] struct {
	Values [2]T `json:"_between"`
}

type ByField

type ByField struct {
	Name   string     `json:"-"`
	Filter FilterRule `json:"-"`
}

func (ByField) MarshalJSON

func (f ByField) MarshalJSON() ([]byte, error)

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(baseURL string, options ...ClientOption) (*Client, error)

func (*Client) AuthLogin

func (c *Client) AuthLogin(ctx context.Context, options AuthLoginParams) (AuthResult, error)

func (*Client) AuthLogout

func (c *Client) AuthLogout(ctx context.Context, options AuthLogoutParams) error

func (*Client) AuthOTPVerify

func (c *Client) AuthOTPVerify(ctx context.Context, options OTPVerifyParams) (AuthResult, error)

func (*Client) AuthPasswordReset

func (c *Client) AuthPasswordReset(ctx context.Context, options PasswordResetParams) error

func (*Client) AuthProviders

func (c *Client) AuthProviders(ctx context.Context) ([]AuthProvider, error)

func (*Client) AuthRefresh

func (c *Client) AuthRefresh(ctx context.Context, options AuthRefreshParams) (AuthResult, error)

func (*Client) AuthResetPasswordRequest

func (c *Client) AuthResetPasswordRequest(ctx context.Context, options PasswordResetRequestParams) error

func (*Client) RandomString

func (c *Client) RandomString(ctx context.Context, length int) (string, error)

func (*Client) ServerHealth

func (c *Client) ServerHealth(ctx context.Context) (string, error)

func (*Client) ServerInfo

func (c *Client) ServerInfo(ctx context.Context) (ServerInfo, error)

func (*Client) ServerPing

func (c *Client) ServerPing(ctx context.Context) (string, error)

type ClientOption

type ClientOption func(c *Client)

func WithExtractTokenFromContext

func WithExtractTokenFromContext(enabled bool) ClientOption

func WithStaticToken

func WithStaticToken(token string) ClientOption

type Contains

type Contains struct {
	Value string `json:"_contains"`
}

type Count

type Count struct {
	Fields []string
}

func (Count) EncodeValues

func (agg Count) EncodeValues(key string, v *url.Values) error

type CountDistinct

type CountDistinct struct {
	Fields []string
}

func (CountDistinct) EncodeValues

func (agg CountDistinct) EncodeValues(key string, v *url.Values) error

type CreateItemRequest

type CreateItemRequest[T any] struct {
	ReadItemQuery

	Collection string
	IsSystem   bool
	Data       any

	Token string
	// contains filtered or unexported fields
}

func NewCreateItem

func NewCreateItem[T any](collection string, data any) *CreateItemRequest[T]

func (*CreateItemRequest[T]) SendBy

func (r *CreateItemRequest[T]) SendBy(client *Client) (T, error)

func (*CreateItemRequest[T]) SetContext

func (r *CreateItemRequest[T]) SetContext(ctx context.Context) *CreateItemRequest[T]

func (*CreateItemRequest[T]) SetData

func (r *CreateItemRequest[T]) SetData(data any) *CreateItemRequest[T]

func (*CreateItemRequest[T]) SetDeep

func (r *CreateItemRequest[T]) SetDeep(v map[string]DeepQuery) *CreateItemRequest[T]

func (*CreateItemRequest[T]) SetIsSystem

func (r *CreateItemRequest[T]) SetIsSystem(v bool) *CreateItemRequest[T]

func (*CreateItemRequest[T]) SetToken

func (r *CreateItemRequest[T]) SetToken(token string) *CreateItemRequest[T]

type DeepQuery

type DeepQuery struct {
	Filter any      `json:"_filter,omitempty"`
	Sort   []string `json:"_sort,omitempty"`
	Search string   `json:"_search,omitempty"`
	Offset int      `json:"_offset,omitempty"`
	Limit  int      `json:"_limit,omitempty"`
	Page   int      `json:"_page,omitempty"`
}

type DeleteItemRequest

type DeleteItemRequest struct {
	Collection, ID string
	IsSystem       bool

	Token string
	// contains filtered or unexported fields
}

func NewDeleteItem

func NewDeleteItem(collection, id string) *DeleteItemRequest

func (*DeleteItemRequest) SendBy

func (r *DeleteItemRequest) SendBy(client *Client) error

func (*DeleteItemRequest) SetContext

func (r *DeleteItemRequest) SetContext(ctx context.Context) *DeleteItemRequest

func (*DeleteItemRequest) SetIsSystem

func (r *DeleteItemRequest) SetIsSystem(v bool) *DeleteItemRequest

func (*DeleteItemRequest) SetToken

func (r *DeleteItemRequest) SetToken(token string) *DeleteItemRequest

type DeleteItemsQuery

type DeleteItemsQuery struct {
	Filter FilterRule `json:"filter"`
}

type DeleteItemsRequest

type DeleteItemsRequest[ID comparable] struct {
	DeleteItemsRequestPayload

	Collection string
	IsSystem   bool

	IDs []ID

	Token string
	// contains filtered or unexported fields
}

func NewDeleteItems

func NewDeleteItems[ID comparable](collection string, ids ...ID) *DeleteItemsRequest[ID]

func (*DeleteItemsRequest[ID]) SendBy

func (r *DeleteItemsRequest[ID]) SendBy(client *Client) error

func (*DeleteItemsRequest[ID]) SetContext

func (r *DeleteItemsRequest[ID]) SetContext(ctx context.Context) *DeleteItemsRequest[ID]

func (*DeleteItemsRequest[ID]) SetFilter

func (r *DeleteItemsRequest[ID]) SetFilter(rule FilterRule) *DeleteItemsRequest[ID]

func (*DeleteItemsRequest[ID]) SetIDs

func (r *DeleteItemsRequest[ID]) SetIDs(ids ...ID) *DeleteItemsRequest[ID]

func (*DeleteItemsRequest[ID]) SetIsSystem

func (r *DeleteItemsRequest[ID]) SetIsSystem(v bool) *DeleteItemsRequest[ID]

func (*DeleteItemsRequest[ID]) SetToken

func (r *DeleteItemsRequest[ID]) SetToken(token string) *DeleteItemsRequest[ID]

type DeleteItemsRequestPayload

type DeleteItemsRequestPayload struct {
	Query DeleteItemsQuery `json:"query"`
}

type EndsWith

type EndsWith struct {
	Value string `json:"_ends_with"`
}

type Equal

type Equal[T any] struct {
	Value T `json:"_eq"`
}

type Error

type Error struct {
	Extensions ErrorExtensions `json:"extensions,omitempty"`
	Message    string          `json:"message"`
}

func (Error) Error

func (err Error) Error() string

func (Error) Status

func (err Error) Status() int

type ErrorCode

type ErrorCode string
const (
	ForbiddenErrorCode            ErrorCode = "FORBIDDEN"
	InvalidIPErrorCode            ErrorCode = "INVALID_IP"
	InvalidOTPErrorCode           ErrorCode = "INVALID_OTP"
	InvalidQueryErrorCode         ErrorCode = "INVALID_QUERY"
	InvalidTokenErrorCode         ErrorCode = "INVALID_TOKEN"
	TokenExpiredErrorCode         ErrorCode = "TOKEN_EXPIRED"
	RouteNotFoundErrorCode        ErrorCode = "ROUTE_NOT_FOUND"
	InvalidPayloadErrorCode       ErrorCode = "INVALID_PAYLOAD"
	RequestExceededErrorCode      ErrorCode = "REQUESTS_EXCEEDED"
	FailedValidationErrorCode     ErrorCode = "FAILED_VALIDATION"
	ServiceUnavailableErrorCode   ErrorCode = "SERVICE_UNAVAILABLE"
	InvalidCredentialsErrorCode   ErrorCode = "INVALID_CREDENTIALS"
	UnprocessableContentErrorCode ErrorCode = "UNPROCESSABLE_CONTENT"
	UnsupportedMediaTypeErrorCode ErrorCode = "UNSUPPORTED_MEDIA_TYPE"
)

func (ErrorCode) Status

func (code ErrorCode) Status() int

type ErrorExtensions

type ErrorExtensions struct {
	Code ErrorCode `json:"code,omitempty"`
}

type Errors

type Errors []Error

func (Errors) Error

func (errs Errors) Error() string

func (Errors) Status

func (errs Errors) Status() int

type ErrorsPayload

type ErrorsPayload struct {
	Errors Errors `json:"errors"`
}

type FilterRule

type FilterRule interface {
	// contains filtered or unexported methods
}

type GreaterThan

type GreaterThan[T any] struct {
	Value T `json:"_gt"`
}

type GreaterThanOrEqual

type GreaterThanOrEqual[T any] struct {
	Value T `json:"_gte"`
}

type Has

type Has struct {
	Filter FilterRule `json:"_has"`
}

type IContains

type IContains struct {
	Value string `json:"_icontains"`
}

type IEndsWith

type IEndsWith struct {
	Value string `json:"_iends_with"`
}

type IStartsWith

type IStartsWith struct {
	Value string `json:"_istarts_with"`
}

type IsEmpty

type IsEmpty struct {
	Value bool `json:"_empty"`
}

type IsNotEmpty

type IsNotEmpty struct {
	Value bool `json:"_nempty"`
}

type IsNotNull

type IsNotNull struct {
	Value bool `json:"_nnull"`
}

type IsNotOneOf

type IsNotOneOf[T any] struct {
	Values []T `json:"_nin"`
}

type IsNull

type IsNull struct {
	Value bool `json:"_null"`
}

type IsOneOf

type IsOneOf[T any] struct {
	Values []T `json:"_in"`
}

type LessThan

type LessThan[T any] struct {
	Value T `json:"_lt"`
}

type LessThanOrEqual

type LessThanOrEqual[T any] struct {
	Value T `json:"_lte"`
}

type Like

type Like struct {
	Value string `json:"_like"`
}

type Many

type Many struct {
	Rules []AggregateRule
}

func (Many) EncodeValues

func (agg Many) EncodeValues(key string, v *url.Values) error

type Max

type Max struct {
	Fields []string
}

func (Max) EncodeValues

func (agg Max) EncodeValues(key string, v *url.Values) error

type Min

type Min struct {
	Fields []string
}

func (Min) EncodeValues

func (agg Min) EncodeValues(key string, v *url.Values) error

type NBetween

type NBetween[T any] struct {
	Values [2]T `json:"_nbetween"`
}

type NContains

type NContains struct {
	Value string `json:"_ncontains"`
}

type NEndsWith

type NEndsWith struct {
	Value string `json:"_nends_with"`
}

type NHas

type NHas struct {
	Filter FilterRule `json:"_nhas"`
}

type NLike

type NLike struct {
	Value string `json:"_nlike"`
}

type NStartsWith

type NStartsWith struct {
	Value string `json:"_nstarts_with"`
}

type None

type None struct {
	Filter FilterRule `json:"_none"`
}

type NotEqual

type NotEqual[T any] struct {
	Value T `json:"_neq"`
}

type OR

type OR struct {
	Filters []FilterRule `json:"_or"`
}

type OTPVerifyParams

type OTPVerifyParams struct {
	OTP string `json:"otp"`
}

type PasswordResetParams

type PasswordResetParams struct {
	Token    string `json:"token"`
	Password string `json:"password"`
}

type PasswordResetRequestParams

type PasswordResetRequestParams struct {
	Email string   `json:"email"`
	Mode  AuthMode `json:"mode,omitempty"`
}

type ReadItemPayload

type ReadItemPayload[T any] struct {
	Data T `json:"data"`
}

type ReadItemQuery

type ReadItemQuery struct {
	Deep helpers.URLParamJSON `url:"deep,omitempty"`
}

type ReadItemRequest

type ReadItemRequest[T any] struct {
	ReadItemQuery

	Collection, ID string
	IsSystem       bool

	Token string
	// contains filtered or unexported fields
}

func NewReadItem

func NewReadItem[T any](collection, id string) *ReadItemRequest[T]

func (*ReadItemRequest[T]) SendBy

func (r *ReadItemRequest[T]) SendBy(client *Client) (T, error)

func (*ReadItemRequest[T]) SetContext

func (r *ReadItemRequest[T]) SetContext(ctx context.Context) *ReadItemRequest[T]

func (*ReadItemRequest[T]) SetDeep

func (r *ReadItemRequest[T]) SetDeep(v map[string]DeepQuery) *ReadItemRequest[T]

func (*ReadItemRequest[T]) SetIsSystem

func (r *ReadItemRequest[T]) SetIsSystem(v bool) *ReadItemRequest[T]

func (*ReadItemRequest[T]) SetToken

func (r *ReadItemRequest[T]) SetToken(token string) *ReadItemRequest[T]

type ReadItemsPayload

type ReadItemsPayload[T any] struct {
	Data []T `json:"data"`
}

type ReadItemsQuery

type ReadItemsQuery struct {
	Alias  map[string]string    `url:"alias,omitempty"`
	Filter helpers.URLParamJSON `url:"filter,omitempty"`
	Sort   []string             `url:"sort,omitempty"`
	Deep   helpers.URLParamJSON `url:"deep,omitempty"`
	Search string               `url:"search,omitempty"`
	Offset int                  `url:"offset,omitempty"`
	Limit  int                  `url:"limit,omitempty"`
	Page   int                  `url:"page,omitempty"`
}

type ReadItemsRequest

type ReadItemsRequest[T any] struct {
	ReadItemsQuery

	Collection string
	IsSystem   bool

	Token string
	// contains filtered or unexported fields
}

func NewReadItems

func NewReadItems[T any](collection string) *ReadItemsRequest[T]

func (*ReadItemsRequest[T]) SendBy

func (r *ReadItemsRequest[T]) SendBy(client *Client) ([]T, error)

func (*ReadItemsRequest[T]) SetAlias

func (r *ReadItemsRequest[T]) SetAlias(v map[string]string) *ReadItemsRequest[T]

func (*ReadItemsRequest[T]) SetContext

func (r *ReadItemsRequest[T]) SetContext(ctx context.Context) *ReadItemsRequest[T]

func (*ReadItemsRequest[T]) SetDeep

func (r *ReadItemsRequest[T]) SetDeep(v map[string]DeepQuery) *ReadItemsRequest[T]

func (*ReadItemsRequest[T]) SetFilter

func (r *ReadItemsRequest[T]) SetFilter(rule FilterRule) *ReadItemsRequest[T]

func (*ReadItemsRequest[T]) SetIsSystem

func (r *ReadItemsRequest[T]) SetIsSystem(v bool) *ReadItemsRequest[T]

func (*ReadItemsRequest[T]) SetLimit

func (r *ReadItemsRequest[T]) SetLimit(limit int) *ReadItemsRequest[T]

func (*ReadItemsRequest[T]) SetOffset

func (r *ReadItemsRequest[T]) SetOffset(offset int) *ReadItemsRequest[T]

func (*ReadItemsRequest[T]) SetPage

func (r *ReadItemsRequest[T]) SetPage(page int) *ReadItemsRequest[T]

func (*ReadItemsRequest[T]) SetSearch

func (r *ReadItemsRequest[T]) SetSearch(search string) *ReadItemsRequest[T]

func (*ReadItemsRequest[T]) SetSort

func (r *ReadItemsRequest[T]) SetSort(sort []string) *ReadItemsRequest[T]

func (*ReadItemsRequest[T]) SetToken

func (r *ReadItemsRequest[T]) SetToken(token string) *ReadItemsRequest[T]

type ReadSingletonQuery

type ReadSingletonQuery struct {
	Deep map[string]DeepQuery `url:"deep,omitempty"`
}

type ReadSingletonRequest

type ReadSingletonRequest[T any] struct {
	ReadSingletonQuery

	Collection string
	IsSystem   bool

	Token string
	// contains filtered or unexported fields
}

func NewReadSingleton

func NewReadSingleton[T any](collection string) *ReadSingletonRequest[T]

func (*ReadSingletonRequest[T]) SendBy

func (r *ReadSingletonRequest[T]) SendBy(client *Client) (T, error)

func (*ReadSingletonRequest[T]) SetContext

func (r *ReadSingletonRequest[T]) SetContext(ctx context.Context) *ReadSingletonRequest[T]

func (*ReadSingletonRequest[T]) SetDeep

func (r *ReadSingletonRequest[T]) SetDeep(deep map[string]DeepQuery) *ReadSingletonRequest[T]

func (*ReadSingletonRequest[T]) SetIsSystem

func (r *ReadSingletonRequest[T]) SetIsSystem(v bool) *ReadSingletonRequest[T]

func (*ReadSingletonRequest[T]) SetToken

func (r *ReadSingletonRequest[T]) SetToken(token string) *ReadSingletonRequest[T]

type ServerInfo

type ServerInfo struct {
	Project struct {
		ProjectName string `json:"project_name"`
		ProjectLogo string `json:"project_logo,omitempty"`
		PublicURL   string `json:"public_url,omitempty"`
	} `json:"project"`
	Directus struct {
		Version string `json:"version"`
	} `json:"directus"`
	Node struct {
		Version string `json:"version"`
		Uptime  int64  `json:"uptime"`
	} `json:"node"`
	OS struct {
		Type     string `json:"type"`
		Version  string `json:"version"`
		Uptime   int64  `json:"uptime"`
		TotalMem int64  `json:"totalmem"`
	} `json:"os"`
}

type Some

type Some struct {
	Filter FilterRule `json:"_some"`
}

type StartsWith

type StartsWith struct {
	Value string `json:"_starts_with"`
}

type Sum

type Sum struct {
	Fields []string
}

func (Sum) EncodeValues

func (agg Sum) EncodeValues(key string, v *url.Values) error

type SumDistinct

type SumDistinct struct {
	Fields []string
}

func (SumDistinct) EncodeValues

func (agg SumDistinct) EncodeValues(key string, v *url.Values) error

type UpdateItemRequest

type UpdateItemRequest[T any] struct {
	ReadItemQuery

	Collection, ID string
	IsSystem       bool
	Changes        any

	Token string
	// contains filtered or unexported fields
}

func NewUpdateItem

func NewUpdateItem[T any](collection, id string, changes any) *UpdateItemRequest[T]

func (*UpdateItemRequest[T]) SendBy

func (r *UpdateItemRequest[T]) SendBy(client *Client) (T, error)

func (*UpdateItemRequest[T]) SetChanges

func (r *UpdateItemRequest[T]) SetChanges(changes any) *UpdateItemRequest[T]

func (*UpdateItemRequest[T]) SetContext

func (r *UpdateItemRequest[T]) SetContext(ctx context.Context) *UpdateItemRequest[T]

func (*UpdateItemRequest[T]) SetDeep

func (r *UpdateItemRequest[T]) SetDeep(v map[string]DeepQuery) *UpdateItemRequest[T]

func (*UpdateItemRequest[T]) SetIsSystem

func (r *UpdateItemRequest[T]) SetIsSystem(v bool) *UpdateItemRequest[T]

func (*UpdateItemRequest[T]) SetToken

func (r *UpdateItemRequest[T]) SetToken(token string) *UpdateItemRequest[T]

type UpdateItemsRequest

type UpdateItemsRequest[T any] struct {
	ReadItemsQuery

	Collection string
	Keys       []string

	IsSystem bool

	Changes any

	Token string
	// contains filtered or unexported fields
}

func NewUpdateItems

func NewUpdateItems[T any](collection string, keys []string, changes any) *UpdateItemsRequest[T]

func (*UpdateItemsRequest[T]) SendBy

func (r *UpdateItemsRequest[T]) SendBy(client *Client) (T, error)

func (*UpdateItemsRequest[T]) SetChanges

func (r *UpdateItemsRequest[T]) SetChanges(changes any) *UpdateItemsRequest[T]

func (*UpdateItemsRequest[T]) SetContext

func (r *UpdateItemsRequest[T]) SetContext(ctx context.Context) *UpdateItemsRequest[T]

func (*UpdateItemsRequest[T]) SetDeep

func (r *UpdateItemsRequest[T]) SetDeep(v map[string]DeepQuery) *UpdateItemsRequest[T]

func (*UpdateItemsRequest[T]) SetFilter

func (r *UpdateItemsRequest[T]) SetFilter(rule FilterRule) *UpdateItemsRequest[T]

func (*UpdateItemsRequest[T]) SetIsSystem

func (r *UpdateItemsRequest[T]) SetIsSystem(v bool) *UpdateItemsRequest[T]

func (*UpdateItemsRequest[T]) SetToken

func (r *UpdateItemsRequest[T]) SetToken(token string) *UpdateItemsRequest[T]

type UpdateItemsRequetBody

type UpdateItemsRequetBody struct {
	Data any      `json:"data"`
	Keys []string `json:"keys,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL