English Finnish
Golang Packaging Guidelines Golang -paketoinnin ohjeet
This document details best practices for packaging Golang packages. Most of it is automated by an extensive use of macros.
https://pagure.io/GoSIG/go2rpm/[go2rpm] is tool that automates many of these steps. It is advisable to try `+go2rpm import_path+` first before attempting to write a SPEC by hand.
Import Path
In Golang, packages are referenced by full URLs. Since this URL is referenced in several places throughout the rpmspec, set the base import path as a global define at the top of the spec file
%global goipath github.com/kr/pretty
All macros, including package name, source URL, will be computed from this value.
*Take the time to identify it accurately.* Changing it later will be
it may differ from the repository URL;
generally, the correct value will be the one used by the project in its documentation, coding examples, and build assertions;
use the gopkg import path for all code states when a project uses it.
If upstream confused itself after multiple forks and renamings, you will need to fix references to past names in the Go source files, unit tests included. Perform this fixing in `+%prep+`.
Source packages (src.rpm)
Golang source packages MUST be named after their main import path. This process is automated by the `+%{goname}+` macro. This macro will remove any capitalization, "go" keywords, and any duplication in the import path.
For example:
the import path `+github.com/kr/pretty+` will become `+golang-github-kr-pretty+`
the import path `+github.com/DATA-DOG/go-txdb+` will become `+golang-github-data-dog-txdb+`
the import path `+github.com/gopherjs/gopherjs+` will become `+golang-github-gopherjs+`
The filename of spec MUST match the name of the package.