# WithGoPrivate

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

Configures private Go module authentication for publish-time Dockerfile generation.

## Remarks

Only affects the generated Dockerfile -- has no effect in run mode, where the local
Go toolchain picks up credentials from the developer's own `~/.netrc` or git
credential helper.
The generated build stage writes a temporary `.netrc` file from the username
build-arg and the token secret, runs `go mod download`, then removes the file -- 
all in a single layer so credentials never persist in the image.

## Definition

```go
func (GoAppResource) WithGoPrivate(
    privatePatterns []string,
    authHost string,
    options ...*WithGoPrivateOptions,
) GoAppResource
```

## Parameters

- `privatePatterns` (`[]string`) -- One or more module path patterns that should bypass the public proxy and checksum database, e.g. `"*.mycompany.com"` or `"github.com/myorg"`. Passed verbatim to `GOPRIVATE`, which implicitly covers `GONOSUMCHECK` and `GONOPROXY`.
- `authHost` (`string`) -- The Git host that requires authentication, e.g. `"github.com"`.
- `options` (`...*WithGoPrivateOptions`) -- optional settings, see [Options](#options)

## Options

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

- `UsernameArgName` (`*string`) -- The Docker build-arg name for the Git username. Defaults to `"GIT_USER"`. Pass it at build time with `--build-arg GIT_USER=myuser`.
- `TokenSecretId` (`*string`) -- The BuildKit secret ID for the Git access token. Defaults to `"gittoken"`. Pass it at build time with `--secret id=gittoken,src=/path/to/token`.

## Returns

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

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

## Applies to

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