Help us shape the future of Go! Take the 2026 Go Developer Survey

cloudrun

package
v0.11.49 Latest Latest
Warning

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

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

Documentation

Overview

Package cloudrun resolves the identity of the running Cloud Run resource from its environment variables.

Cloud Run services set K_SERVICE and K_REVISION, while Cloud Run jobs set CLOUD_RUN_JOB and CLOUD_RUN_EXECUTION instead. These helpers prefer the service variables and fall back to the job variables, so a workload reports a stable identity whether it runs as a service or a job.

See https://cloud.google.com/run/docs/container-contract#services-env-vars and https://cloud.google.com/run/docs/container-contract#jobs-env-vars.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsJob

func IsJob() bool

IsJob reports whether the process is running as a Cloud Run job.

Example
package main

import (
	"fmt"

	"chainguard.dev/driftlessaf/internal/cloudrun"
)

func main() {
	if cloudrun.IsJob() {
		fmt.Println("running as a Cloud Run job")
	} else {
		fmt.Println("running as a Cloud Run service")
	}
}

func RevisionName

func RevisionName() string

RevisionName returns the revision/execution identifier of the running Cloud Run resource, preferring K_REVISION (services) and falling back to CLOUD_RUN_EXECUTION (jobs). It returns "" if neither is set.

Example
package main

import (
	"cmp"
	"fmt"

	"chainguard.dev/driftlessaf/internal/cloudrun"
)

func main() {
	revision := cmp.Or(cloudrun.RevisionName(), "unknown")
	fmt.Println(revision)
}

func ServiceName

func ServiceName() string

ServiceName returns the identifier of the running Cloud Run resource, preferring K_SERVICE (services) and falling back to CLOUD_RUN_JOB (jobs). It returns "" if neither is set.

Example
package main

import (
	"cmp"
	"fmt"

	"chainguard.dev/driftlessaf/internal/cloudrun"
)

func main() {
	// Resolve the running resource's identity, defaulting when unset.
	name := cmp.Or(cloudrun.ServiceName(), "unknown")
	fmt.Println(name)
}

Types

This section is empty.

Jump to

Keyboard shortcuts

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