github.com/go-asm/go@v1.21.1-0.20240213172139-40c5ead50c48/cmd/go/cfg/lookpath.go (about) 1 // Copyright 2023 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 cfg 6 7 import ( 8 "os/exec" 9 10 "github.com/go-asm/go/cmd/go/par" 11 ) 12 13 var lookPathCache par.ErrCache[string, string] 14 15 // LookPath wraps exec.LookPath and caches the result 16 // which can be called by multiple Goroutines at the same time. 17 func LookPath(file string) (path string, err error) { 18 return lookPathCache.Do(file, 19 func() (string, error) { 20 return exec.LookPath(file) 21 }) 22 }