diff options
| author | Shulhan <ms@kilabit.info> | 2025-06-05 00:39:02 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2025-06-05 00:39:02 +0700 |
| commit | 7798a353509448e5d706274115f3dd79835e9af5 (patch) | |
| tree | 09fc19d2197e384340b3c88b12dff80625398110 | |
| parent | c044c4edd47c260ae6137b7116c0891cd8b979d1 (diff) | |
| download | jarink-7798a353509448e5d706274115f3dd79835e9af5.tar.xz | |
all: encode the whole BrokenlinksResult struct to JSON
Previously, we only encode the BrokenlinksResult.PageLinks.
The struct may changes in the future, so its better to encode the whole
struct now rather than changing the output later.
| -rw-r--r-- | brokenlinks.go | 2 | ||||
| -rw-r--r-- | brokenlinks_worker.go | 2 | ||||
| -rw-r--r-- | cmd/jarink/main.go | 2 | ||||
| -rw-r--r-- | testdata/past_result.json | 14 |
4 files changed, 11 insertions, 9 deletions
diff --git a/brokenlinks.go b/brokenlinks.go index 833e2d2..4be4fe8 100644 --- a/brokenlinks.go +++ b/brokenlinks.go @@ -33,7 +33,7 @@ type BrokenlinksOptions struct { // BrokenlinksResult store the result of scanning for broken links. type BrokenlinksResult struct { // PageLinks store the page and its broken links. - PageLinks map[string][]Broken + PageLinks map[string][]Broken `json:"page_links"` } func newBrokenlinksResult() *BrokenlinksResult { diff --git a/brokenlinks_worker.go b/brokenlinks_worker.go index dbb3453..03a89bd 100644 --- a/brokenlinks_worker.go +++ b/brokenlinks_worker.go @@ -82,7 +82,7 @@ func newWorker(opts BrokenlinksOptions) (wrk *brokenlinksWorker, err error) { } wrk.pastResult = newBrokenlinksResult() - err = json.Unmarshal(pastresult, &wrk.pastResult.PageLinks) + err = json.Unmarshal(pastresult, &wrk.pastResult) if err != nil { return nil, err } diff --git a/cmd/jarink/main.go b/cmd/jarink/main.go index c8ba2e2..cba254f 100644 --- a/cmd/jarink/main.go +++ b/cmd/jarink/main.go @@ -45,7 +45,7 @@ func main() { } var resultJson []byte - resultJson, err = json.MarshalIndent(result.PageLinks, ``, ` `) + resultJson, err = json.MarshalIndent(result, ``, ` `) if err != nil { log.Fatal(err.Error()) } diff --git a/testdata/past_result.json b/testdata/past_result.json index 3ba37c1..a5a11fe 100644 --- a/testdata/past_result.json +++ b/testdata/past_result.json @@ -1,8 +1,10 @@ { - "http://127.0.0.1:11836/page2": [ - { - "link": "http://127.0.0.1:11836/", - "code": 404 - } - ] + "page_links": { + "http://127.0.0.1:11836/page2": [ + { + "link": "http://127.0.0.1:11836/", + "code": 404 + } + ] + } } |
