Documentation
¶
Overview ¶
Package generator exposes a bunch of functions to be wrapped with engine.Generator function signature.
Index ¶
- Constants
- Variables
- func FetchCodeOfConduct(ctx context.Context, httpClient *http.Client) ([]byte, error)
- func FetchContainerImage(ctx context.Context, httpClient *http.Client, repository, tag string) (string, error)
- func FetchGitignore(ctx context.Context, httpClient *http.Client, templates ...string) ([]byte, error)
Constants ¶
const ( // CodeOfConductURL is the Contributor Covenant 3.0 markdown source URL. CodeOfConductURL = "https://www.contributor-covenant.org/version/3/0/code_of_conduct/code_of_conduct.md" // FileCodeOfConduct is the filename representation for CODE_OF_CONDUCT.md. FileCodeOfConduct = "CODE_OF_CONDUCT.md" )
const ( // FileGitignore is the filename representation for .gitignore. FileGitignore = ".gitignore" // GitignoreBaseURL is the Toptal base URL to retrieve .gitignore templates. GitignoreBaseURL = "https://www.toptal.com/developers/gitignore/api" )
Variables ¶
var ( // ErrInvalidResponse is returned when an HTTP request response status isn't 2XX or its body exceeds 1 MiB. // // When the status isn't 2XX, the response body (quoted and truncated to 512 bytes) is included in the error message. ErrInvalidResponse = errors.New("invalid response from api") // ErrNoClient is returned when input HTTP client is nil. ErrNoClient = errors.New("no client provided") )
var ErrNoTemplates = errors.New("no templates provided")
ErrNoTemplates is returned when templates slice input in FetchGitignore function is empty.
Functions ¶
func FetchCodeOfConduct ¶
FetchCodeOfConduct fetches the Contributor Covenant 3.0 code of conduct markdown and returns the obtained result without writing it anywhere.
type config struct { ... }
func GeneratorCodeOfConduct(ctx context.Context, destdir string, c config) error {
content, err := generator.FetchCodeOfConduct(ctx, cleanhttp.DefaultClient())
// handle err
...
}
Note: the returned content still contains the upstream placeholders (e.g. the reporting method note), callers are expected to patch it before writing it out.
func FetchContainerImage ¶
func FetchContainerImage(ctx context.Context, httpClient *http.Client, repository, tag string) (string, error)
FetchContainerImage resolves the digest of the given repository and tag from its registry and returns the image reference pinned by that digest (e.g. "docker.io/library/golang:1.25.3-trixie@sha256:...").
The repository must include its registry host (e.g. "docker.io/library/golang").
It can be used as a simple function, calling it directly, but its expected usage is with engine.Generate:
type config struct { ... }
func GeneratorDockerfile(ctx context.Context, destdir string, c config) error {
image, err := generator.FetchContainerImage(ctx, cleanhttp.DefaultClient(), "docker.io/library/golang", "1.25.3-trixie")
// handle err
...
}
Note: registry credentials are read from Docker configuration ($DOCKER_CONFIG or ~/.docker/config.json, with its credential helpers), anonymous access is used when none matches the registry.
func FetchGitignore ¶
func FetchGitignore(ctx context.Context, httpClient *http.Client, templates ...string) ([]byte, error)
FetchGitignore fetches a combined .gitignore using the Gitignore API and returns the obtained result without writing it anywhere.
type config struct { ... }
func GeneratorGitignore(ctx context.Context, destdir string, c config) error {
content, err := generator.FetchGitignore(ctx, cleanhttp.DefaultClient(), "java", "linux")
// handle err
...
}
Note: the full list of templates is available on Gitignore listing.
Types ¶
This section is empty.