importer

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package importer plans and applies the import of 1 parsed Netscape bookmark file, over the app's API: it reads the target's folders and bookmarks with ListFolders and ListBookmarks, and, unless it is a dry run, it writes with CreateFolder and CreateBookmark.

The contract is the section "The import" of docs/specs/cli.md. The importer checks the folder rules of the API before it writes (see checkFolder), so that a refused folder is a refusal of the plan, and no folder is made for it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Added

type Added struct {
	// ID is the bookmark's id; it is empty in a dry run.
	ID string `json:"id,omitempty"`
	// Folder is the canonical folder of the bookmark.
	Folder string `json:"folder"`
	// URL is the normalized URL.
	URL string `json:"url"`
	// Title is the bookmark's title.
	Title string `json:"title"`
}

Added is 1 bookmark that the import adds.

type Refusal

type Refusal struct {
	// Folder is the folder of the bookmark, or the refused folder itself.
	Folder string `json:"folder"`
	// URL is the URL of the bookmark as the file gives it; it is empty for a
	// refused folder.
	URL string `json:"url"`
	// Title is the bookmark's title; it is empty for a refused folder.
	Title string `json:"title"`
	// Reason is the text of the rule that refuses it.
	Reason string `json:"reason"`
}

Refusal is 1 folder or bookmark that the import refuses.

type Result

type Result struct {
	// DryRun is true for a plan that wrote nothing.
	DryRun bool `json:"dryRun"`
	// Folder is the canonical target folder.
	Folder string `json:"folder"`
	// FoldersMade is the count of Folders.
	FoldersMade int `json:"foldersMade"`
	// BookmarksAdded is the count of Added.
	BookmarksAdded int `json:"bookmarksAdded"`
	// SkippedDuplicates is the count of Skipped.
	SkippedDuplicates int `json:"skippedDuplicates"`
	// Refused is the count of Refusals.
	Refused int `json:"refused"`
	// Folders are the folders that the import makes, parents first.
	Folders []string `json:"folders"`
	// Added are the bookmarks that the import adds, in the order of the file.
	Added []Added `json:"added"`
	// Skipped are the duplicates, in the order of the file.
	Skipped []Skipped `json:"skipped"`
	// Refusals are the refused folders and bookmarks: the folders, then the
	// refusals of the parser, then the bookmarks that the rules or the daemon
	// refuse.
	Refusals []Refusal `json:"refusals"`
}

Result is the plan of 1 import, and, without a dry run, what the import did. It marshals to the JSON form of docs/specs/cli.md.

func Run

func Run(ctx context.Context, client marksv1connect.MarksClient, doc *netscape.Document, target string, dryRun bool) (*Result, error)

Run plans the import of 1 document below a target folder, and, without dryRun, applies the plan.

An invalid target is an error, and so is any error of a call besides the answers that the plan expects: not_found of ListFolders, already_exists of CreateFolder, and already_exists and invalid_argument of CreateBookmark. What the import wrote before an error stays, and the next import skips it.

type Skipped

type Skipped struct {
	// Folder is the canonical folder of the bookmark.
	Folder string `json:"folder"`
	// URL is the normalized URL.
	URL string `json:"url"`
	// Title is the bookmark's title.
	Title string `json:"title"`
}

Skipped is 1 bookmark that the import skips as a duplicate.

Jump to

Keyboard shortcuts

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