parser

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package parser provides functions for extracting and filtering links from various sources.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractLinksFromFile

func ExtractLinksFromFile(filePath string) ([]string, error)

ExtractLinksFromFile reads a file and extracts all links from its content. Supports HTML, JSON, and plain text files. The file size is limited to 10MB for safety. Returns a slice of unique links found in the file or an error if reading or parsing fails.

func ExtractLinksFromURL

func ExtractLinksFromURL(targetURL string, ignoreCert bool) ([]string, error)

ExtractLinksFromURL fetches a URL and extracts all links from its content. Supports HTML, JSON, XML content types. The ignoreCert parameter can be used to skip TLS certificate validation. Returns a slice of unique links found in the content or an error if the fetch or parsing fails.

func FilterLinksByRegex

func FilterLinksByRegex(links []string, regex string) ([]string, error)

FilterLinksByRegex filters a slice of links using a regular expression pattern. Only links that match the pattern are returned. Returns an error if the regex pattern is invalid.

func PrintLinksAsHTML

func PrintLinksAsHTML(links []string)

PrintLinksAsHTML prints the links as an HTML unordered list to stdout. Each link is wrapped in an anchor tag that links to itself.

func PrintLinksAsJSON

func PrintLinksAsJSON(links []string)

PrintLinksAsJSON prints the links as a JSON array to stdout. If JSON marshaling fails, an error message is printed.

func PrintLinksAsNumbered

func PrintLinksAsNumbered(links []string)

PrintLinksAsNumbered prints the links as a numbered list to stdout. Each link is prefixed with its position number in the list.

func PrintLinksAsText

func PrintLinksAsText(links []string)

PrintLinksAsText prints the links as plain text to stdout. Each link is printed on a new line.

Types

This section is empty.

Jump to

Keyboard shortcuts

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