Documentation
¶
Overview ¶
Package strapi provides a client for interacting with Strapi CMS API.
The Strapi client supports blog post management, content type operations, and other CMS-related functionality.
Example usage:
client := strapi.New(
strapi.WithAPIClient(apiClient),
strapi.WithBaseURL("https://strapi.example.com"),
)
// Create a blog post
post, err := client.CreateBlogPost(ctx, &strapi.CreateBlogPostRequest{
Title: "My First Post",
Content: "# Hello World\n\nThis is my first blog post!",
Author: "John Doe",
Status: "draft",
})
Index ¶
- type BlogPost
- type BlogPostAttributes
- type BlogPostData
- type Client
- func (c *Client) CreateBlogPost(ctx context.Context, req *CreateBlogPostRequest) (*BlogPost, error)
- func (c *Client) CreateContent(ctx context.Context, contentType string, data map[string]interface{}) (*ContentEntry, error)
- func (c *Client) DeleteBlogPost(ctx context.Context, id int) error
- func (c *Client) DeleteContent(ctx context.Context, contentType string, id int) error
- func (c *Client) GetBlogPost(ctx context.Context, id int) (*BlogPost, error)
- func (c *Client) ListBlogPosts(ctx context.Context, opts *ListOptions) ([]*BlogPost, *ListMeta, error)
- func (c *Client) ListContent(ctx context.Context, contentType string, opts *ListOptions) ([]*ContentEntry, *ListMeta, error)
- func (c *Client) ListContentTypes(ctx context.Context) ([]*ContentType, error)
- func (c *Client) PublishBlogPost(ctx context.Context, id int) (*BlogPost, error)
- func (c *Client) UpdateBlogPost(ctx context.Context, id int, req *UpdateBlogPostRequest) (*BlogPost, error)
- func (c *Client) UpdateContent(ctx context.Context, contentType string, id int, data map[string]interface{}) (*ContentEntry, error)
- type ContentEntry
- type ContentType
- type ContentTypeInfo
- type CreateBlogPostRequest
- type CreateBlogPostResponse
- type CreateContentRequest
- type CreateContentResponse
- type DeleteBlogPostResponse
- type ErrorDetail
- type ErrorResponse
- type GetBlogPostResponse
- type ListBlogPostsResponse
- type ListContentResponse
- type ListContentTypesResponse
- type ListMeta
- type ListOptions
- type Option
- type Pagination
- type PublishBlogPostData
- type PublishBlogPostRequest
- type PublishBlogPostResponse
- type UpdateBlogPostRequest
- type UpdateBlogPostResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BlogPost ¶
type BlogPost struct {
ID int `json:"id"`
Attributes *BlogPostAttributes `json:"attributes"`
Meta map[string]interface{} `json:"meta,omitempty"`
}
BlogPost represents a blog post in Strapi CMS.
type BlogPostAttributes ¶
type BlogPostAttributes struct {
Title string `json:"title"`
Content string `json:"content"`
Slug string `json:"slug,omitempty"`
Author string `json:"author,omitempty"`
Status string `json:"status"` // draft, published
PublishedAt *time.Time `json:"publishedAt,omitempty"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
Tags []string `json:"tags,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
BlogPostAttributes contains the attributes of a blog post.
type BlogPostData ¶
type BlogPostData struct {
Title string `json:"title"`
Content string `json:"content"`
Slug string `json:"slug,omitempty"`
Author string `json:"author,omitempty"`
Status string `json:"status,omitempty"` // draft (default), published
Tags []string `json:"tags,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
BlogPostData contains the data for creating or updating a blog post.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents a client for Strapi CMS operations.
func (*Client) CreateBlogPost ¶
CreateBlogPost creates a new blog post in Strapi.
func (*Client) CreateContent ¶
func (c *Client) CreateContent(ctx context.Context, contentType string, data map[string]interface{}) (*ContentEntry, error)
CreateContent creates a new entry in a specified content type.
func (*Client) DeleteBlogPost ¶
DeleteBlogPost deletes a blog post by ID.
func (*Client) DeleteContent ¶
DeleteContent deletes an entry from a specified content type.
func (*Client) GetBlogPost ¶
GetBlogPost retrieves a single blog post by ID.
func (*Client) ListBlogPosts ¶
func (c *Client) ListBlogPosts(ctx context.Context, opts *ListOptions) ([]*BlogPost, *ListMeta, error)
ListBlogPosts lists blog posts with optional filters.
func (*Client) ListContent ¶
func (c *Client) ListContent(ctx context.Context, contentType string, opts *ListOptions) ([]*ContentEntry, *ListMeta, error)
ListContent lists entries from a specified content type.
func (*Client) ListContentTypes ¶
func (c *Client) ListContentTypes(ctx context.Context) ([]*ContentType, error)
ListContentTypes lists all available content types in Strapi.
func (*Client) PublishBlogPost ¶
PublishBlogPost publishes a blog post by updating its status and publishedAt timestamp.
func (*Client) UpdateBlogPost ¶
func (c *Client) UpdateBlogPost(ctx context.Context, id int, req *UpdateBlogPostRequest) (*BlogPost, error)
UpdateBlogPost updates an existing blog post.
func (*Client) UpdateContent ¶
func (c *Client) UpdateContent(ctx context.Context, contentType string, id int, data map[string]interface{}) (*ContentEntry, error)
UpdateContent updates an entry in a specified content type.
type ContentEntry ¶
type ContentEntry struct {
ID int `json:"id"`
Attributes map[string]interface{} `json:"attributes"`
}
ContentEntry represents a generic content entry in Strapi.
type ContentType ¶
type ContentType struct {
UID string `json:"uid"`
DisplayName string `json:"displayName"`
Kind string `json:"kind"` // singleType, collectionType
Info *ContentTypeInfo `json:"info,omitempty"`
Attributes map[string]interface{} `json:"attributes,omitempty"`
}
ContentType represents a Strapi content type.
type ContentTypeInfo ¶
type ContentTypeInfo struct {
DisplayName string `json:"displayName"`
Description string `json:"description,omitempty"`
Singular string `json:"singularName"`
Plural string `json:"pluralName"`
}
ContentTypeInfo contains information about a content type.
type CreateBlogPostRequest ¶
type CreateBlogPostRequest struct {
Data *BlogPostData `json:"data"`
}
CreateBlogPostRequest represents a request to create a new blog post.
type CreateBlogPostResponse ¶
type CreateBlogPostResponse struct {
Data *BlogPost `json:"data"`
Meta map[string]interface{} `json:"meta,omitempty"`
}
CreateBlogPostResponse represents the response from creating a blog post.
type CreateContentRequest ¶
type CreateContentRequest struct {
Data map[string]interface{} `json:"data"`
}
CreateContentRequest represents a request to create content.
type CreateContentResponse ¶
type CreateContentResponse struct {
Data *ContentEntry `json:"data"`
Meta map[string]interface{} `json:"meta,omitempty"`
}
CreateContentResponse represents the response from creating content.
type DeleteBlogPostResponse ¶
type DeleteBlogPostResponse struct {
Data *BlogPost `json:"data"`
Meta map[string]interface{} `json:"meta,omitempty"`
}
DeleteBlogPostResponse represents the response from deleting a blog post.
type ErrorDetail ¶
type ErrorDetail struct {
Status int `json:"status"`
Name string `json:"name"`
Message string `json:"message"`
Details map[string]interface{} `json:"details,omitempty"`
}
ErrorDetail contains error details.
type ErrorResponse ¶
type ErrorResponse struct {
Error *ErrorDetail `json:"error"`
}
ErrorResponse represents a Strapi API error response.
type GetBlogPostResponse ¶
type GetBlogPostResponse struct {
Data *BlogPost `json:"data"`
Meta map[string]interface{} `json:"meta,omitempty"`
}
GetBlogPostResponse represents the response from getting a single blog post.
type ListBlogPostsResponse ¶
ListBlogPostsResponse represents the response from listing blog posts.
type ListContentResponse ¶
type ListContentResponse struct {
Data []*ContentEntry `json:"data"`
Meta *ListMeta `json:"meta"`
}
ListContentResponse represents the response from listing content entries.
type ListContentTypesResponse ¶
type ListContentTypesResponse struct {
Data []*ContentType `json:"data"`
}
ListContentTypesResponse represents the response from listing content types.
type ListMeta ¶
type ListMeta struct {
Pagination *Pagination `json:"pagination"`
}
ListMeta contains pagination metadata for list responses.
type ListOptions ¶
type ListOptions struct {
Page int `json:"page,omitempty"`
PageSize int `json:"pageSize,omitempty"`
Sort []string `json:"sort,omitempty"`
Filters map[string]interface{} `json:"filters,omitempty"`
Fields []string `json:"fields,omitempty"`
Populate interface{} `json:"populate,omitempty"`
}
ListOptions contains options for listing content.
type Option ¶
type Option func(*Client)
Option is a functional option for configuring the Client.
func WithAPIClient ¶
WithAPIClient sets the underlying HTTP API client.
type Pagination ¶
type Pagination struct {
Page int `json:"page"`
PageSize int `json:"pageSize"`
PageCount int `json:"pageCount"`
Total int `json:"total"`
}
Pagination contains pagination information.
type PublishBlogPostData ¶
PublishBlogPostData contains the data for publishing a blog post.
type PublishBlogPostRequest ¶
type PublishBlogPostRequest struct {
Data *PublishBlogPostData `json:"data"`
}
PublishBlogPostRequest represents a request to publish a blog post.
type PublishBlogPostResponse ¶
type PublishBlogPostResponse struct {
Data *BlogPost `json:"data"`
Meta map[string]interface{} `json:"meta,omitempty"`
}
PublishBlogPostResponse represents the response from publishing a blog post.
type UpdateBlogPostRequest ¶
type UpdateBlogPostRequest struct {
Data *BlogPostData `json:"data"`
}
UpdateBlogPostRequest represents a request to update a blog post.
type UpdateBlogPostResponse ¶
type UpdateBlogPostResponse struct {
Data *BlogPost `json:"data"`
Meta map[string]interface{} `json:"meta,omitempty"`
}
UpdateBlogPostResponse represents the response from updating a blog post.