aboutsummaryrefslogtreecommitdiff
path: root/brokenlinks/result.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2025-06-12 21:13:58 +0700
committerShulhan <ms@kilabit.info>2025-06-12 21:13:58 +0700
commita02e915388723a5d8cc3b555fb3dfec477fc2a55 (patch)
treeaa35678b263646e1edd730a16cb35a66e7b933d8 /brokenlinks/result.go
parentf408c77795a9dd6d4551fadd2e8352ba08915feb (diff)
downloadjarink-a02e915388723a5d8cc3b555fb3dfec477fc2a55.tar.xz
all: refactoring, move brokenlinks code to its own package
When two or more struct has the same prefix that means it is time to move it to group it. Also, we will group one command to one package in the future.
Diffstat (limited to 'brokenlinks/result.go')
-rw-r--r--brokenlinks/result.go37
1 files changed, 37 insertions, 0 deletions
diff --git a/brokenlinks/result.go b/brokenlinks/result.go
new file mode 100644
index 0000000..676859b
--- /dev/null
+++ b/brokenlinks/result.go
@@ -0,0 +1,37 @@
+// SPDX-FileCopyrightText: 2025 M. Shulhan <ms@kilabit.info>
+// SPDX-License-Identifier: GPL-3.0-only
+
+package brokenlinks
+
+import (
+ "slices"
+ "strings"
+)
+
+// Broken store the broken link, HTTP status code, and the error message that
+// cause it.
+type Broken struct {
+ Link string `json:"link"`
+ Error string `json:"error,omitempty"`
+ Code int `json:"code"`
+}
+
+// Result store the result of scanning for broken links.
+type Result struct {
+ // BrokenLinks store the page and its broken links.
+ BrokenLinks map[string][]Broken `json:"broken_links"`
+}
+
+func newResult() *Result {
+ return &Result{
+ BrokenLinks: map[string][]Broken{},
+ }
+}
+
+func (result *Result) sort() {
+ for _, listBroken := range result.BrokenLinks {
+ slices.SortFunc(listBroken, func(a, b Broken) int {
+ return strings.Compare(a.Link, b.Link)
+ })
+ }
+}