Copyright 2021 The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

package internal

import 
A BuildContext describes a build context for the Go tool: information needed to build a Go package. For our purposes, we only care about the information that affects documentation generated from the package.
type BuildContext struct {
	GOOS, GOARCH string
}
String returns a string formatted representation of the build context.
func ( BuildContext) () string {
	return fmt.Sprintf("%s/%s", .GOOS, .GOARCH)
}
Match reports whether its receiver, which acts like a pattern, matches its target, an ordinary BuildContext. In addition to the usual values, a pattern can have an empty GOOS or GOARCH, which means "match anything."
func ( BuildContext) ( BuildContext) bool {
	 := func(,  string) bool { return  == "" ||  == All ||  ==  }

	return (.GOOS, .GOOS) && (.GOARCH, .GOARCH)
}
All represents all values for a build context element (GOOS or GOARCH).
const All = "all"

var (
	BuildContextAll     = BuildContext{All, All}
	BuildContextLinux   = BuildContext{"linux", "amd64"}
	BuildContextWindows = BuildContext{"windows", "amd64"}
	BuildContextDarwin  = BuildContext{"darwin", "amd64"}
	BuildContextJS      = BuildContext{"js", "wasm"}
)
BuildContexts are the build contexts we check when loading a package (see internal/fetch/load.go). We store documentation for all of the listed contexts. The order determines which environment's docs we will show as the default.
CompareBuildContexts returns a negative number, 0, or a positive number depending on the relative positions of c1 and c2 in BuildContexts.
func (,  BuildContext) int {
	if  ==  {
		return 0
Although we really shouldn't see a BuildContext with "all" here, we may if the DB erroneously has both an all/all row and some other row. So just prefer the all/all.
	if  == BuildContextAll {
		if  == BuildContextAll {
			return 0
		}
		return -1
	}
	if  == BuildContextAll {
		return 1
	}
	 := func( BuildContext) int {
		for ,  := range BuildContexts {
			if  ==  {
				return 
			}
		}
		return len(BuildContexts) // unknowns sort last
	}
	return () - ()
}
BuildContext returns the BuildContext for d.
DocumentationForBuildContext returns the first Documentation the list that matches the BuildContext, or nil if none does. A Documentation matches if its GOOS and GOARCH fields are the same as those of the BuildContext, or if the Documentation field is "all", or if the BuildContext field is empty. That is, empty BuildContext fields act as wildcards. So the zero BuildContext will match the first element of docs, if there is one.
func ( []*Documentation,  BuildContext) *Documentation {
	for ,  := range  {
		if .Match(BuildContext{.GOOS, .GOARCH}) {
			return 
		}
	}
	return nil