checklinks

command
v0.34.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: GPL-3.0 Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

checklinks is a small Go program that validates every link found in the resticprofile source tree that starts with the documentation base URL.

What it does

  1. Discovery – walks all files under the current directory (skipping directories containing binaries) and extracts every URL that begins with the configured source base URL using a regular expression.
  2. Deduplication – each unique URL is checked only once, and a small built-in exclusion list (e.g. JSON-schema endpoints) is skipped.
  3. Checking – each URL is fetched with an HTTP GET request. A response with a 2xx or 3xx status code is considered successful.
  4. Fragment validation – when a URL contains a fragment (#anchor), the response body is scanned for id="anchor" so that broken anchors are caught as well.

Modes of operation

Local mode (default)

When no -target flag is provided, the tool starts an in-process TLS server that serves the compiled HTML documentation from a local directory. All discovered links are rewritten to point at that local server so no network access is required.

checklinks -dir ./public
Remote mode

When a -target URL is supplied, all requests are redirected from the source host to the target host at the TCP dial level. This is useful for smoke-testing a staging deployment without modifying source files.

checklinks -source https://creativeprojects.github.io/resticprofile \
           -target  https://staging.example.com

Usage

checklinks [-v] [-source <url>] [-target <url>] [-dir <path>]
Flag Default Description
-v false Print each link as it is discovered (verbose).
-source https://creativeprojects.github.io/resticprofile Base URL whose occurrences are searched for in files.
-target (empty) Alternative base URL to send requests to. When omitted, a local server is started and -dir is required.
-dir (empty) Directory containing the compiled HTML documentation. Required when -target is not given.

Exit codes

Code Meaning
0 All links are valid.
1 One or more links could not be verified, or the tool encountered a fatal configuration error.

Building

go build ./checklinks

Or run directly without building:

go run ./checklinks -dir ./public

Documentation

Overview

checklinks is a link-checking tool for the resticprofile documentation.

It scans all files in the current directory tree (skipping common non-doc directories) for URLs that begin with the configured source base URL, then verifies that every discovered URL returns a successful HTTP response.

When checking links, the tool can operate in two modes:

  1. Local mode (default): starts an in-process HTTPS server that serves the compiled documentation from a local directory, then checks all links against that server. Use -dir to point at the directory.

  2. Remote mode: redirects all requests to an alternative base URL supplied via -target. Useful for smoke-testing a staging deployment without rewriting every link in the source files.

In addition to checking HTTP status codes, the tool validates URL fragments (e.g. /page#section) by searching the response body for the corresponding id="…" attribute, so broken anchors are caught as well.

Usage:

checklinks [-v] [-source <url>] [-target <url>] [-dir <path>]

Flags:

-v          Print each link as it is discovered (verbose output).
-source     Base URL whose occurrences are searched for in files.
            Defaults to https://creativeprojects.github.io/resticprofile.
-target     Alternative base URL to send requests to.  When omitted, a
            local server is started and -dir must be provided.
-dir        Directory containing the compiled HTML documentation.
            Required when -target is not specified.

Jump to

Keyboard shortcuts

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