Source file src/go/build/constraint/example_test.go

     1  // Copyright 2026 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package constraint_test
     6  
     7  import (
     8  	"fmt"
     9  	"log"
    10  
    11  	"go/build/constraint"
    12  )
    13  
    14  func ExampleParse() {
    15  	expr, err := constraint.Parse("//go:build linux && (amd64 || arm64)")
    16  	if err != nil {
    17  		log.Fatal(err)
    18  	}
    19  
    20  	tagSets := []map[string]bool{
    21  		{"linux": true, "arm64": true},
    22  		{"linux": true, "amd64": true},
    23  		{"linux": true},
    24  		{"arm64": true},
    25  	}
    26  
    27  	fmt.Println(expr)
    28  	for _, tags := range tagSets {
    29  		fmt.Println(expr.Eval(func(tag string) bool {
    30  			return tags[tag]
    31  		}))
    32  	}
    33  
    34  	// Output:
    35  	// linux && (amd64 || arm64)
    36  	// true
    37  	// true
    38  	// false
    39  	// false
    40  }
    41  

View as plain text