From 6ae1c16ec74dfef44dad2b49fc19bef4ee945ec4 Mon Sep 17 00:00:00 2001 From: demo Date: Fri, 8 May 2026 10:37:02 -0400 Subject: feat: implement localclient logic I've also added the local html files I'll be working with. --- cmd/localclient/main.go | 31 +++++++++++++++++++++++++ html/ex1.html | 6 +++++ html/ex2.html | 17 ++++++++++++++ html/ex3.html | 62 +++++++++++++++++++++++++++++++++++++++++++++++++ html/ex4.html | 5 ++++ 5 files changed, 121 insertions(+) create mode 100644 html/ex1.html create mode 100644 html/ex2.html create mode 100644 html/ex3.html create mode 100644 html/ex4.html diff --git a/cmd/localclient/main.go b/cmd/localclient/main.go index 21d405d..e65e49f 100644 --- a/cmd/localclient/main.go +++ b/cmd/localclient/main.go @@ -2,13 +2,44 @@ package main import ( "flag" + "fmt" "log" + "os" + "strings" + + "git.brandonirizarry.xyz/links/internal/findlinks" ) func main() { + // Set up logging. + log.SetFlags(log.LstdFlags | log.Lshortfile) + + // Retrieve the CLI flags, and check them. filename := flag.String("file", "", "Local HTML file") + flag.Parse() + if *filename == "" { log.Fatal("Missing -file argument") } + // FIXME: .htm is possible as well, but I'm skipping that for + // now. Also, we could look into templates and that sort of + // thing at some point. + if !strings.HasSuffix(*filename, ".html") { + log.Fatal("Need HTML file (.html)") + } + + // Open the local file. + f, err := os.Open(*filename) + if err != nil { + log.Fatalf("can't open %s: %v", *filename, err) + } + defer f.Close() + + links, err := findlinks.FindLinks(f) + if err != nil { + log.Fatal(err) + } + + fmt.Println(links) } diff --git a/html/ex1.html b/html/ex1.html new file mode 100644 index 0000000..833f110 --- /dev/null +++ b/html/ex1.html @@ -0,0 +1,6 @@ + + +

Hello!

+ A link to another page + + diff --git a/html/ex2.html b/html/ex2.html new file mode 100644 index 0000000..3d22f94 --- /dev/null +++ b/html/ex2.html @@ -0,0 +1,17 @@ + + + + + +

Social stuffs

+
+ + Check me out on twitter + + + + Gophercises is on Github! + +
+ + diff --git a/html/ex3.html b/html/ex3.html new file mode 100644 index 0000000..1e718e2 --- /dev/null +++ b/html/ex3.html @@ -0,0 +1,62 @@ + + + + + + + + + + + Gophercises - Coding exercises for budding gophers + + + +
+
+ +
+ +

coding exercises for budding gophers

+
+
+
+ + + Lost? Need help? +
+
+

Gophercises is 100% FREE, but is currently in beta. There will be bugs, and things will be changing significantly over the coming weeks.

+
+
+
+ + + diff --git a/html/ex4.html b/html/ex4.html new file mode 100644 index 0000000..0e893b8 --- /dev/null +++ b/html/ex4.html @@ -0,0 +1,5 @@ + + + dog cat + + -- cgit v1.2.3