Skip to content

Repository files navigation

Package Description

Test Lint Go Report Card License: MIT Release

Package go-copyright-checker provides a set of utilities and a CLI tool for checking and ensuring copyright headers in Go source files. It is designed to be easily integrated into CI/CD pipelines or used as a standalone developer tool.

This package was originally developed as an internal project at Altessa Solutions Inc. and is now open-sourced under the MIT License.

AI tools were used during the open-source transition for: creating GitHub workflows and configuration files, updating and consolidating documentation, generating usage examples, and reviewing code for consistency.

API Reference

Core

Component Description
checker.Check Main entry point for checking files. Returns an iterator of files needing changes or errors.
checker.Config Configuration structure for custom templates, exclusions, and fix mode.

Installation

Using Go

go install github.com/altessa-s/go-copyright-checker@latest

From Source

git clone https://github.com/altessa-s/go-copyright-checker.git
cd go-copyright-checker
make build

Usage

CLI Tool

Check Copyrights

To check all Go files in the current directory (recursively):

go-copyright-checker check .

If any files are missing headers or have incorrect headers, the command will exit with a non-zero status and list the files.

Fix Copyrights

To automatically fix missing or incorrect headers:

go-copyright-checker check . --fix

Configuration

You can configure the tool using a .copyright.yaml file or command-line flags.

Configuration File (.copyright.yaml)

template: |
  Copyright 2021-{{.YEAR}} Altessa Solutions Inc. All rights reserved.
  Use of this source code is governed by license that can be found in 
  the LICENSE file.
variables:
  YEAR: 2026

Variables

  • {{.YEAR}}: Defaults to the current year. You can override it in the config file.

Command Line Flags

  • -c, --config: Path to configuration file (default: .copyright.yaml).
  • -e, --exclude: Comma-separated list of directories to exclude.
  • -f, --fix: Fix missing or incorrect headers.

Library Usage

You can also use the checker package in your own Go tools:

package main

import (
	"fmt"
	"github.com/altessa-s/go-copyright-checker/pkg/checker"
)

func main() {
	cfg := checker.Config{
		Dir:      ".",
		Template: "Copyright {{.YEAR}} My Corp",
		Data:     map[string]string{"YEAR": "2026"},
	}

	for file, err := range checker.Check(cfg) {
		if err != nil {
			panic(err)
		}
		fmt.Printf("Missing copyright: %s\n", file)
	}
}

About

Package go-copyright-checker provides a set of utilities and a CLI tool for checking and ensuring copyright headers in Go source files.

Topics

Resources

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages