github.com/golangci/go-tools@v0.0.0-20190318060251-af6baa5dc196/staticcheck/buildtag.go (about)

     1  package staticcheck
     2  
     3  import (
     4  	"go/ast"
     5  	"strings"
     6  
     7  	. "github.com/golangci/go-tools/lint/lintdsl"
     8  )
     9  
    10  func buildTags(f *ast.File) [][]string {
    11  	var out [][]string
    12  	for _, line := range strings.Split(Preamble(f), "\n") {
    13  		if !strings.HasPrefix(line, "+build ") {
    14  			continue
    15  		}
    16  		line = strings.TrimSpace(strings.TrimPrefix(line, "+build "))
    17  		fields := strings.Fields(line)
    18  		out = append(out, fields)
    19  	}
    20  	return out
    21  }