what does //go:build xxx and // +build xxx means in golang?

Issue

I always see the code,

//go:build linux
// +build linux

what mean? I don’t understand.

just give me some examples

Solution

These are build constraints, see https://pkg.go.dev/go/build#hdr-Build_Constraints

In older versions of Go, you would say

// +build linux

where the new syntax from Go 1.17 and up is

//go:build linux

but they do the same thing: only include this file in the Linux build.

Answered By – gonutz

Answer Checked By – Marie Seifert (GoLangFix Admin)

Leave a Reply

Your email address will not be published.