# AddGoApp

- Module: [Aspire.Hosting.Go](/reference/api/go/aspire.hosting.go.md)
- Version: `17.0.0`
- Kind: `method`
- Defined on: `DistributedApplicationBuilder`
- Source: [GitHub](https://github.com/microsoft/aspire/tree/2d325b13709752ba6d9a943635c5e2940a2530c0)

Adds a Go application to the application model. The Go toolchain must be available on the PATH.

## Remarks

This method executes the Go application using `go run .`. The Go toolchain resolves the
entry point from the package in `appDirectory`.
Go applications automatically have VS Code debugging support enabled via Delve.
Use `WithModTidy`, `WithModVendor`, or `WithModDownload`
to manage module dependencies before startup, and `WithVetTool` to run static analysis.
Use `WithAppArgs` to pass runtime program arguments, and
`WithDelveServer` to enable remote debugging via a headless Delve server.

## Definition

```go
func (DistributedApplicationBuilder) AddGoApp(
    name string,
    appDirectory string,
    options ...*AddGoAppOptions,
) GoAppResource
```

## Parameters

- `name` (`string`) -- The name of the resource.
- `appDirectory` (`string`) -- The path to the directory that acts as both the Go module root (where `go.mod` lives) and the Docker build context for `aspire publish`.
- `options` (`...*AddGoAppOptions`) -- optional settings, see [Options](#options)

## Options

Optional parameters are passed in a trailing `options ...*AddGoAppOptions` argument.

- `PackagePath` (`*string`) -- The Go package to run or build, relative to `appDirectory`. Defaults to `"."` (the module root itself). Use a sub-path such as `"./cmd/server"` when the main package is not at the module root (e.g. `api/cmd/server/main.go` with `api/go.mod`). This value is passed to `go run`, `dlv debug`, and `go build` consistently.
- `BuildTags` (`[]string`) -- Optional build tags passed to the compiler via `-tags` (e.g. `"netgo"`, `"integration"`).
- `LdFlags` (`*string`) -- Optional linker flags passed via `-ldflags` (e.g. `"-X main.version=1.0.0"`).
- `GcFlags` (`*string`) -- Optional compiler flags passed via `-gcflags` (e.g. `"all=-N -l"` to disable optimisations for Delve).
- `RaceDetector` (`*bool`) -- When `true`, enables the Go race detector by passing `-race` to `go run`.

## Returns

[`GoAppResource`](/reference/api/go/aspire.hosting.go/goappresource.md) -- The resource builder.

Returns a handle; failures surface later via `Err()`.

## Applies to

- `DistributedApplicationBuilder`
