Documentation ¶
Index ¶
- Constants
- Variables
- func FilterJSON(filter Filter) (string, error)
- type Accountability
- type Alterations
- type Client
- type ClientOption
- type Collection
- type CollectionCollapse
- type CollectionMeta
- type CollectionSchema
- type CustomTranslation
- type Dashboard
- type Error
- type ErrorCode
- type ErrorExtensions
- type Field
- type FieldMeta
- type FieldSchema
- type FieldSpecial
- type FieldType
- type FieldWidth
- type File
- type Filter
- func And(filters ...Filter) Filter
- func Between(field string, from, to any) Filter
- func Empty(field string) Filter
- func Eq(field string, value any) Filter
- func Gt(field string, value any) Filter
- func Gte(field string, value any) Filter
- func In(field string, values ...any) Filter
- func Lt(field string, value any) Filter
- func Lte(field string, value any) Filter
- func Neq(field string, value any) Filter
- func Noop() Filter
- func NotEmpty(field string) Filter
- func Or(filters ...Filter) Filter
- func Related(field string, filter Filter) Filter
- func StartsWith(field string, value string) Filter
- type Flow
- type Folder
- type Icon
- type ItemsClient
- func (items *ItemsClient[T]) Create(ctx context.Context, item *T) (*T, error)
- func (items *ItemsClient[T]) Delete(ctx context.Context, id string) error
- func (items *ItemsClient[T]) Filter(ctx context.Context, filter Filter, opts ...ReadOption) ([]*T, error)
- func (items *ItemsClient[T]) Get(ctx context.Context, id string) (*T, error)
- func (items *ItemsClient[T]) List(ctx context.Context, opts ...ReadOption) ([]*T, error)
- func (items *ItemsClient[T]) Update(ctx context.Context, id string, item *T) (*T, error)
- type Nullable
- type Operation
- type Panel
- type Permission
- type PermissionAction
- type Preset
- type ProtoJSON
- type ReadOption
- func WithDeepLimit(field string, limit int64) ReadOption
- func WithDeepSort(field string, sort ...string) ReadOption
- func WithFields(fields ...string) ReadOption
- func WithLimit(limit int64) ReadOption
- func WithNoLimit() ReadOption
- func WithOffset(offset int64) ReadOption
- func WithSort(sort ...string) ReadOption
- type Relation
- type RelationAction
- type RelationDefinition
- type RelationMeta
- type RelationSchema
- type ResourceClient
- func (rc *ResourceClient[T]) Create(ctx context.Context, item *T) (*T, error)
- func (rc *ResourceClient[T]) Delete(ctx context.Context, id string) error
- func (rc *ResourceClient[T]) Get(ctx context.Context, id string) (*T, error)
- func (rc *ResourceClient[T]) List(ctx context.Context) ([]*T, error)
- func (rc *ResourceClient[T]) Patch(ctx context.Context, id string, item *T) (*T, error)
- type Role
- type SingletonClient
- type User
Constants ¶
const ( ErrorCodeRecordNotUnique = "RECORD_NOT_UNIQUE" ErrorCodeInvalidForeignKey = "INVALID_FOREIGN_KEY" )
Variables ¶
var ( // ErrItemNotFound is returned when the item is not found in the collection. ErrItemNotFound = errors.New("directus: item not found") // ErrIEmpty is returned when the item is returned empty. ErrEmpty = errors.New("directus: empty") )
Functions ¶
func FilterJSON ¶
Types ¶
type Accountability ¶ added in v0.16.0
type Accountability string
const ( AccountabilityAll Accountability = "all" AccountabilityActivity Accountability = "activity" )
type Alterations ¶ added in v0.16.15
type Client ¶
type Client struct { Collections *ResourceClient[Collection] CustomTranslations *ResourceClient[CustomTranslation] Folders *ResourceClient[Folder] Relations *ResourceClient[RelationDefinition] Roles *ResourceClient[Role] Users *ResourceClient[User] Presets *ResourceClient[Preset] Operations *ResourceClient[Operation] Flows *ResourceClient[Flow] Files *ResourceClient[File] Permissions *ResourceClient[Permission] Dashboards *ResourceClient[Dashboard] Panels *ResourceClient[Panel] Fields *clientFields // contains filtered or unexported fields }
Client keeps a connection to a Directus instance.
type ClientOption ¶
type ClientOption func(client *Client)
ClinetOption configures a client when creating it.
func WithBodyLogger ¶
func WithBodyLogger() ClientOption
WithBodyLogger prints the request and response bodies to the logger.
func WithLogger ¶
func WithLogger(logger *slog.Logger) ClientOption
WithLogger sets a custom logger for the sent requests and responses received from the server.
type Collection ¶ added in v0.16.0
type Collection struct { Collection string `json:"collection"` Meta CollectionMeta `json:"meta"` Schema *CollectionSchema `json:"schema,omitempty"` Fields []*Field `json:"fields,omitempty"` }
type CollectionCollapse ¶ added in v0.16.0
type CollectionCollapse string
const ( CollectionCollapseOpen CollectionCollapse = "open" CollectionCollapseClosed CollectionCollapse = "closed" CollectionCollapseLocked CollectionCollapse = "locked" )
type CollectionMeta ¶ added in v0.16.0
type CollectionMeta struct { Collection string `json:"collection,omitempty"` Color string `json:"color,omitempty"` Icon Icon `json:"icon,omitempty"` Note string `json:"note,omitempty"` Hidden bool `json:"hidden"` Singleton bool `json:"singleton"` ArchiveField string `json:"archive_field,omitempty"` ArchiveValue string `json:"archive_value,omitempty"` UnarchiveValue string `json:"unarchive_value,omitempty"` ArchiveAppFilter bool `json:"archive_app_filter"` SortField string `json:"sort_field,omitempty"` Group Nullable[string] `json:"group,omitempty"` Sort int64 `json:"sort,omitempty"` Collapse CollectionCollapse `json:"collapse,omitempty"` Versioning bool `json:"versioning,omitempty"` Accountability Nullable[Accountability] `json:"accountability"` System bool `json:"system,omitempty"` PreviewURL string `json:"preview_url,omitempty"` DisplayTemplate string `json:"display_template,omitempty"` Unknown map[string]any `json:"-"` }
func (*CollectionMeta) MarshalJSON ¶ added in v0.16.0
func (meta *CollectionMeta) MarshalJSON() ([]byte, error)
func (*CollectionMeta) UnmarshalJSON ¶ added in v0.16.0
func (meta *CollectionMeta) UnmarshalJSON(data []byte) error
type CollectionSchema ¶ added in v0.16.0
type CollectionSchema struct { Name string `json:"name"` Comment string `json:"comment,omitempty"` Collation string `json:"collation,omitempty"` Engine string `json:"engine,omitempty"` Schema string `json:"schema,omitempty"` Unknown map[string]any `json:"-"` }
func (*CollectionSchema) MarshalJSON ¶ added in v0.16.0
func (schema *CollectionSchema) MarshalJSON() ([]byte, error)
func (*CollectionSchema) UnmarshalJSON ¶ added in v0.16.0
func (schema *CollectionSchema) UnmarshalJSON(data []byte) error
type CustomTranslation ¶ added in v0.16.0
type Error ¶ added in v0.15.0
type Error struct { Message string `json:"message"` Extensions ErrorExtensions `json:"extensions"` }
type ErrorExtensions ¶ added in v0.15.0
type ErrorExtensions struct {
Code ErrorCode `json:"code"`
}
type Field ¶ added in v0.12.0
type Field struct { Collection string `json:"collection"` Field string `json:"field"` Type FieldType `json:"type"` Meta FieldMeta `json:"meta"` Schema *FieldSchema `json:"schema,omitempty"` }
type FieldMeta ¶ added in v0.12.0
type FieldMeta struct { ID int64 `json:"id,omitempty"` Hidden bool `json:"hidden"` Width FieldWidth `json:"width,omitempty"` ReadOnly bool `json:"read_only"` Required bool `json:"required"` Sort int64 `json:"sort,omitempty"` System bool `json:"system,omitempty"` Special []FieldSpecial `json:"special,omitempty"` Unknown map[string]any `json:"-"` }
func (*FieldMeta) HasSpecial ¶ added in v0.16.12
func (meta *FieldMeta) HasSpecial(special FieldSpecial) bool
func (*FieldMeta) UnmarshalJSON ¶ added in v0.16.0
type FieldSchema ¶ added in v0.16.0
type FieldSchema struct { Name string `json:"name,omitempty"` Table string `json:"table,omitempty"` DataType string `json:"data_type"` MaxLength int64 `json:"max_length,omitempty"` IsNullable bool `json:"is_nullable"` IsUnique bool `json:"is_unique,omitempty"` IsPrimaryKey bool `json:"is_primary_key,omitempty"` HasAutoIncrement bool `json:"has_auto_increment,omitempty"` Unknown map[string]any `json:"-"` }
func (*FieldSchema) UnmarshalJSON ¶ added in v0.16.0
func (schema *FieldSchema) UnmarshalJSON(data []byte) error
type FieldSpecial ¶ added in v0.16.0
type FieldSpecial string
const ( FieldSpecialManyToOne FieldSpecial = "m2o" FieldSpecialDateCreated FieldSpecial = "date-created" FieldSpecialDateUpdated FieldSpecial = "date-updated" FieldSpecialUUID FieldSpecial = "uuid" FieldSpecialUserCreated FieldSpecial = "user-created" FieldSpecialUserUpdated FieldSpecial = "user-updated" FieldSpecialFile FieldSpecial = "file" FieldSpecialAlias FieldSpecial = "alias" FieldSpecialNoData FieldSpecial = "no-data" FieldSpecialCastBoolean FieldSpecial = "cast-boolean" FieldSpecialGroup FieldSpecial = "group" )
func (*FieldSpecial) UnmarshalJSON ¶ added in v0.16.2
func (special *FieldSpecial) UnmarshalJSON(data []byte) error
type FieldWidth ¶ added in v0.12.0
type FieldWidth string
const ( FieldWidthFull FieldWidth = "full" FieldWidthHalf FieldWidth = "half" )
type File ¶ added in v0.19.0
type File struct { FileSize Nullable[int64] `json:"file_size"` ID string `json:"id,omitempty"` Folder Nullable[string] `json:"folder"` Title Nullable[string] `json:"title"` Type Nullable[string] `json:"type"` Description Nullable[string] `json:"description"` Storage string `json:"storage"` Charset Nullable[string] `json:"charset"` FilenameDowload string `json:"filename_download"` FocalPointX Nullable[int32] `json:"focal_point_x"` FocalPointY Nullable[int32] `json:"focal_point_y"` Width Nullable[int32] `json:"width"` Height Nullable[int32] `json:"height"` Duration Nullable[int32] `json:"duration"` Location Nullable[string] `json:"location"` Tags Nullable[string] `json:"tags"` Embed Nullable[string] `json:"embed"` FilenameDisk Nullable[string] `json:"filename_disk"` Unknown map[string]any `json:"-"` }
func (*File) MarshalJSON ¶ added in v0.19.0
func (*File) UnmarshalJSON ¶ added in v0.19.0
type Filter ¶
type Filter interface { String() string // contains filtered or unexported methods }
func StartsWith ¶ added in v0.17.0
type Flow ¶ added in v0.19.0
type Flow struct { ID string `json:"id,omitempty"` Name string `json:"name"` Status string `json:"status"` Description Nullable[string] `json:"description"` Accountability Accountability `json:"accountability"` Color string `json:"color,omitempty"` Icon Icon `json:"icon,omitempty"` Operation Nullable[string] `json:"operation"` Unknown map[string]any `json:"-"` }
func (*Flow) MarshalJSON ¶ added in v0.19.0
func (*Flow) UnmarshalJSON ¶ added in v0.19.0
type ItemsClient ¶
type ItemsClient[T any] struct { // contains filtered or unexported fields }
ItemsClient access the items API in a type-safe way.
func NewItemsClient ¶
func NewItemsClient[T any](client *Client, collection string, opts ...ReadOption) *ItemsClient[T]
NewItemsClient creates a new client to access & write items in a type-safe way.
func (*ItemsClient[T]) Create ¶
func (items *ItemsClient[T]) Create(ctx context.Context, item *T) (*T, error)
Create a new item in the collection.
func (*ItemsClient[T]) Delete ¶
func (items *ItemsClient[T]) Delete(ctx context.Context, id string) error
Delete an item from the collection by its primary key.
func (*ItemsClient[T]) Filter ¶
func (items *ItemsClient[T]) Filter(ctx context.Context, filter Filter, opts ...ReadOption) ([]*T, error)
Filter items of the collection.
func (*ItemsClient[T]) Get ¶
func (items *ItemsClient[T]) Get(ctx context.Context, id string) (*T, error)
Get a single item by its primary key. If it cannot be found, it returns ErrItemNotFound.
func (*ItemsClient[T]) List ¶
func (items *ItemsClient[T]) List(ctx context.Context, opts ...ReadOption) ([]*T, error)
List items of the collection.
type Operation ¶ added in v0.19.0
type Operation struct { ID string `json:"id,omitempty"` Flow string `json:"flow"` Key string `json:"key"` PositionX int32 `json:"position_x"` PositionY int32 `json:"position_y"` Type string `json:"type"` Name Nullable[string] `json:"name"` Reject Nullable[string] `json:"reject"` Resolve Nullable[string] `json:"resolve"` Unknown map[string]any `json:"-"` }
func (*Operation) MarshalJSON ¶ added in v0.19.0
func (*Operation) UnmarshalJSON ¶ added in v0.19.0
type Panel ¶ added in v0.19.0
type Panel struct { ID Nullable[string] `json:"id"` Dashboard string `json:"dashboard"` Height int32 `json:"height"` Width int32 `json:"width"` PositionX int32 `json:"position_x"` PositionY int32 `json:"position_y"` ShowHeader bool `json:"show_header"` Type string `json:"type"` Color Nullable[string] `json:"color"` Icon Icon `json:"icon"` Name Nullable[string] `json:"name"` Note Nullable[string] `json:"note"` Unknown map[string]any `json:"-"` }
func (*Panel) MarshalJSON ¶ added in v0.19.0
func (*Panel) UnmarshalJSON ¶ added in v0.19.0
type Permission ¶ added in v0.19.0
type Permission struct { ID int64 `json:"id,omitempty"` Role Nullable[string] `json:"role"` Collection string `json:"collection"` Action PermissionAction `json:"action"` Fields Nullable[string] `json:"fields"` Unknown map[string]any `json:"-"` }
func (*Permission) MarshalJSON ¶ added in v0.19.0
func (permission *Permission) MarshalJSON() ([]byte, error)
func (*Permission) UnmarshalJSON ¶ added in v0.19.0
func (permission *Permission) UnmarshalJSON(data []byte) error
type PermissionAction ¶ added in v0.19.0
type PermissionAction string
const ( PermissionActionCreate PermissionAction = "create" PermissionActionRead PermissionAction = "read" PermissionActionUpdate PermissionAction = "update" PermissionActionDelete PermissionAction = "delete" )
type Preset ¶ added in v0.18.0
type Preset struct { ID int64 `json:"id,omitempty"` Bookmark Nullable[string] `json:"bookmark"` User Nullable[string] `json:"user"` Role Nullable[string] `json:"role"` Collection string `json:"collection"` Layout Nullable[string] `json:"layout"` Icon Nullable[string] `json:"icon"` Unknown map[string]any `json:"-"` }
func (*Preset) MarshalJSON ¶ added in v0.18.0
func (*Preset) UnmarshalJSON ¶ added in v0.18.0
type ProtoJSON ¶
func NewProtoJSON ¶
func (ProtoJSON[T]) MarshalJSON ¶
func (*ProtoJSON[T]) UnmarshalJSON ¶
type ReadOption ¶
ReadOption configures the returned data from Directus when reading or returning items.
func WithDeepLimit ¶ added in v0.10.0
func WithDeepLimit(field string, limit int64) ReadOption
WithDeepLimit limits the number of returned deep relations of each item.
func WithDeepSort ¶ added in v0.10.0
func WithDeepSort(field string, sort ...string) ReadOption
WithDeepSort sorts the deep relations of each returned item by the given fields. Use a minus sign (-) to sort in descending order. It does not order the items themselves. To sort the items, use WithSort.
func WithFields ¶
func WithFields(fields ...string) ReadOption
WithFields filters the fields of each returned item. It can add relations deep fields to the response to obtain them in the same request.
func WithLimit ¶ added in v0.10.0
func WithLimit(limit int64) ReadOption
WithLimit limits the number of returned items.
func WithNoLimit ¶ added in v0.10.0
func WithNoLimit() ReadOption
WithNoLimit returns all items of the collection.
func WithOffset ¶ added in v0.10.0
func WithOffset(offset int64) ReadOption
WithOffset skips the first n items.
func WithSort ¶
func WithSort(sort ...string) ReadOption
WithSort sorts the returned items by the given fields. Use a minus sign (-) to sort in descending order. It does not order deep relations inside each of the items. To sort deep relations, use WithDeepSort.
type Relation ¶
type Relation[T any] struct { // contains filtered or unexported fields }
func NewRelation ¶
func (Relation[T]) MarshalJSON ¶
func (*Relation[T]) UnmarshalJSON ¶
type RelationAction ¶ added in v0.16.0
type RelationAction string
const ( RelationActionCascade RelationAction = "CASCADE" RelationActionSetNull RelationAction = "SET NULL" RelationActionNoAction RelationAction = "NO ACTION" )
func (*RelationAction) UnmarshalJSON ¶ added in v0.16.11
func (action *RelationAction) UnmarshalJSON(data []byte) error
type RelationDefinition ¶ added in v0.16.0
type RelationDefinition struct { Collection string `json:"collection"` Field string `json:"field"` RelatedCollection string `json:"related_collection"` Schema RelationSchema `json:"schema"` Meta RelationMeta `json:"meta"` }
type RelationMeta ¶ added in v0.16.0
type RelationMeta struct { ID int64 `json:"id,omitempty"` System bool `json:"system,omitempty"` Unknown map[string]any `json:"-"` }
func (*RelationMeta) MarshalJSON ¶ added in v0.16.0
func (meta *RelationMeta) MarshalJSON() ([]byte, error)
func (*RelationMeta) UnmarshalJSON ¶ added in v0.16.0
func (meta *RelationMeta) UnmarshalJSON(data []byte) error
type RelationSchema ¶ added in v0.16.0
type RelationSchema struct { Table string `json:"table"` Column string `json:"column"` OnUpdate RelationAction `json:"on_update"` OnDelete RelationAction `json:"on_delete"` Unknown map[string]any `json:"-"` }
func (*RelationSchema) MarshalJSON ¶ added in v0.16.0
func (schema *RelationSchema) MarshalJSON() ([]byte, error)
func (*RelationSchema) UnmarshalJSON ¶ added in v0.16.0
func (schema *RelationSchema) UnmarshalJSON(data []byte) error
type ResourceClient ¶ added in v0.16.0
type ResourceClient[T any] struct { // contains filtered or unexported fields }
func NewResourceClient ¶ added in v0.16.0
func NewResourceClient[T any](client *Client, endpoint string) *ResourceClient[T]
func (*ResourceClient[T]) Create ¶ added in v0.16.0
func (rc *ResourceClient[T]) Create(ctx context.Context, item *T) (*T, error)
func (*ResourceClient[T]) Delete ¶ added in v0.16.0
func (rc *ResourceClient[T]) Delete(ctx context.Context, id string) error
func (*ResourceClient[T]) Get ¶ added in v0.16.0
func (rc *ResourceClient[T]) Get(ctx context.Context, id string) (*T, error)
type SingletonClient ¶
type SingletonClient[T any] struct { // contains filtered or unexported fields }
func NewSingletonClient ¶
func NewSingletonClient[T any](client *Client, collection string, opts ...ReadOption) *SingletonClient[T]
type User ¶ added in v0.13.0
type User struct { ID string `json:"id,omitempty"` FirstName string `json:"first_name,omitempty"` LastName string `json:"last_name,omitempty"` Email string `json:"email,omitempty"` Role string `json:"role,omitempty"` Provider string `json:"provider,omitempty"` ExternalIdentifier string `json:"external_identifier,omitempty"` }