type port … var preferredPorts … // matches reports whether the port matches a file with the given absolute path // and content. // // Note that this function accepts content rather than e.g. a file.Handle, // because we trim content before matching for performance reasons, and // therefore need to do this outside of matches when considering multiple ports. func (p port) matches(path string, content []byte) bool { … } // trimContentForPortMatch trims the given Go file content to a minimal file // containing the same build constraints, if any. // // This is an unfortunate but necessary optimization, as matching build // constraints using go/build has significant overhead, and involves parsing // more than just the build constraint. // // TestMatchingPortsConsistency enforces consistency by comparing results // without trimming content. func trimContentForPortMatch(content []byte) []byte { … } // buildComment returns the first matching //go:build comment in the given // content, or "" if none exists. func buildComment(content []byte) string { … } // Adapted from go/build/build.go. // // TODO(rfindley): use constraint.IsGoBuild once we are on 1.19+. func isGoBuildComment(line string) bool { … }