### Installation via go get Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/mattn/go-colorable/README.md Installs the package using the Go toolchain. ```bash $ go get github.com/mattn/go-colorable ``` -------------------------------- ### Installation with go get Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/monochromegane/go-gitignore/README.md Installs the go-gitignore package using the go get command. ```sh $ go get github.com/monochromegane/go-gitignore ``` -------------------------------- ### Install pflag with go get Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/spf13/pflag/README.md Install pflag using the standard go get command. ```bash go get github.com/spf13/pflag ``` -------------------------------- ### Install cat with go get Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/olekukonko/cat/README.md Command to install the cat library using go get. ```bash go get github.com/your-repo/cat ``` -------------------------------- ### Run local Go Doc site Source: https://github.com/agent-substrate/substrate/blob/main/vendor/go.opentelemetry.io/otel/CONTRIBUTING.md Commands to install and start a local documentation server. ```sh go install golang.org/x/pkgsite/cmd/pkgsite@latest pkgsite ``` -------------------------------- ### Install and test go-ole Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/go-ole/go-ole/README.md Commands to fetch the library, run tests, and execute the Excel example. ```shell go get github.com/go-ole/go-ole cd /path/to/go-ole/ go test cd /path/to/go-ole/example/excel go run excel.go ``` -------------------------------- ### Install multierr with go get Source: https://github.com/agent-substrate/substrate/blob/main/vendor/go.uber.org/multierr/README.md Install the multierr library using the go get command. This fetches the latest version from go.uber.org/multierr. ```bash go get -u go.uber.org/multierr@latest ``` -------------------------------- ### Install Theine with go get Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/Yiling-J/theine-go/README.md Install the Theine library using the standard Go package manager command. ```bash go get github.com/Yiling-J/theine-go ``` -------------------------------- ### Setup environment file for configuration Source: https://github.com/agent-substrate/substrate/blob/main/tools/setup-gcp/README.md Copy the example environment file, customize it, and source it to set default values for CLI flags. Command-line flags take precedence over these environment variables. ```bash cp hack/ate-dev-env.sh.example .ate-dev-env.sh # Edit .ate-dev-env.sh to match your project and preferences source .ate-dev-env.sh ``` -------------------------------- ### Install uniseg with go get Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/rivo/uniseg/README.md Install the package using the standard Go tool. Run this command in your terminal. ```bash go get github.com/rivo/uniseg ``` -------------------------------- ### Install locafero with go get Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/sagikazarmark/locafero/README.md Install the locafero library using the Go module system. ```shell go get github.com/sagikazarmark/locafero ``` -------------------------------- ### Install Afero Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/spf13/afero/README.md Use the go get command to add the Afero package to your project. ```bash go get github.com/spf13/afero ``` -------------------------------- ### Go get install Cobra Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/spf13/cobra/README.md Install the latest Cobra library using go get. ```bash go get -u github.com/spf13/cobra@latest ``` -------------------------------- ### Install jsoniter with go get Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/json-iterator/go/README.md Installs the jsoniter library using the go get command. ```shell go get github.com/json-iterator/go ``` -------------------------------- ### Install with go get Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/go-openapi/jsonpointer/README.md Command to add the go-openapi/jsonpointer library to a Go project. ```cmd go get github.com/go-openapi/jsonpointer ``` -------------------------------- ### Install the metadata library with go get Source: https://github.com/agent-substrate/substrate/blob/main/vendor/cloud.google.com/go/compute/metadata/README.md Use this command to install the cloud.google.com/go/compute/metadata package. Run it in your terminal to add the dependency to your Go module. ```bash go get cloud.google.com/go/compute/metadata ``` -------------------------------- ### Install go.yaml.in/yaml/v2 with go get Source: https://github.com/agent-substrate/substrate/blob/main/vendor/go.yaml.in/yaml/v2/README.md Install the yaml package for Go using the go get command. The import path is go.yaml.in/yaml/v2. ```shell go get go.yaml.in/yaml/v2 ``` -------------------------------- ### Install yaml.v3 with go get Source: https://github.com/agent-substrate/substrate/blob/main/vendor/gopkg.in/yaml.v3/README.md Install the yaml package using the go get command. The import path is gopkg.in/yaml.v3. ```shell go get gopkg.in/yaml.v3 ``` -------------------------------- ### Run setup wizard Source: https://github.com/agent-substrate/substrate/blob/main/benchmarking/automation/README.md Run the setup wizard to build and push the orchestrator image and render scratch/cronjob.yaml, scratch/test-list.yaml, and scratch/target-clusters.yaml. It snapshots the repo's .ate-dev-env.sh to scratch/target-clusters/.sh and prompts only for the target cluster name and GCP project ID of the orchestrator image registry. ```bash ./benchmarking/automation/setup.sh ``` -------------------------------- ### Install sigs.k8s.io/yaml Source: https://github.com/agent-substrate/substrate/blob/main/vendor/sigs.k8s.io/yaml/README.md Installs the sigs.k8s.io/yaml package using the go get command. ```shell $ go get sigs.k8s.io/yaml ``` -------------------------------- ### Install otlptranslator with go get Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/prometheus/otlptranslator/README.md Installs the otlptranslator Go library from GitHub. ```bash go get github.com/prometheus/otlptranslator ``` -------------------------------- ### Install conc with go get Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/sourcegraph/conc/README.md Use this command to install the conc library. It fetches the package from GitHub. ```sh go get github.com/sourcegraph/conc ``` -------------------------------- ### Install go-isatty with go get Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/mattn/go-isatty/README.md This shell command installs the go-isatty package using the go get tool. It is the standard way to add the package to a Go project. ```shell $ go get github.com/mattn/go-isatty ``` -------------------------------- ### Install color library Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/fatih/color/README.md Use the go get command to install the color package into your Go project. ```bash go get github.com/fatih/color ``` -------------------------------- ### Test script file creation example Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/fsnotify/fsnotify/CONTRIBUTING.md Example of creating a file and verifying the resulting events. ```text # Create a new empty file with some data. watch / echo data >/file Output: create /file write /file ``` -------------------------------- ### Install go.yaml.in/yaml/v3 Source: https://github.com/agent-substrate/substrate/blob/main/vendor/go.yaml.in/yaml/v3/README.md Installs the yaml package for Go using the go get command. ```bash go get go.yaml.in/yaml/v3 ``` -------------------------------- ### Install ll with Go modules Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/olekukonko/ll/README.md Install the ll library using the go get command. Requires Go 1.21 or later. ```bash go get github.com/olekukonko/ll ``` -------------------------------- ### Install Viper with go get Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/spf13/viper/README.md Use this command to install the Viper library. It requires Go Modules for dependency management. ```shell go get github.com/spf13/viper ``` -------------------------------- ### Install swag module with go get Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/go-openapi/swag/README.md Use this command to install the swag module. The placeholder {module} should be replaced with the specific child module name. ```cmd go get github.com/go-openapi/swag/{module} ``` -------------------------------- ### Install IAM Go Client Library Source: https://github.com/agent-substrate/substrate/blob/main/vendor/cloud.google.com/go/iam/README.md Install the Go client library for the Identity and Access Management (IAM) API using the go get command. ```bash go get cloud.google.com/go/iam ``` -------------------------------- ### Install mapstructure Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/go-viper/mapstructure/v2/README.md Use the go get command to add the library to your project. ```shell go get github.com/go-viper/mapstructure/v2 ``` -------------------------------- ### Install interpolate with go get Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/mfridman/interpolate/README.md Install the interpolate library using the Go module tool. ```bash go get github.com/mfridman/interpolate@latest ``` -------------------------------- ### Install and import mergo Source: https://github.com/agent-substrate/substrate/blob/main/vendor/dario.cat/mergo/README.md Install the mergo package with go get and import it in your Go code. ```bash go get dario.cat/mergo ``` ```go // use in your .go code import ( "dario.cat/mergo" ) ``` -------------------------------- ### Install EventBus with go get Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/asaskevich/EventBus/README.md Install the EventBus package using the Go package manager. ```bash go get github.com/asaskevich/EventBus ``` -------------------------------- ### Install a Google Cloud Go package Source: https://github.com/agent-substrate/substrate/blob/main/vendor/cloud.google.com/go/README.md Use `go get` to install a specific package, replacing `firestore` with the desired package name. ```bash go get cloud.google.com/go/firestore@latest # Replace firestore with the package you want to use. ``` -------------------------------- ### Get the netns package with go get Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/vishvananda/netns/README.md Use this command to download and install the netns package. ```shell go get github.com/vishvananda/netns ``` -------------------------------- ### Setup test database in new cluster Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/jackc/pgx/v5/CONTRIBUTING.md Sets up the test database in the new cluster using the provided SQL setup script. ```shell createdb psql --no-psqlrc -f testsetup/postgresql_setup.sql ``` -------------------------------- ### Set up local kind cluster and counter demo Source: https://github.com/agent-substrate/substrate/blob/main/README.md Sets up a local kind cluster with a registry, installs the ATE system and counter demo, installs kubectl-ate, creates a counter actor, and port-forwards the network router to local port 8000. Requires Go, kubectl, and docker; other dependencies are managed automatically. ```shell hack/create-kind-cluster.sh # install ate, PostgreSQL, rustfs hack/install-ate-kind.sh --deploy-ate-system # install counter demo hack/install-ate-kind.sh --deploy-demo-counter # install kubectl-ate go install ./cmd/kubectl-ate # create a counter actor in the demo's atespace (--template names the # actor template, resolved in the actor's atespace) kubectl ate create actor my-counter-1 -a ate-demo-counter --template counter # port-forward the network router to bind to local port `8000` kubectl port-forward -n ate-system svc/atenet-router 8000:80 ``` -------------------------------- ### Example: Create and switch network namespaces in Go Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/vishvananda/netns/README.md Complete Go example that locks the OS thread, saves the current namespace, creates a new one, lists interfaces, and switches back to the original namespace. ```go package main import ( "fmt" "net" "runtime" "github.com/vishvananda/netns" ) func main() { // Lock the OS Thread so we don't accidentally switch namespaces runtime.LockOSThread() defer runtime.UnlockOSThread() // Save the current network namespace origns, _ := netns.Get() defer origns.Close() // Create a new network namespace newns, _ := netns.New() defer newns.Close() // Do something with the network namespace ifaces, _ := net.Interfaces() fmt.Printf("Interfaces: %v\n", ifaces) // Switch back to the original namespace netns.Set(origns) } ``` -------------------------------- ### Install uuid package with go get Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/google/uuid/README.md Use this command to install the github.com/google/uuid package. Run it in your terminal to fetch the package. ```sh go get github.com/google/uuid ``` -------------------------------- ### Install Google Auth Library for Go Source: https://github.com/agent-substrate/substrate/blob/main/vendor/cloud.google.com/go/auth/README.md Install the Google Auth Library for Go using the Go module tool. ```bash go get cloud.google.com/go/auth@latest ``` -------------------------------- ### Install properties library with go get Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/magiconair/properties/README.md Installs or upgrades the properties library using the Go module tool. This command fetches the latest version from the repository. ```shell $ go get -u github.com/magiconair/properties ``` -------------------------------- ### Cross-process server example Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/asaskevich/EventBus/README.md Server-side code for cross-process events: start a server, publish an event, and stop. ```go func main() { server := NewServer(":2010", "/_server_bus_", New()) server.Start() // ... server.EventBus().Publish("main:calculator", 4, 6) // ... server.Stop() } ``` -------------------------------- ### Cross-process client example Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/asaskevich/EventBus/README.md Client-side code for cross-process events: start a client, subscribe to a remote topic, and stop. ```go func main() { client := NewClient(":2015", "/_client_bus_", New()) client.Start() client.Subscribe("main:calculator", calculator, ":2010", "/_server_bus_") // ... client.Stop() } ``` -------------------------------- ### Install jsonpatch with go get Source: https://github.com/agent-substrate/substrate/blob/main/vendor/gopkg.in/evanphx/json-patch.v4/README.md Use this command to get the latest version of the jsonpatch library. For version 4, use the gopkg.in path. ```bash go get -u github.com/evanphx/json-patch/v5 ``` -------------------------------- ### Quick Start: Basic logging with ll Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/olekukonko/ll/README.md Shows how to create a logger and log messages immediately without explicit enabling. Demonstrates basic Info, Warn, Error calls and structured fields with Fields(). ```go package main import "github.com/olekukonko/ll" func main() { // Logger is ENABLED by default - no .Enable() needed! logger := ll.New("app") // Basic logging - works immediately logger.Info("Server starting") // Output: [app] INFO: Server starting logger.Warn("Memory high") // Output: [app] WARN: Memory high logger.Error("Connection failed") // Output: [app] ERROR: Connection failed // Structured fields logger.Fields("user", "alice", "status", 200).Info("Login successful") // Output: [app] INFO: Login successful [user=alice status=200] } ``` -------------------------------- ### Install development preview from master Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/olekukonko/tablewriter/README_LEGACY.md Use this command to get the in-progress, unstable version of tablewriter for development preview. ```bash go get github.com/olekukonko/tablewriter@master ``` -------------------------------- ### Quick Start with Logger Source: https://github.com/agent-substrate/substrate/blob/main/vendor/go.uber.org/zap/README.md Use the Logger when performance and type safety are critical. It is even faster than the SugaredLogger and allocates far less, but only supports structured logging. The example shows creating a production logger and logging with strongly typed fields. ```go logger, _ := zap.NewProduction() defer logger.Sync() logger.Info("failed to fetch URL", // Structured context as strongly typed Field values. zap.String("url", url), zap.Int("attempt", 3), zap.Duration("backoff", time.Second), ) ``` -------------------------------- ### Run ate-setup and build with make Source: https://github.com/agent-substrate/substrate/blob/main/cmd/ate-setup/README.md Shows the general command syntax for running ate-setup and the make target to build the binary. The make command builds bin/ate-setup. ```bash go run ./cmd/ate-setup [global flags] [flags] make build-ate-setup # builds bin/ate-setup ``` -------------------------------- ### Install micro-VM fixtures Source: https://github.com/agent-substrate/substrate/blob/main/internal/e2e/README.md Install the counter-microvm and egress-microvm demos needed for the micro-VM sandbox class. Requires a node with /dev/kvm. ```shell $ hack/run-microvm-demo-kind.sh # counter-microvm + assets $ hack/install-ate-kind.sh --deploy-demo-egress-microvm # egress-microvm ``` -------------------------------- ### Set up Go 1.25.9 with gvm Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/testcontainers/testcontainers-go/AI.md Run before any Go command. Use the appropriate architecture flag for your machine: arm64 for Apple Silicon, amd64 for Intel/AMD. ```bash # For Apple Silicon (M1/M2/M3) eval "$(gvm 1.25.9 --arch=arm64)" # For Intel/AMD (x86_64) eval "$(gvm 1.25.9 --arch=amd64)" ``` -------------------------------- ### Install jsonreference with go get Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/go-openapi/jsonreference/README.md Use this command to add the jsonreference library to your Go project. It fetches the latest version from the module proxy. ```cmd go get github.com/go-openapi/jsonreference ``` -------------------------------- ### Quick Start with SugaredLogger Source: https://github.com/agent-substrate/substrate/blob/main/vendor/go.uber.org/zap/README.md Use the SugaredLogger when performance is nice but not critical. It is 4-10x faster than other structured logging packages and supports both structured and printf-style APIs. The example shows creating a production logger, deferring Sync to flush buffers, and logging with Infow and Infof. ```go logger, _ := zap.NewProduction() defer logger.Sync() // flushes buffer, if any sugar := logger.Sugar() sugar.Infow("failed to fetch URL", // Structured context as loosely typed key-value pairs. "url", url, "attempt", 3, "backoff", time.Second, ) sugar.Infof("Failed to fetch URL: %s", url) ``` -------------------------------- ### Usage example: GetOnline and GetPossible Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/tklauser/numcpus/README.md Shows how to use the numcpus package to retrieve the number of online and possible CPUs. The example prints the results to stdout and writes errors to stderr. It is the only usage example on the page. ```Go package main import ( "fmt" "os" "github.com/tklauser/numcpus" ) func main() { online, err := numcpus.GetOnline() if err != nil { fmt.Fprintf(os.Stderr, "GetOnline: %v\n", err) } fmt.Printf("online CPUs: %v\n", online) possible, err := numcpus.GetPossible() if err != nil { fmt.Fprintf(os.Stderr, "GetPossible: %v\n", err) } fmt.Printf("possible CPUs: %v\n", possible) } ``` -------------------------------- ### Micro-VM demo bring-up steps (assemble, cluster, stage, apply) Source: https://github.com/agent-substrate/substrate/blob/main/hack/microvm-assets/README.md Manual steps to assemble micro-VM assets, bring up a kind cluster with the control plane, stage assets into rustfs, and apply the counter demo. Run on a KVM-capable Linux host matching the node arch; assets are single-arch. ```sh ARCH=arm64 hack/microvm-assets/assemble.sh ``` ```sh hack/create-kind-cluster.sh # mounts /dev/kvm into the nodes hack/install-ate-kind.sh # control plane + rustfs (bucket: ate-snapshots) ``` ```sh OUT="$PWD/microvm-assets-arm64" hack/microvm-assets/stage-to-rustfs.sh ``` ```sh BUCKET_NAME=ate-snapshots SUBSTRATE_VERSION="$(git describe --tags --always --dirty)" envsubst < demos/counter/counter-microvm.yaml.tmpl | kubectl apply -f - # the pool pins workers to nodes labeled with this version ``` -------------------------------- ### Install golangci-lint and run linter Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/pelletier/go-toml/v2/AGENTS.md Install a specific version of golangci-lint (check lint.yml for current version) and run the linter on the codebase. The version must match CI. ```bash # Install specific version (check lint.yml for current version) curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s -- -b $(go env GOPATH)/bin ``` ```bash # Run linter golangci-lint run ./... ``` -------------------------------- ### Install errors package with go get Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/olekukonko/errors/README.md Install the latest version of the errors package using the go get command. ```bash go get github.com/olekukonko/errors@latest ``` -------------------------------- ### Create GCP cluster and bucket individually Source: https://github.com/agent-substrate/substrate/blob/main/README.md Runs individual GCP setup steps to create a cluster and a bucket. See `go run ./tools/setup-gcp --help` for available options. ```bash go run ./tools/setup-gcp create cluster go run ./tools/setup-gcp create bucket ``` -------------------------------- ### Install Agent Substrate core system Source: https://github.com/agent-substrate/substrate/blob/main/demos/jupyter/README.md Installs the Agent Substrate core system to the Kind cluster. ```bash ./hack/install-ate-kind.sh --deploy-ate-system ``` -------------------------------- ### Example .env file Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/subosito/gotenv/README.md Example .env file content with two variables. ```sh APP_ID=1234567 APP_SECRET=abcdef ``` -------------------------------- ### Registering and Using Aliases with viper.RegisterAlias Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/spf13/viper/README.md Demonstrates how to create an alias for a key and use it to set and get values. The example shows that setting either the alias or the original key yields the same result. ```go viper.RegisterAlias("loud", "Verbose") viper.Set("verbose", true) // same result as next line viper.Set("loud", true) // same result as prior line viper.GetBool("loud") // true viper.GetBool("verbose") // true ``` -------------------------------- ### Basic glog usage examples Source: https://github.com/agent-substrate/substrate/blob/main/vendor/k8s.io/klog/v2/README.md These examples show basic logging calls using the glog package. Use glog.Info for informational messages and glog.Fatalf for fatal errors with formatting. The examples are from the glog.go comment and demonstrate the primary logging functions. ```go glog.Info("Prepare to repel boarders") ``` ```go glog.Fatalf("Initialization failed: %s", err) ``` -------------------------------- ### Example test main for a new suite Source: https://github.com/agent-substrate/substrate/blob/main/internal/e2e/README.md Copy this from internal/e2e/suites/example/testmain_test.go. It sets up and tears down the suite and runs the e2e test main, handling standard flags and checks. ```go func run(m *testing.M) int { Setup() defer Teardown() // return allows the deferred Teardown to run. return e2e.RunTestMain(m) } func TestMain(m *testing.M) { os.Exit(run(m)) } ``` -------------------------------- ### Initialize blockdevice FS for proc and sys Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/prometheus/procfs/README.md Shows how to create a blockdevice FS from both /proc and /sys, then read disk statistics. Requires the blockdevice sub-package. ```go fs, err := blockdevice.NewFS("/proc", "/sys") stats, err := fs.ProcDiskstats() ``` -------------------------------- ### Save and load cache example Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/Yiling-J/theine-go/README.md This example shows how to save a cache to a file and load it into a new client. The LoadCache call must be made immediately after creating the new client to avoid affecting TTL of existing entries. The version number must match between save and load. ```go // save f, err := os.Create("test") err := client.SaveCache(0, f) f.Close() // load f, err = os.Open("test") require.Nil(t, err) newClient, err := theine.NewBuilder[int, int](100).Build() // load immediately after client created err = newClient.LoadCache(0, f) f.Close() ``` -------------------------------- ### ate-setup command syntax Source: https://github.com/agent-substrate/substrate/blob/main/cmd/ate-setup/commands.md Shows the general syntax for running ate-setup commands with global flags and a single command. ```bash go run ./cmd/ate-setup [global flags] [flags] ``` -------------------------------- ### Install CLI and spawn load actors Source: https://github.com/agent-substrate/substrate/blob/main/demos/autoscaled-workerpool/README.md Installs the kubectl-ate plugin and creates 15 actors in the demo atespace using the counter template. ```sh # Install the CLI as a kubectl plugin if not already installed go install ./cmd/kubectl-ate # Create 15 actors to generate load for i in {001..015}; do kubectl ate create actor c$i -a ate-demo-autoscaled-workerpool --template counter done ``` -------------------------------- ### Marshal all settings to YAML string Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/spf13/viper/README.md Use viper.AllSettings() to get a map of all settings and then marshal it to a YAML string with yaml.Marshal. The example shows a function that returns the YAML string and logs a fatal error if marshalling fails. ```go import ( yaml "gopkg.in/yaml.v2" // ... ) func yamlStringSettings() string { c := viper.AllSettings() bs, err := yaml.Marshal(c) if err != nil { log.Fatalf("unable to marshal config to YAML: %v", err) } return string(bs) } ``` -------------------------------- ### Install kubectl-ate CLI Source: https://github.com/agent-substrate/substrate/blob/main/demos/jupyter/README.md Installs the kubectl-ate CLI from the source directory. ```bash go install ./cmd/kubectl-ate ``` -------------------------------- ### Install meter and send control plane to it Source: https://github.com/agent-substrate/substrate/blob/main/benchmarking/telemetry/README.md Installs the meter with kubectl apply and sets the OTLP endpoint to the meter's service, then runs install-ate.sh with --otlp-endpoint to patch the ate-otel-config ConfigMap and restart workloads. ```bash kubectl apply -f benchmarking/telemetry/meter.yaml METER=http://telemetry-meter.benchmarking.svc.cluster.local:4317 ./hack/install-ate.sh --deploy-ate-system --otlp-endpoint "${METER}" ``` -------------------------------- ### Basic table creation and rendering Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/olekukonko/tablewriter/README_LEGACY.md Creates a table with a header and appends rows, then renders to stdout. Demonstrates automatic padding and alignment. ```go data := [][]string{ []string{"A", "The Good", "500"}, []string{"B", "The Very very Bad Man", "288"}, []string{"C", "The Ugly", "120"}, []string{"D", "The Gopher", "800"}, } table := tablewriter.NewWriter(os.Stdout) table.SetHeader([]string{"Name", "Sign", "Rating"}) for _, v := range data { table.Append(v) } table.Render() // Send output ``` -------------------------------- ### Sample usage model for codec handles, encoders, decoders, and RPC Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/ugorji/go/codec/README.md Shows how to create and configure codec handles (Binc, Msgpack, Cbor), set up extensions, create encoders/decoders, and use RPC server/client codecs. The Handle is safe for concurrent read but not modification; Encoder/Decoder are not safe for concurrent use. Use Reset() to reuse an Encoder/Decoder. ```go // create and configure Handle var ( bh codec.BincHandle mh codec.MsgpackHandle ch codec.CborHandle ) mh.MapType = reflect.TypeOf(map[string]interface{}(nil)) // configure extensions // e.g. for msgpack, define functions and enable Time support for tag 1 // mh.SetExt(reflect.TypeOf(time.Time{}), 1, myExt) // create and use decoder/encoder var ( r io.Reader w io.Writer b []byte h = &bh // or mh to use msgpack ) dec = codec.NewDecoder(r, h) dec = codec.NewDecoderBytes(b, h) err = dec.Decode(&v) enc = codec.NewEncoder(w, h) enc = codec.NewEncoderBytes(&b, h) err = enc.Encode(v) //RPC Server go func() { for { conn, err := listener.Accept() rpcCodec := codec.GoRpc.ServerCodec(conn, h) //OR rpcCodec := codec.MsgpackSpecRpc.ServerCodec(conn, h) rpc.ServeCodec(rpcCodec) } }() //RPC Communication (client side) conn, err = net.Dial("tcp", "localhost:5555") rpcCodec := codec.GoRpc.ClientCodec(conn, h) //OR rpcCodec := codec.MsgpackSpecRpc.ClientCodec(conn, h) client := rpc.NewClientWithCodec(rpcCodec) ``` -------------------------------- ### Install goose binary with go install Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/pressly/goose/v3/README.md Installs the goose CLI binary to $GOPATH/bin. Requires Go installed. ```shell go install github.com/pressly/goose/v3/cmd/goose@latest ``` -------------------------------- ### Install ULID command-line tool Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/oklog/ulid/v2/README.md Installs the ULID command-line tool using Go's install command. Requires Go to be installed and the module to be available. ```shell go install github.com/oklog/ulid/v2/cmd/ulid@latest ``` -------------------------------- ### Check Go version Source: https://github.com/agent-substrate/substrate/blob/main/vendor/cloud.google.com/go/CONTRIBUTING.md Verify that Go is installed and accessible in your environment. ```bash go version ``` -------------------------------- ### Provision Cloud SQL instance Source: https://github.com/agent-substrate/substrate/blob/main/tools/setup-gcp/cloud-sql.md Use the setup tool to idempotently create a Cloud SQL instance with the required IAM roles and Workload Identity bindings. ```sh export PROJECT_ID= go run ./tools/setup-gcp create cloudsql --region= # other flags: --instance, --tier, --edition, --storage-size, --gsa-name, --network ``` -------------------------------- ### Install Gonum BLAS Source: https://github.com/agent-substrate/substrate/blob/main/vendor/gonum.org/v1/gonum/blas/README.md Use the go get command to install the Gonum BLAS package collection. ```sh go get gonum.org/v1/gonum/blas/... ``` -------------------------------- ### Clone and set up the zap repository Source: https://github.com/agent-substrate/substrate/blob/main/vendor/go.uber.org/zap/CONTRIBUTING.md Fork and clone the repository, then add the upstream remote and fetch it. This is the initial setup for contributing. ```bash mkdir -p $GOPATH/src/go.uber.org cd $GOPATH/src/go.uber.org git clone git@github.com:your_github_username/zap.git cd zap git remote add upstream https://github.com/uber-go/zap.git git fetch upstream ``` -------------------------------- ### Initialize MinIO Backend Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/spf13/afero/README.md Use the cpyun/afero-minio package to create an S3-compatible object storage filesystem. ```go import "github.com/cpyun/afero-minio" minioFs := miniofs.NewMinioFs(ctx, "minio://endpoint/bucket") ``` -------------------------------- ### Install and use jsontoml Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/pelletier/go-toml/v2/README.md Commands to install and view help for the jsontoml tool, which reads a JSON file and outputs a TOML representation. ```shell $ go install github.com/pelletier/go-toml/v2/cmd/jsontoml@latest $ jsontoml --help ``` -------------------------------- ### Install Gonum LAPACK packages Source: https://github.com/agent-substrate/substrate/blob/main/vendor/gonum.org/v1/gonum/lapack/README.md Install the Gonum LAPACK packages using the Go module tool. ```bash go get gonum.org/v1/gonum/lapack/... ``` -------------------------------- ### Install libsodium Source: https://github.com/agent-substrate/substrate/blob/main/_LICENSES/github.com/myzhan/gomq/README.md Downloads and verifies libsodium 1.0.8, then builds and installs it. Run `sudo ldconfig` on Linux; skip on OSX. ```bash wget https://download.libsodium.org/libsodium/releases/libsodium-1.0.8.tar.gz wget https://download.libsodium.org/libsodium/releases/libsodium-1.0.8.tar.gz.sig wget https://download.libsodium.org/jedi.gpg.asc gpg --import jedi.gpg.asc gpg --verify libsodium-1.0.8.tar.gz.sig libsodium-1.0.8.tar.gz tar zxvf libsodium-1.0.8.tar.gz cd libsodium-1.0.8 ./configure; make check sudo make install sudo ldconfig ``` -------------------------------- ### Enable GCP APIs subcommand Source: https://github.com/agent-substrate/substrate/blob/main/tools/setup-gcp/README.md Runs the setup-gcp tool to enable required GCP APIs. Uses the global --project-id flag to specify the project. ```bash go run ./tools/setup-gcp enable apis [flags] ``` -------------------------------- ### Environment Variable Binding Example Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/spf13/viper/README.md Shows how to bind a key to an environment variable with a prefix. The example sets the prefix to 'spf', binds the key 'id', and then retrieves the value after setting the environment variable SPF_ID. ```go SetEnvPrefix("spf") // will be uppercased automatically BindEnv("id") os.Setenv("SPF_ID", "13") // typically done outside of the app id := Get("id") // 13 ``` -------------------------------- ### Example I/O Timeout Error Source: https://github.com/agent-substrate/substrate/blob/main/vendor/google.golang.org/grpc/README.md This is an example of the error message produced by go get when the golang.org domain is unreachable. ```console $ go get -u google.golang.org/grpc package google.golang.org/grpc: unrecognized import path "google.golang.org/grpc" (https fetch: Get https://google.golang.org/grpc?go-get=1: dial tcp 216.239.37.1:443: i/o timeout) ``` -------------------------------- ### Install and use tomljson Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/pelletier/go-toml/v2/README.md Commands to install and view help for the tomljson tool, which reads a TOML file and outputs its JSON representation. ```shell $ go install github.com/pelletier/go-toml/v2/cmd/tomljson@latest $ tomljson --help ``` -------------------------------- ### Build and run the dashboard binary Source: https://github.com/agent-substrate/substrate/blob/main/demos/claude-code-multiplex/README.md Compile the UI server into a binary and run it with the same environment variables. Use this to avoid the Go toolchain at runtime. The binary name is ui-server and it listens on the provided PORT. ```bash cd demos/claude-code-multiplex/ui go build -o ui-server . PORT=8090 ATEAPI_ADDR=localhost:8080 ./ui-server ``` -------------------------------- ### Install Lima and Docker CLI with Homebrew Source: https://github.com/agent-substrate/substrate/blob/main/docs/dev/microvm-local.md Installs the `lima` and `docker` command-line tools via Homebrew. Required before launching the nested-virtualization VM. ```sh brew install lima docker ``` -------------------------------- ### Example Usage: Creating and Using a Puddle Pool Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/jackc/puddle/v2/README.md This example shows how to create a puddle pool with a constructor that dials a TCP connection, acquire a resource, use it, and release it. It requires a running TCP server on 127.0.0.1:8080. The pool is configured with a max size of 10. ```go package main import ( "context" "log" "net" "github.com/jackc/puddle/v2" ) func main() { constructor := func(context.Context) (net.Conn, error) { return net.Dial("tcp", "127.0.0.1:8080") } destructor := func(value net.Conn) { value.Close() } maxPoolSize := int32(10) pool, err := puddle.NewPool(&puddle.Config[net.Conn]{Constructor: constructor, Destructor: destructor, MaxSize: maxPoolSize}) if err != nil { log.Fatal(err) } // Acquire resource from the pool. res, err := pool.Acquire(context.Background()) if err != nil { log.Fatal(err) } // Use resource. _, err = res.Value().Write([]byte{1}) if err != nil { log.Fatal(err) } // Release when done. res.Release() } ``` -------------------------------- ### Deploy the parking demo with install-ate.sh Source: https://github.com/agent-substrate/substrate/blob/main/demos/parking/README.md Runs the installation script to build the counter workload image, create the ate-demo-parking namespace, a 2-replica WorkerPool, the atespace, and the actor template. Do not manually edit the YAML templates; the script injects the BUCKET_NAME environment variable. ```bash ./hack/install-ate.sh --deploy-demo-parking ``` -------------------------------- ### Install graphemes package with go get Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/clipperhouse/uax29/v2/graphemes/README.md Install the graphemes package from the uax29 module. Run this command in your terminal before using the package. ```bash go get "github.com/clipperhouse/uax29/v2/graphemes" ``` -------------------------------- ### Example using TagSet and TagOptions Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/fxamacker/cbor/v2/README.md Shows how to create a TagSet, register a CBOR tag (number 18) with a custom type, and create EncMode/DecMode with tag support. The example uses `signedCWT` type defined elsewhere and demonstrates both encoding and decoding with tags. TagSet and modes are safe for concurrent use. ```Go // Use signedCWT struct defined in "Decoding CWT" example. // Create TagSet (safe for concurrency). tags := cbor.NewTagSet() // Register tag COSE_Sign1 18 with signedCWT type. tags.Add( cbor.TagOptions{EncTag: cbor.EncTagRequired, DecTag: cbor.DecTagRequired}, reflect.TypeOf(signedCWT{}), 18) // Create DecMode with immutable tags. dm, _ := cbor.DecOptions{}.DecModeWithTags(tags) // Unmarshal to signedCWT with tag support. var v signedCWT if err := dm.Unmarshal(data, &v); err != nil { return err } // Create EncMode with immutable tags. em, _ := cbor.EncOptions{}.EncModeWithTags(tags) // Marshal signedCWT with tag number. if data, err := em.Marshal(v); err != nil { return err } ``` -------------------------------- ### Initialize procfs and read system statistics Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/prometheus/procfs/README.md Shows how to create a procfs FS from /proc and then read system statistics via the Stat() method. Requires the procfs package. ```go fs, err := procfs.NewFS("/proc") stats, err := fs.Stat() ``` -------------------------------- ### Create and setup test database Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/jackc/pgx/v5/CONTRIBUTING.md Creates and sets up a test database for pgx tests. Requires an existing PostgreSQL server and a `postgres` user. ```shell export PGDATABASE=pgx_test createdb psql -c 'create extension hstore;' psql -c 'create extension ltree;' psql -c 'create domain uint64 as numeric(20,0);' ``` -------------------------------- ### Nested JSON configuration example Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/spf13/viper/README.md Example JSON configuration with nested host, datastore, metric, and warehouse objects. Used to demonstrate accessing nested keys with dot-delimited paths. ```json { "host": { "address": "localhost", "port": 5799 }, "datastore": { "metric": { "host": "127.0.0.1", "port": 3099 }, "warehouse": { "host": "198.0.0.1", "port": 2112 } } } ``` -------------------------------- ### Calling C functions from Go without Cgo using purego Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/ebitengine/purego/README.md Example for macOS and Linux that loads the system library and calls the C 'puts' function. Requires CGO_ENABLED=0 to run. Other platforms need special handling as shown in the complete example at examples/libc. ```go package main import ( "fmt" "runtime" "github.com/ebitengine/purego" ) func getSystemLibrary() string { switch runtime.GOOS { case "darwin": return "/usr/lib/libSystem.B.dylib" case "linux": return "libc.so.6" default: panic(fmt.Errorf("GOOS=%s is not supported", runtime.GOOS)) } } func main() { libc, err := purego.Dlopen(getSystemLibrary(), purego.RTLD_NOW|purego.RTLD_GLOBAL) if err != nil { panic(err) } var puts func(string) purego.RegisterLibFunc(&puts, libc, "puts") puts("Calling C from Go without Cgo!") } ``` ```bash CGO_ENABLED=0 go run main.go ``` -------------------------------- ### Install and run json-patch CLI Source: https://github.com/agent-substrate/substrate/blob/main/vendor/gopkg.in/evanphx/json-patch.v4/README.md Commands to install the json-patch command-line tool and apply the example patches to document.json. The output shows the patched document. ```bash $ go install github.com/evanphx/json-patch/cmd/json-patch $ cat document.json | json-patch -p patch.1.json -p patch.2.json {"address":"123 Main St","age":"21","name":"Jane"} ``` -------------------------------- ### Replace client.Copy for queries with Query.Run Source: https://github.com/agent-substrate/substrate/blob/main/vendor/cloud.google.com/go/CHANGES.md Migration for starting a query job. Use Query.Run instead of client.Copy. ```go client.Copy(ctx, table, query) ``` ```go query.Run(ctx) ``` -------------------------------- ### Run make all Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/grpc-ecosystem/go-grpc-middleware/CONTRIBUTING.md Run the full validation suite: vet, fmt, regenerate documentation, and run all tests. ```bash make all ``` -------------------------------- ### Go: SpdyStream client example (connecting to mirroring server without auth) Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/moby/spdystream/README.md Creates a TCP connection to localhost:8080, initializes a SpdyStream connection with isServer set to false, serves the connection with NoOpStreamHandler, creates a stream with empty headers and no parent, writes to the stream, reads the response into a buffer, and prints it. The stream is closed after reading. ```Go package main import ( "fmt" "github.com/moby/spdystream" "net" "net/http" ) func main() { conn, err := net.Dial("tcp", "localhost:8080") if err != nil { panic(err) } spdyConn, err := spdystream.NewConnection(conn, false) if err != nil { panic(err) } go spdyConn.Serve(spdystream.NoOpStreamHandler) stream, err := spdyConn.CreateStream(http.Header{}, nil, false) if err != nil { panic(err) } stream.Wait() fmt.Fprint(stream, "Writing to stream") buf := make([]byte, 25) stream.Read(buf) fmt.Println(string(buf)) stream.Close() } ``` -------------------------------- ### Create a client with a service account key file Source: https://github.com/agent-substrate/substrate/blob/main/vendor/cloud.google.com/go/README.md Creates a storage client using a service account key file by passing `option.WithCredentialsFile` to `NewClient`. Set the `GOOGLE_APPLICATION_CREDENTIALS` environment variable or use this option. ```go client, err := storage.NewClient(ctx, option.WithCredentialsFile("path/to/keyfile.json")) ``` -------------------------------- ### Install kubectl-ate and create actors from different templates Source: https://github.com/agent-substrate/substrate/blob/main/demos/multi-template/README.md Installs the kubectl-ate plugin and creates one actor per template. Each actor is created in its template's atespace, with the template resolved in that atespace. The actor's DNS name embeds the atespace. ```bash go install ./cmd/kubectl-ate ``` ```bash kubectl ate create actor c1 -a ate-demo-multi-template-counter --template counter kubectl ate create actor f1 -a ate-demo-multi-template-fspersist --template fspersist ``` -------------------------------- ### Initialize Amazon S3 Backend Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/spf13/afero/README.md Use the fclairamb/afero-s3 package to create a production-ready S3 filesystem backend. ```go import "github.com/fclairamb/afero-s3" s3fs := s3.NewFs(bucket, session) ``` -------------------------------- ### Deploy ate-setup with custom image repository Source: https://github.com/agent-substrate/substrate/blob/main/cmd/ate-setup/README.md Deploys ate-setup to the ate-system namespace using published images from a specified registry. No images are built or pushed; manifests come from the checkout and references are pinned to the digest of the given tag. ```bash ate-setup deploy ate-system \ --image-repo registry.example.com/substrate \ --image-tag v0.0.0 ``` -------------------------------- ### Run setup-gcp create cluster command Source: https://github.com/agent-substrate/substrate/blob/main/tools/setup-gcp/README.md Use this go run command to create a GKE cluster via the setup-gcp tool. It handles enabling the required beta APIs and configures the cluster for Agent Substrate. Flags override environment variables and defaults as documented in the table. ```bash go run ./tools/setup-gcp create cluster [flags] ``` -------------------------------- ### Install ULID with go get Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/oklog/ulid/v2/README.md Use this command to add the ULID package to your Go module dependencies. ```shell go get github.com/oklog/ulid/v2 ``` -------------------------------- ### Using the GCP Resource Detector in Go Source: https://github.com/agent-substrate/substrate/blob/main/vendor/go.opentelemetry.io/contrib/detectors/gcp/README.md This example shows how to create a resource using the GCP detector, keeping default detectors and adding custom attributes. It also demonstrates using the resource in a tracer provider. ```golang ctx := context.Background() // Detect your resources res, err := resource.New(ctx, // Use the GCP resource detector! resource.WithDetectors(gcp.NewDetector()), // Keep the default detectors resource.WithTelemetrySDK(), // Add your own custom attributes to identify your application resource.WithAttributes( semconv.ServiceNameKey.String("my-application"), semconv.ServiceNamespaceKey.String("my-company-frontend-team"), ), ) if err != nil { // Handle err } // Use the resource in your tracerprovider (or meterprovider) tp := trace.NewTracerProvider( // ... other options trace.WithResource(res), ) ``` -------------------------------- ### Standard library logging example Source: https://github.com/agent-substrate/substrate/blob/main/vendor/sigs.k8s.io/controller-runtime/TMP-LOGGING.md Shows the traditional Go standard library logging approach with a formatted message. ```go log.Printf("starting reconciliation for pod %s/%s", podNamespace, podName) ``` -------------------------------- ### Configure External PostgreSQL Connection Source: https://github.com/agent-substrate/substrate/blob/main/tools/setup-gcp/cloud-sql.md Environment variable setup and installation command for connecting to a non-GCP PostgreSQL database. ```sh export ATE_API_POSTGRES_CONNECTION_STRING='postgresql://:@:5432/atepg?sslmode=verify-ca&sslrootcert=/run/postgres-server-ca/server-ca.pem' export ATE_API_POSTGRES_SERVER_CA_FILE=/path/to/server-ca.pem ./hack/install-ate.sh --deploy-ate-system ``` -------------------------------- ### Incorrect go.mod reference Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/antlr4-go/antlr/v4/README.md An example of an unclear and problematic reference generated by go get when targeting the main antlr/antlr4 repository. ```sh require ( github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230219212500-1f9a474cc2dc ) ``` -------------------------------- ### Create a client with custom credentials Source: https://github.com/agent-substrate/substrate/blob/main/vendor/cloud.google.com/go/README.md Creates a storage client using credentials from the `credentials` package. Detect credentials with `credentials.DetectDefault` and pass them via `option.WithAuthCredentials`. ```go creds, err := credentials.DetectDefault(&credentials.DetectOptions{...}) ... client, err := storage.NewClient(ctx, option.WithAuthCredentials(creds)) ``` -------------------------------- ### Install boomer with go get: master branch and locust 1.6.0 tag Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/myzhan/boomer/README.md Installs boomer either from the master branch or from the v1.6.0 tag that works with locust 1.6.0. The master branch works with locust's master branch; tagged versions cover older locust releases when breaking changes are introduced. ```bash # Install the master branch $ go get github.com/myzhan/boomer@master # Install a tagged version that works with locust 1.6.0 $ go get github.com/myzhan/boomer@v1.6.0 ``` -------------------------------- ### Get clock ticks with sysconf.Sysconf Source: https://github.com/agent-substrate/substrate/blob/main/vendor/github.com/tklauser/go-sysconf/README.md Shows how to call sysconf.Sysconf with sysconf.SC_CLK_TCK to retrieve the number of clock ticks per second, equivalent to C.sysconf(_SC_CLK_TCK). The example prints the value if no error occurs. ```Go package main import ( "fmt" "github.com/tklauser/go-sysconf" ) func main() { // get clock ticks, this will return the same as C.sysconf(C._SC_CLK_TCK) clktck, err := sysconf.Sysconf(sysconf.SC_CLK_TCK) if err == nil { fmt.Printf("SC_CLK_TCK: %v\n", clktck) } } ```