Documentation ¶
Index ¶
- Constants
- Variables
- func DeleteItem(ctx context.Context, model string, id string, opts ...optionFn) error
- func GetAssetLink(id string, opts ...optionFn) (string, error)
- func GetImage(ctx context.Context, id string, opts ...optionFn) (string, error)
- func GetItem[T any](ctx context.Context, model string, id string, opts ...optionFn) (*T, error)
- func GetSingleton[T any](ctx context.Context, model string, opts ...optionFn) (T, error)
- func GetUploadLink(path string, opts ...optionFn) (string, error)
- func SetDefaultApiKey(key string)
- func SetDefaultBaseURL(url string)
- func SetDefaultDebugMode(enabled bool)
- func SetDefaultHttpClient(c *http.Client)
- func UpsertItem[T any](ctx context.Context, model string, data interface{}, opts ...optionFn) (*T, error)
- func WithApiKey(key string) optionFn
- func WithBaseURL(url string) optionFn
- func WithDebugMode(enabled bool) optionFn
- func WithFields(fields string) optionFn
- func WithFilter(filter string) optionFn
- func WithHeight(h int) optionFn
- func WithHttpClient(c *http.Client) optionFn
- func WithLimit(limit int) optionFn
- func WithLocale(locale string) optionFn
- func WithMime(mime string) optionFn
- func WithPopulate(enabled bool) optionFn
- func WithQuality(q int) optionFn
- func WithResizeMode(m string) optionFn
- func WithSkip(skip int) optionFn
- func WithSort(sort string) optionFn
- func WithWidth(w int) optionFn
- type Asset
- type BaseModel
- type Items
Constants ¶
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 ¶
var (
ErrNotFound = errors.New("not found")
)
Functions ¶
func DeleteItem ¶
DeleteItem deletes an item. - model is the name of the model - id is the id of the item
func GetAssetLink ¶ added in v0.0.2
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 GetItem ¶
GetItem requests an item. - model is the name of the model - id is the id of the item
func GetSingleton ¶
GetSingleton requests a singleton model. - model is the name of the model
func GetUploadLink ¶ added in v0.0.2
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 ¶
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 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 WithHttpClient ¶
WithHttpClient sets the http client for the request.
func WithLimit ¶
func WithLimit(limit int) optionFn
WithLimit specifies the number of items to return.
func WithPopulate ¶
func WithPopulate(enabled bool) optionFn
WithPopulate specifies if linked content items should be populated.
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.
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
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