Skip to content

Commit

Permalink
Add golang Apply func
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Koch <[email protected]>
  • Loading branch information
hugelgupf committed Feb 12, 2024
1 parent 8c409c9 commit c7dd668
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/pkg/golang/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func WithGO111MODULE(go111module string) Opt {

// Default is the default build environment comprised of the default GOPATH,
// GOROOT, GOOS, GOARCH, and CGO_ENABLED values.
func Default(opt ...Opt) *Environ {
func Default(opts ...Opt) *Environ {
env := &Environ{
Context: build.Default,
GO111MODULE: os.Getenv("GO111MODULE"),
Expand All @@ -126,12 +126,19 @@ func Default(opt ...Opt) *Environ {
if env.GO111MODULE != "off" {
env.Mod = ModReadonly
}
for _, o := range opt {
o(env)
}
env.Apply(opts...)
return env
}

// Apply applies additional opts to the environment.
func (c *Environ) Apply(opts ...Opt) {
for _, opt := range opts {
if opt != nil {
opt(c)
}
}
}

// Lookup looks up packages by patterns relative to dir, using the Go environment from c.
func (c *Environ) Lookup(mode packages.LoadMode, dir string, patterns ...string) ([]*packages.Package, error) {
cfg := &packages.Config{
Expand Down

0 comments on commit c7dd668

Please sign in to comment.