link

package module
v0.0.0-...-74492a2 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2024 License: MIT Imports: 3 Imported by: 0

README

This is my solution for the excercise 4 of Gophercises gophercises/link.

For this exercise I had to create a simple parser that gets the anchor tags from an html document and returns them in a slice of Link instances.

type Link struct {
  Href string
  Text string
}

To achive this I made use of the x/net/html package, and I followed a TDD strategy.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Link struct {
	Href string
	Text string
}

Link represents a link (<a href="...">) in an HTML document.

func Parse

func Parse(r io.Reader) ([]Link, error)

Parse receives an HTML document and returns a slice of Links parsed from it.

Example
s := `<a href="https://go.dev">Hello, Go!</a>`
r := strings.NewReader(s)

links, err := Parse(r)
if err != nil {
	log.Fatal(err)
}
fmt.Printf("%+v", links)
Output:

[{Href:https://go.dev Text:Hello, Go!}]

Jump to

Keyboard shortcuts

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