go install go.bug.st/licenser@latest
Create a doc.go or a main.go with the header you want, for example:
//
// Copyright 2022-2026 Cristian Maglie. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//
package main
// Other docs here...Run:
$ licenser .
Golang project detected
Extracting license from doc.go
IGNORED: LICENSE
IGNORED: README.md
OK doc.go
IGNORED: go.mod
IGNORED: go.sum
OK main.goThe tool will automatically copy the license found in doc.go (or in main.go if doc.go does not exist) to all your other golang source files. If the license is changed on those "master" files, the license on the other files will be updated as well.
WARNING: Always use this tool in a source tree that has a version control system, such as Git, in place.
This tool updates files in-place, which means that the old content will be overwritten without confirmation. Therefore, it is advisable to have a backup in case of failures.