linkding

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2024 License: MIT Imports: 9 Imported by: 0

README

go-linkding

Go client library for the Linkding API.

Installation

go get -u github.com/piero-vic/go-linkding

Getting Started

List Bookmarks
package main

import (
	"fmt"

	"github.com/piero-vic/go-linkding"
)

func main() {
	client := linkding.NewClient("https://linkding.example.org", "secret-token")

	params := linkding.ListBookmarksParams{
		Limit: 15,
	}

	response, err := client.ListBookmarks(params)
	if err != nil {
		fmt.Println(err.Error())
		return
	}

	fmt.Println(response.Results)
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInternalServerError = errors.New("linkding: internal server error")
	ErrUnauthorized        = errors.New("linkding: unauthorized")
	ErrNotFound            = errors.New("linkding: not found")
	ErrBadRequest          = errors.New("linkding: bad request")
)

Functions

This section is empty.

Types

type Bookmark

type Bookmark struct {
	ID                    int       `json:"id"`
	URL                   string    `json:"url"`
	Title                 string    `json:"title"`
	Description           string    `json:"description"`
	Notes                 string    `json:"notes"`
	WebsiteTitle          string    `json:"website_title"`
	WebsiteDescription    string    `json:"website_description"`
	WebArchiveSnapshotURL string    `json:"web_archive_snapshot_url"`
	FaviconURL            string    `json:"favicon_url"`
	PreviewImageURL       string    `json:"preview_image_url"`
	IsArchived            bool      `json:"is_archived"`
	Unread                bool      `json:"unread"`
	Shared                bool      `json:"shared"`
	TagNames              []string  `json:"tag_names"`
	DateAdded             time.Time `json:"date_added"`
	DateModified          time.Time `json:"date_modified"`
}

Bookmark represents a bookmark object in the Linkding API.

type Client

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

Client handles all interactions with the Linkding API.

func NewClient

func NewClient(baseURL, token string) *Client

NewClient creates a new Linkding API client using the given URL and token.

The URL provided must be a complete URL. It must contain a schema and the domain for the API. Do not include the prefix path of the API. e.g. "https://linkding.example.org".

func (*Client) ArchiveBookmark

func (c *Client) ArchiveBookmark(id int) error

ArchiveBookmark archives a bookmark from Linkding.

func (*Client) CreateBookmark

func (c *Client) CreateBookmark(payload CreateBookmarkRequest) (*Bookmark, error)

CreateBookmark creates a new bookmark in Linkding using the provided payload.

Warning: Ensure that the TagNames property in the CreateBookmarkRequest is initialized (even if empty) to avoid nil pointer issues.

func (*Client) CreateTag

func (c *Client) CreateTag(name string) (*Tag, error)

CreateTag creates a new tag in Linkding with the provided name.

func (*Client) DeleteBookmark

func (c *Client) DeleteBookmark(id int) error

DeleteBookmark deletes a bookmark from Linkding.

func (*Client) GetBookmark

func (c *Client) GetBookmark(id int) (*Bookmark, error)

GetBookmark retrieves a single bookmark from Linkding.

func (*Client) GetTag

func (c *Client) GetTag(id int) (*Tag, error)

GetTag retrieves a single tag from Linkding.

func (*Client) GetUserPreferences

func (c *Client) GetUserPreferences() (*UserPreferences, error)

GetUserPreferences retrieves the user's preferences from Linkding.

func (*Client) ListArchivedBookmarks

func (c *Client) ListArchivedBookmarks(params ListBookmarksParams) (*ListBookmarksResponse, error)

ListArchivedBookmarks retrieves a list of archived bookmarks from Linkding. It also filters the list based on the provided parameters.

func (*Client) ListBookmarks

func (c *Client) ListBookmarks(params ListBookmarksParams) (*ListBookmarksResponse, error)

ListBookmarks retrieves a list of bookmarks from Linkding based on the provided parameters.

func (*Client) ListTags

func (c *Client) ListTags(params ListTagsParams) (*ListTagsResponse, error)

ListTags retrieves a list of tags from Linkding based on the provided parameters.

func (*Client) UnarchiveBookmark

func (c *Client) UnarchiveBookmark(id int) error

UnarchiveBookmark unarchives a bookmark from Linkding.

func (*Client) UpdateBookmark

func (c *Client) UpdateBookmark(id int, payload CreateBookmarkRequest) (*Bookmark, error)

UpdateBookmark updates an existing bookmark in Linkding using the provided payload.

Warning: Ensure that the TagNames property in the CreateBookmarkRequest is initialized (even if empty) to avoid nil pointer issues.

type CreateBookmarkRequest

type CreateBookmarkRequest struct {
	URL         string   `json:"url"`
	Title       string   `json:"title"`
	Description string   `json:"description"`
	Notes       string   `json:"notes"`
	IsArchived  bool     `json:"is_archived"`
	Unread      bool     `json:"unread"`
	Shared      bool     `json:"shared"`
	TagNames    []string `json:"tag_names"`
}

CreateBookmarkRequest represents the request body when creating or updating bookmarks.

type CreateTagRequest

type CreateTagRequest struct {
	Name string `json:"name"`
}

CreateTagRequest represents the request body when creating a new tag.

type ListBookmarksParams

type ListBookmarksParams struct {
	// The search query to filter bookmarks.
	Query string
	// The maximum number of bookmarks to return.
	Limit int
	// The offset for pagination.
	Offset int
	// Filter to include only unread bookmarks.
	Unread bool
}

ListBookmarksParams defines the parameters used when listing bookmarks.

type ListBookmarksResponse

type ListBookmarksResponse struct {
	Count    int        `json:"count"`
	Next     string     `json:"next"`
	Previous string     `json:"previous"`
	Results  []Bookmark `json:"results"`
}

ListBookmarksResponse represents the response from the Linkding API when listing bookmarks.

type ListTagsParams

type ListTagsParams struct {
	// The maximum number of tags to return.
	Limit int
	// The offset for pagination.
	Offset int
}

ListTagsParams defines the parameters used when listing tags.

type ListTagsResponse

type ListTagsResponse struct {
	Count    int    `json:"count"`
	Next     string `json:"next"`
	Previous string `json:"previous"`
	Results  []Tag  `json:"results"`
}

ListTagsResponse represents the response from the Linkding API when listing tags.

type Tag

type Tag struct {
	ID        int       `json:"id"`
	Name      string    `json:"name"`
	DateAdded time.Time `json:"date_added"`
}

Tag represents a tag object in the Linkding API.

type UserPreferences

type UserPreferences struct {
	Theme                 string `json:"theme"`
	BookmarkDateDisplay   string `json:"bookmark_date_display"`
	BookmarkLinkTarget    string `json:"bookmark_link_target"`
	WebArchiveIntegration string `json:"web_archive_integration"`
	TagSearch             string `json:"tag_search"`
	EnableSharing         bool   `json:"enable_sharing"`
	EnablePublicSharing   bool   `json:"enable_public_sharing"`
	EnableFavicons        bool   `json:"enable_favicons"`
	DisplayURL            bool   `json:"display_url"`
	PermanentNotes        bool   `json:"permanent_notes"`
	SearchPreferences     struct {
		Sort   string `json:"sort"`
		Shared string `json:"shared"`
		Unread string `json:"unread"`
	} `json:"search_preferences"`
}

UserPreferences represents the user-specific settings in the Linkding API.

Jump to

Keyboard shortcuts

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