cpit

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2024 License: MIT Imports: 12 Imported by: 0

README

cpit

Cockpit CMS Golang Client

Documentation

Index

Constants

View Source
const (
	// State constants
	StateArchived  = -1
	StateDraft     = 0
	StatePublished = 1

	// ReziseMode constants
	ResizeModeThumbnail   = "thumbnail"
	ResizeModeBestFit     = "bestFit"
	ResizeModeResize      = "resize"
	ResizeModeFitToWidth  = "fitToWidth"
	ResizeModeFitToHeight = "fitToHeight"

	// MimeType constants
	MimeTypeAuto = "auto"
	MimeTypeGif  = "gif"
	MimeTypeJpeg = "jpeg"
	MimeTypePng  = "png"
	MimeTypeWebp = "webp"
	MimeTypeBmp  = "bmp"
)

Variables

View Source
var (
	ErrNotFound = errors.New("not found")
)

Functions

func DeleteItem

func DeleteItem(ctx context.Context, model string, id string, opts ...optionFn) error

DeleteItem deletes an item. - model is the name of the model - id is the id of the item

func GetAssetLink(id string, opts ...optionFn) (string, error)

GetAssetLink returns a link to the asset. The resulting link will redirect to the asset. If the asset path is known, use GetUploadLink instead.

func GetImage

func GetImage(ctx context.Context, id string, opts ...optionFn) (string, error)

GetImage requests an image. Returns the image url. - id is the id of the image

func GetItem

func GetItem[T any](ctx context.Context, model string, id string, opts ...optionFn) (*T, error)

GetItem requests an item. - model is the name of the model - id is the id of the item

func GetSingleton

func GetSingleton[T any](ctx context.Context, model string, opts ...optionFn) (T, error)

GetSingleton requests a singleton model. - model is the name of the model

func GetUploadLink(path string, opts ...optionFn) (string, error)

GetUploadLink returns a direct link to the asset file.

func SetDefaultApiKey

func SetDefaultApiKey(key string)

SetDefaultApiKey sets the default api key used for requests.

func SetDefaultBaseURL added in v0.0.4

func SetDefaultBaseURL(url string)

SetDefaultBaseURL sets the default base url used for requests.

func SetDefaultDebugMode

func SetDefaultDebugMode(enabled bool)

SetDefaultDebugMode sets the default debug mode used for requests.

func SetDefaultHttpClient

func SetDefaultHttpClient(c *http.Client)

SetDefaultHttpClient sets the default http client used for requests.

func UpsertItem

func UpsertItem[T any](ctx context.Context, model string, data interface{}, opts ...optionFn) (*T, error)

UpsertItem upserts an item. - model is the name of the model When updating an item, the data/body must contain a valid _id field.

func WithApiKey

func WithApiKey(key string) optionFn

WithApiKey sets the api key for the request.

func WithBaseURL

func WithBaseURL(url string) optionFn

WithBaseURL sets the base url for the request.

func WithDebugMode

func WithDebugMode(enabled bool) optionFn

WithDebugMode sets the debug mode for the request.

func WithFields

func WithFields(fields string) optionFn

WithFields specifies the fields to be returned in the request. See following links for more info: https://getcockpit.com/documentation/core/api/content#project-fields-to-return-from-query https://www.mongodb.com/docs/manual/tutorial/project-fields-from-query-results/ Example to only retrieve the title field: - WithFields(`{"title":1}`)

func WithFilter

func WithFilter(filter string) optionFn

WithFilter specifies the filter to be applied in the request. See following links for more info: https://getcockpit.com/documentation/core/api/content#filtering https://www.mongodb.com/docs/manual/reference/operator/query/ Example to filter items with title containing "cat" (case insensitive): - WithFilter(`{"title": {"$regex": "/cat/i"}}`)

func WithHeight

func WithHeight(h int) optionFn

WithHeight sets the height for the image.

func WithHttpClient

func WithHttpClient(c *http.Client) optionFn

WithHttpClient sets the http client for the request.

func WithLimit

func WithLimit(limit int) optionFn

WithLimit specifies the number of items to return.

func WithLocale

func WithLocale(locale string) optionFn

WithLocale specifies the wanted locale.

func WithMime

func WithMime(mime string) optionFn

WithMime sets the mime type for the image.

func WithPopulate

func WithPopulate(enabled bool) optionFn

WithPopulate specifies if linked content items should be populated.

func WithQuality

func WithQuality(q int) optionFn

WithQuality sets the quality for the image.

func WithResizeMode

func WithResizeMode(m string) optionFn

WithResizeMode sets the resize mode for the image.

func WithSkip

func WithSkip(skip int) optionFn

WithSkip specifies the number of items to skip. Useful for pagination, it must be used in combination with WithLimit or it won't have any effect. When using pagination(WithSkip), cockit uses a different response format. The PaginatedResp model can be used as output to get the total number of items.

func WithSort

func WithSort(sort string) optionFn

WithSort specifies the sort order for the request. Example to sort by title in ascending order: - WithSort(`{"title":1}`) Example to sort by title in descending order: - WithSort(`{"title":-1}`)

func WithWidth

func WithWidth(w int) optionFn

WithWidth sets the width for the image.

Types

type Asset added in v0.0.2

type Asset struct {
	BaseModel
	Hash        string   `json:"_hash,omitempty"`
	Thumbhash   string   `json:"thumbhash,omitempty"`
	Path        string   `json:"path,omitempty"`
	Title       string   `json:"title,omitempty"`
	Mime        string   `json:"mime,omitempty"`
	Type        string   `json:"type,omitempty"`
	Description string   `json:"description,omitempty"`
	Tags        []any    `json:"tags,omitempty"`
	Size        int      `json:"size,omitempty"`
	Colors      []string `json:"colors,omitempty"`
	Width       int      `json:"width,omitempty"`
	Height      int      `json:"height,omitempty"`
	Folder      string   `json:"folder,omitempty"`
}

Asset is a struct that holds the fields for an asset

func GetAsset

func GetAsset(ctx context.Context, id string, opts ...optionFn) (Asset, error)

GetAsset requests an asset. - id is the id of the asset

type BaseModel

type BaseModel struct {
	ID         string `json:"_id,omitempty"`
	State      int    `json:"_state"`
	Modified   int    `json:"_modified,omitempty"`
	ModifiedBy string `json:"_mby,omitempty"`
	Created    int    `json:"_created,omitempty"`
	CreatedBy  string `json:"_cby,omitempty"`
}

BaseModel is a struct that contains the common fields for all models

type Items added in v0.0.2

type Items[T any] struct {
	Data []T `json:"data"`
	Meta struct {
		// Total is the total number of items in the collection and is only
		// present when the collection is paginated using both the limit and
		// skip parameters.
		Total int `json:"total"`
	} `json:"meta"`
}

Items is a struct that contains the fields for a paginated response

func GetItems

func GetItems[T any](ctx context.Context, model string, opts ...optionFn) (Items[T], error)

GetItems requests items of a model. - model is the name of the model

Jump to

Keyboard shortcuts

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