golangutils

package
v0.0.0-kmdagger2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 12, 2023 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package golangutils holds utility functions, wrappers, and types for building Go binaries for Grafana.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunBuild

func RunBuild(ctx context.Context, opts BuildOpts) error

Build runs the go build process in the current shell given the opts. This function will panic if no Stdout/Stderr/Stdin is provided in the opts.

Types

type BuildOpts

type BuildOpts struct {
	// Package refers to the path to the `main` package containing `func main`
	Package string

	// Output is used as the -o argument in the go build command
	Output string

	// Workdir should define some place in the module where the package path resolves.
	// Go commands need to be ran inside a the Go module directory.
	Workdir string

	GoOS   config.OS
	GoArch config.Architecture
	GoArm  string
	Go386  string
	CC     string
	LibC   string

	CGoEnabled bool
	CGoCFlags  string

	// LdFlags are joined by a space character and provided to the -ldflags argument.
	// A valid element here would be `-X 'main.version=1.0.0'`.
	LdFlags []string

	Stdout io.ReadWriter
	Stderr io.ReadWriter
	Stdin  io.ReadWriter

	// ExtraEnv allows consumers to provide extra env args that are not defined above.
	// A single element should be formatted using like so: {NAME}={VALUE}. Example: GOOS=linux.
	ExtraEnv []string

	// ExtraArgs allows consumers to provide extra arguments that are not defined above.
	// Flag names and values should be two separate elements.
	// These flags will be appended to the command arguments before the package path in "go build".
	ExtraArgs []string
}

func (BuildOpts) Args

func (opts BuildOpts) Args() []string

Args constructs a list of flags and values for use with the exec.Command type when running "go build".

func (BuildOpts) Env

func (opts BuildOpts) Env() []string

Env constructs a list of key/value pairs for setting a build command's environment. Should we consider using something to unmarshal the struct to env?

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL