generator

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package generator exposes a bunch of functions to be wrapped with engine.Generator function signature.

Index

Constants

View Source
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"
)
View Source
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

View Source
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")
)
View Source
var ErrNoTemplates = errors.New("no templates provided")

ErrNoTemplates is returned when templates slice input in FetchGitignore function is empty.

Functions

func FetchCodeOfConduct

func FetchCodeOfConduct(ctx context.Context, httpClient *http.Client) ([]byte, error)

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.

Jump to

Keyboard shortcuts

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