Copyrighter
Copyrighter
is a utility that leverages Go's code generator to add a copyright notice to source files in the following languages:
- C (.c)
- C++ (.cpp)
- C# (.cs)
- CSS (.css)
- Go (.go)
- HTML (.html)
- Java (.java)
- JavaScript (.js)
- PHP (.php)
- PowerShell (.ps1)
- Python (.py)
- Shell (.sh)
- SQL (.sql)
- TypeScript (.ts)
- XML (.xml)
- YAML (.yaml, *.yml)
Usage
To install, go get github.com/microbus-io/copyrighter
.
Place a copyright.go
file in the root of the source code directory tree, with:
- A comment at the top of the file with the copyright or license notice
- A
go generate
directive
- File matching patterns (optional)
package
and import
statements
/*
Copyright 2023 You
All rights reserved
*/
//go:generate go run github.com/microbus-io/copyrighter
// - *.*
// + *.go
// - /vendors/*
package yourpackage
import _ "github.com/microbus-io/copyrighter/i"
Copyright Notice
The first comment surrounded by /*
and */
(on separate lines with nothing else added to those lines) or one where each line starts with //
will be recognized as the copyright notice.
/*
Copyright 2023 You
All rights reserved
*/
...
// Copyright 2023 You
// All rights reserved
...
The special constant YYYY
may be used as placeholder for the current year.
// Copyright 2023-YYYY You
File Matching Patterns
By default, all recognized source file types are processed.
To customize which files to process, file matching patterns may be added anywhere in the file. Patterns are executed in the order of their appearance in file. The last pattern that matches the file wins.
The following examples excludes all files by default, then re-includes *.go
and *.sql
files, except in the /vendors
directory.
// - *.*
// + *.go
// + *.sql
// - /vendors/*
A -
or +
is used to indicate if this pattern is an exclusion or inclusion pattern.
Patterns that start with a /
are matched to the root directory where copyright.go
is located. Otherwise, they are applied to any subdirectory.
The following pattern can be used to exclude hidden files on Unix:
// - .*
Verbose Flag
The -v
flag may be added to the go:generate
directive to produce verbose output.
//go:generate go run github.com/microbus-io/copyrighter -v
Legal
Copyrighter
is released by Microbus LLC
under the Apache 2.0 license.