### Getting Started with Cat Library Source: https://github.com/cri-o/cri-o/blob/main/vendor/github.com/olekukonko/cat/README.md Provides instructions for installing the 'cat' library using go get and demonstrates basic usage within a Go program, including simple concatenation and the use of pooled builders for high-performance loops. ```bash go get github.com/your-repo/cat ``` ```go import "github.com/your-repo/cat" func main() { // Simple concatenation msg := cat.Concat("User ", userID, " has ", count, " items") // Pooled builder (for high-performance loops) builder := cat.New(", ") defer builder.Release() // Return to pool result := builder.Add(items...).String() } ``` -------------------------------- ### Basic Go-Chi Router Setup Source: https://github.com/cri-o/cri-o/blob/main/vendor/github.com/go-chi/chi/v5/README.md A minimal example of setting up a Go-Chi router with a single GET route and basic logging middleware. This is suitable for simple web services. ```go package main import ( "net/http" "github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5/middleware" ) func main() { r := chi.NewRouter() r.Use(middleware.Logger) r.Get("/", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("welcome")) }) http.ListenAndServe(":3000", r) } ``` -------------------------------- ### Install displaywidth Package Source: https://github.com/cri-o/cri-o/blob/main/vendor/github.com/clipperhouse/displaywidth/README.md Use 'go get' to install the displaywidth package. ```bash go get github.com/clipperhouse/displaywidth ``` -------------------------------- ### Install go.yaml.in/yaml/v3 Source: https://github.com/cri-o/cri-o/blob/main/vendor/go.yaml.in/yaml/v3/README.md To install the package, run the go get command. ```bash go get go.yaml.in/yaml/v3 ``` -------------------------------- ### Install Mergo Source: https://github.com/cri-o/cri-o/blob/main/vendor/dario.cat/mergo/README.md Use `go get` to install the Mergo library. Then import it into your Go code. ```go go get dario.cat/mergo // use in your .go code import ( "dario.cat/mergo" ) ``` -------------------------------- ### Install Golang Color Library Source: https://github.com/cri-o/cri-o/blob/main/vendor/github.com/fatih/color/README.md Use 'go get' to install the color library. This command fetches and installs the specified package. ```bash go get github.com/fatih/color ``` -------------------------------- ### Install go-isatty Package Source: https://github.com/cri-o/cri-o/blob/main/vendor/github.com/mattn/go-isatty/README.md Install the go-isatty package using the go get command. ```bash go get github.com/mattn/go-isatty ``` -------------------------------- ### Quick Start Logging in Go Source: https://github.com/cri-o/cri-o/blob/main/vendor/github.com/olekukonko/ll/README.md A basic example demonstrating how to create a logger and perform info, warn, and error logging. Structured fields can be added to log messages. ```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 Cobra Library Source: https://github.com/cri-o/cri-o/blob/main/vendor/github.com/spf13/cobra/README.md Use 'go get' to install the latest version of the Cobra library. ```go go get -u github.com/spf13/cobra@latest ``` -------------------------------- ### Install pgzip Source: https://github.com/cri-o/cri-o/blob/main/vendor/github.com/klauspost/pgzip/README.md Use 'go get' to install the pgzip library. You may need to update its dependencies. ```go go get github.com/klauspost/pgzip/... ``` ```go go get -u github.com/klauspost/compress ``` -------------------------------- ### Run Command with Pty Source: https://github.com/cri-o/cri-o/blob/main/vendor/github.com/creack/pty/README.md This example demonstrates how to start a command with a pseudo-terminal and interact with it by writing to its input and reading from its output. It's intended for demonstration and not production use. ```go package main import ( "io" "os" "os/exec" "github.com/creack/pty" ) func main() { c := exec.Command("grep", "--color=auto", "bar") f, err := pty.Start(c) if err != nil { panic(err) } go func() { f.Write([]byte("foo\n")) f.Write([]byte("bar\n")) f.Write([]byte("baz\n")) f.Write([]byte{4}) // EOT }() io.Copy(os.Stdout, f) } ``` -------------------------------- ### Install otellogrus Source: https://github.com/cri-o/cri-o/blob/main/vendor/github.com/uptrace/opentelemetry-go-extra/otellogrus/README.md Install the otellogrus package using go get. ```shell go get github.com/uptrace/opentelemetry-go-extra/otellogrus ``` -------------------------------- ### Install go-openapi/spec Source: https://github.com/cri-o/cri-o/blob/main/vendor/github.com/go-openapi/spec/README.md Use go get to add the go-openapi/spec library to your project. ```cmd go get github.com/go-openapi/spec ``` -------------------------------- ### Install pty Package Source: https://github.com/cri-o/cri-o/blob/main/vendor/github.com/creack/pty/README.md Use 'go get' to install the pty package. ```sh go get github.com/creack/pty ``` -------------------------------- ### Install go-sqlite3 Source: https://github.com/cri-o/cri-o/blob/main/vendor/github.com/mattn/go-sqlite3/README.md Install the package using the go get command. Ensure CGO_ENABLED is set to 1 and a GCC compiler is available. ```go go get github.com/mattn/go-sqlite3 ``` -------------------------------- ### Install gorilla/mux Source: https://github.com/cri-o/cri-o/blob/main/vendor/github.com/gorilla/mux/README.md Install the gorilla/mux package using the go get command. Ensure your Go toolchain is correctly configured. ```sh go get -u github.com/gorilla/mux ``` -------------------------------- ### Define a WebService and Route Source: https://github.com/cri-o/cri-o/blob/main/vendor/github.com/emicklei/go-restful/v3/README.md Example of creating a WebService, defining its path, supported content types, and a GET route for retrieving a user. The route specifies documentation, a path parameter, and the expected response type. ```go ws := new(restful.WebService) ws. Path("/users"). Consumes(restful.MIME_XML, restful.MIME_JSON). Produces(restful.MIME_JSON, restful.MIME_XML) ws.Route(ws.GET("/{user-id}").To(u.findUser). Doc("get a user"). Param(ws.PathParameter("user-id", "identifier of the user").DataType("string")). Writes(User{})) ... func (u UserResource) findUser(request *restful.Request, response *restful.Response) { id := request.PathParameter("user-id") ... } ``` -------------------------------- ### Basic Ginkgo Spec Example Source: https://github.com/cri-o/cri-o/blob/main/vendor/github.com/onsi/ginkgo/v2/README.md A comprehensive example demonstrating how to structure a Ginkgo test suite. It includes setup with BeforeEach, defining test cases with It and Context, and using Gomega matchers for assertions. This snippet is suitable for understanding the core structure of Ginkgo tests. ```go import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ... ) var _ = Describe("Checking books out of the library", Label("library"), func() { var library *libraries.Library var book *books.Book var valjean *users.User BeforeEach(func() { library = libraries.NewClient() book = &books.Book{ Title: "Les Miserables", Author: "Victor Hugo", } valjean = users.NewUser("Jean Valjean") }) When("the library has the book in question", func() { BeforeEach(func(ctx SpecContext) { Expect(library.Store(ctx, book)).To(Succeed()) }) Context("and the book is available", func() { It("lends it to the reader", func(ctx SpecContext) { Expect(valjean.Checkout(ctx, library, "Les Miserables")).To(Succeed()) Expect(valjean.Books()).To(ContainElement(book)) Expect(library.UserWithBook(ctx, book)).To(Equal(valjean)) }, SpecTimeout(time.Second * 5)) }) Context("but the book has already been checked out", func() { var javert *users.User BeforeEach(func(ctx SpecContext) { javert = users.NewUser("Javert") Expect(javert.Checkout(ctx, library, "Les Miserables")).To(Succeed()) }) It("tells the user", func(ctx SpecContext) { err := valjean.Checkout(ctx, library, "Les Miserables") Expect(err).To(MatchError("Les Miserables is currently checked out")) }, SpecTimeout(time.Second * 5)) It("lets the user place a hold and get notified later", func(ctx SpecContext) { Expect(valjean.Hold(ctx, library, "Les Miserables")).To(Succeed()) Expect(valjean.Holds(ctx)).To(ContainElement(book)) By("when Javert returns the book") Expect(javert.Return(ctx, library, book)).To(Succeed()) By("it eventually informs Valjean") notification := "Les Miserables is ready for pick up" Eventually(ctx, valjean.Notifications).Should(ContainElement(notification)) Expect(valjean.Checkout(ctx, library, "Les Miserables")).To(Succeed()) Expect(valjean.Books(ctx)).To(ContainElement(book)) Expect(valjean.Holds(ctx)).To(BeEmpty()) }, SpecTimeout(time.Second * 10)) }) }) When("the library does not have the book in question", func() { It("tells the reader the book is unavailable", func(ctx SpecContext) { err := valjean.Checkout(ctx, library, "Les Miserables") Expect(err).To(MatchError("Les Miserables is not in the library catalog")) }, SpecTimeout(time.Second * 5)) }) }) ``` -------------------------------- ### Install Blackfriday v2 Source: https://github.com/cri-o/cri-o/blob/main/vendor/github.com/russross/blackfriday/v2/README.md Install the Blackfriday v2 package using the go get command. This command resolves and adds the package to your module, then builds and installs it. ```go go get github.com/russross/blackfriday/v2 ``` -------------------------------- ### Setup BATS Framework on Host Source: https://github.com/cri-o/cri-o/blob/main/test/README.md Install the BATS framework on your host machine for running integration tests directly. This involves cloning the BATS repository and running an installation script. ```shell cd ~/go/src/github.com git clone https://github.com/bats-core/bats-core.git cd bats ./install.sh /usr/local ``` -------------------------------- ### Install and Run Local Go Doc Site Source: https://github.com/cri-o/cri-o/blob/main/vendor/go.opentelemetry.io/otel/CONTRIBUTING.md Installs and runs a local Go Doc site for viewing package documentation. Ensure you have the latest version of pkgsite installed. ```shell go install golang.org/x/pkgsite/cmd/pkgsite@latest pkgsite ``` -------------------------------- ### Install Ginkgo Locally Source: https://github.com/cri-o/cri-o/blob/main/vendor/github.com/onsi/ginkgo/v2/CONTRIBUTING.md Installs Ginkgo locally using the go install command. Ensure Ginkgo is installed before running tests. ```bash go install ./... ``` -------------------------------- ### Install blackfriday-tool Source: https://github.com/cri-o/cri-o/blob/main/vendor/github.com/russross/blackfriday/v2/README.md Download and install the blackfriday-tool, a command-line tool for processing Markdown files. This also installs the blackfriday package. ```go go get github.com/russross/blackfriday-tool ``` -------------------------------- ### Go Git Submodule Example Source: https://github.com/cri-o/cri-o/blob/main/vendor/github.com/go-git/go-git/v5/COMPATIBILITY.md Demonstrates the usage of submodules in go-git. This example is located at _examples/submodule/main.go. ```go package main import ( "fmt" "os" "github.com/go-git/go-git/v5" ) func main() { // Open the repository in the current directory repo, err := git.PlainOpen(".") if err != nil { panic(err) } // Get the submodule iterator submodules, err := repo.Submodules() if err != nil { panic(err) } // Iterate over the submodules and print their names and URLs err = submodules.ForEach(func(submodule *git.Submodule) error { fmt.Printf("Name: %s\n", submodule.Config().Name) fmt.Printf("URL: %s\n", submodule.Config().URL) return nil }) if err != nil { panic(err) } } ``` -------------------------------- ### Go Git Push Example Source: https://github.com/cri-o/cri-o/blob/main/vendor/github.com/go-git/go-git/v5/COMPATIBILITY.md Demonstrates the push operation in go-git. This example is located at _examples/push/main.go. ```go package main import ( "fmt" "os" "github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5/plumbing/transport/http" ) func main() { // Open the repository in the current directory repo, err := git.PlainOpen(".") if err != nil { panic(err) } // Get the remote remote, err := repo.Remote("origin") if err != nil { panic(err) } // Push the changes to the remote repository var auth http.BasicAuth // If you need to use username and password, uncomment the following lines: // auth = http.BasicAuth{ // Username: "YOUR_USERNAME", // Password: "YOUR_PASSWORD", // } err = remote.Push(&git.PushOptions{ Auth: &auth, RemoteName: "origin", RefSpecs: []plumbing.RefSpec{plumbing.RefSpec("refs/heads/main:refs/heads/main")}, }) if err != nil { panic(err) } fmt.Println("Push successful.") } ``` -------------------------------- ### Install CRI-O Binary Source: https://github.com/cri-o/cri-o/blob/main/install.md Installs the CRI-O binary to the default location. This is the first step before running CRI-O. ```shell sudo make install ``` -------------------------------- ### Build and Run PKCS#11 Example Source: https://github.com/cri-o/cri-o/blob/main/vendor/github.com/stefanberger/go-pkcs11uri/README.md These commands demonstrate how to build the Go example program and then run it with a specific PKCS#11 URI. The URI includes the slot ID, module path, and PIN, allowing the program to connect to the SoftHSM2 token. ```bash $ go build ./... $ sudo ./pkcs11-example 'pkcs11:slot-id=2053753261?module-path=/usr/lib64/pkcs11/libsofthsm2.so&pin-value=1234' ``` -------------------------------- ### Table Initialization (v1.0.x) - Minimal Setup Source: https://github.com/cri-o/cri-o/blob/main/vendor/github.com/olekukonko/tablewriter/MIGRATION.md Shows the minimal setup for initializing a table writer in v1.0.x using `NewTable` with default configurations. ```go package main import ( "fmt" // Added for FormattableEntry example "github.com/olekukonko/tablewriter" "github.com/olekukonko/tablewriter/renderer" // Import renderer "github.com/olekukonko/tablewriter/tw" "os" "strings" // Added for Formatter example ) func main() { // Minimal Setup (Default Configuration) tableMinimal := tablewriter.NewTable(os.Stdout) _ = tableMinimal // Avoid "declared but not used" // Using Option Functions for Targeted Configuration tableWithOptions := tablewriter.NewTable(os.Stdout, tablewriter.WithHeaderAlignment(tw.AlignCenter), // Center header text tablewriter.WithRowAlignment(tw.AlignLeft), // Left-align row text tablewriter.WithDebug(true), // Enable debug logging ) _ = tableWithOptions // Avoid "declared but not used" // Using a Full Config Struct for Comprehensive Control cfg := tablewriter.Config{ Header: tw.CellConfig{ Alignment: tw.CellAlignment{ Global: tw.AlignCenter, PerColumn: []tw.Align{tw.AlignLeft, tw.AlignRight}, // Column-specific alignment }, Formatting: tw.CellFormatting{AutoFormat: tw.On}, }, Row: tw.CellConfig{ Alignment: tw.CellAlignment{Global: tw.AlignLeft}, Formatting: tw.CellFormatting{AutoWrap: tw.WrapNormal}, }, Footer: tw.CellConfig{ Alignment: tw.CellAlignment{Global: tw.AlignRight}, }, MaxWidth: 80, // Constrain total table width Behavior: tw.Behavior{ AutoHide: tw.Off, // Show empty columns TrimSpace: tw.On, // Trim cell spaces }, Widths: tw.CellWidth{ Global: 20, // Default fixed column width PerColumn: tw.NewMapper[int, int]().Set(0, 15), // Column 0 fixed at 15 }, } tableWithConfig := tablewriter.NewTable(os.Stdout, tablewriter.WithConfig(cfg)) _ = tableWithConfig // Avoid "declared but not used" // Using ConfigBuilder for Fluent, Complex Configuration builder := tablewriter.NewConfigBuilder(). WithMaxWidth(80). WithAutoHide(tw.Off). WithTrimSpace(tw.On). WithDebug(true). // Enable debug logging Header(). Alignment(). WithGlobal(tw.AlignCenter). Build(). // Returns *ConfigBuilder Header(). Formatting(). WithAutoFormat(tw.On). WithAutoWrap(tw.WrapTruncate). // Test truncation WithMergeMode(tw.MergeNone). // Explicit merge mode Build(). // Returns *HeaderConfigBuilder Padding(). WithGlobal(tw.Padding{Left: "[", Right: "]", Overwrite: true}). Build(). // Returns *HeaderConfigBuilder Build(). // Returns *ConfigBuilder Row(). Formatting(). WithAutoFormat(tw.On). // Uppercase rows Build(). // Returns *RowConfigBuilder Build(). // Returns *ConfigBuilder Row(). Alignment(). WithGlobal(tw.AlignLeft). Build(). // Returns *ConfigBuilder Build() // Finalize Config tableWithFluent := tablewriter.NewTable(os.Stdout, tablewriter.WithConfig(builder)) _ = tableWithFluent // Avoid "declared but not used" } ``` -------------------------------- ### Install json-iterator/go Source: https://github.com/cri-o/cri-o/blob/main/vendor/github.com/json-iterator/go/README.md Install the json-iterator/go library using the go get command. ```bash go get github.com/json-iterator/go ``` -------------------------------- ### Full Example: Mux Based Server Source: https://github.com/cri-o/cri-o/blob/main/vendor/github.com/gorilla/mux/README.md Provides a complete, runnable Go program demonstrating a basic web server using Gorilla Mux. It includes setting up a router and defining a simple handler for the root path. ```go package main import ( "net/http" "log" "github.com/gorilla/mux" ) func YourHandler(w http.ResponseWriter, r *http.Request) { w.Write([]byte("Gorilla!\n")) } func main() { r := mux.NewRouter() // Routes consist of a path and a handler function. r.HandleFunc("/", YourHandler) // Bind to a port and pass our router in log.Fatal(http.ListenAndServe(":8000", r)) } ``` -------------------------------- ### Install mapstructure Source: https://github.com/cri-o/cri-o/blob/main/vendor/github.com/go-viper/mapstructure/v2/README.md Install the mapstructure library using the go get command. ```shell go get github.com/go-viper/mapstructure/v2 ``` -------------------------------- ### Minimal Table Setup in Go Source: https://github.com/cri-o/cri-o/blob/main/vendor/github.com/olekukonko/tablewriter/MIGRATION.md Demonstrates a basic table creation with headers and data using default settings. This is a simple replacement for older versions' NewWriter and SetHeader/Append functions. ```go package main import ( "github.com/olekukonko/tablewriter" "os" ) func main() { table := tablewriter.NewTable(os.Stdout) table.Header("Name", "Status") table.Append("Node1", "Ready") ttable.Render() } ``` -------------------------------- ### Install stripansi Package Source: https://github.com/cri-o/cri-o/blob/main/vendor/github.com/acarl005/stripansi/README.md Use 'go get' to install the stripansi package. This command fetches and installs the package and its dependencies. ```sh $ go get -u github.com/acarl005/stripansi ``` -------------------------------- ### Basic Test Script Example Source: https://github.com/cri-o/cri-o/blob/main/vendor/github.com/fsnotify/fsnotify/CONTRIBUTING.md Demonstrates creating a test case using the script syntax. It shows how to watch a path and simulate file operations, with expected output events. ```shell # Create a new empty file with some data. watch / echo data >/file Output: create /file write /file ``` -------------------------------- ### Basic Table Creation Source: https://github.com/cri-o/cri-o/blob/main/vendor/github.com/olekukonko/tablewriter/README_LEGACY.md Demonstrates how to create a basic table with headers and data, rendering it to standard output. ```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 ``` -------------------------------- ### Install go-colorable Package Source: https://github.com/cri-o/cri-o/blob/main/vendor/github.com/mattn/go-colorable/README.md This command installs the go-colorable package using the go get command. Ensure you have Go installed and configured correctly. ```bash go get github.com/mattn/go-colorable ``` -------------------------------- ### Quick Example of TableWriter Usage Source: https://github.com/cri-o/cri-o/blob/main/vendor/github.com/olekukonko/tablewriter/README.md Demonstrates basic table creation with headers and bulk data insertion, rendering to standard output. ```go package main import ( "github.com/olekukonko/tablewriter" "os" ) func main() { data := [][]string{ {"Package", "Version", "Status"}, {"tablewriter", "v0.0.5", "legacy"}, {"tablewriter", "v1.1.3", "latest"}, } table := tablewriter.NewWriter(os.Stdout) ttable.Header(data[0]) ttable.Bulk(data[1:]) ttable.Render() } ``` -------------------------------- ### Install errors Package Source: https://github.com/cri-o/cri-o/blob/main/vendor/github.com/olekukonko/errors/README.md Install the latest version of the errors package using go get. ```bash go get github.com/olekukonko/errors@latest ``` -------------------------------- ### Setup Source: https://github.com/cri-o/cri-o/blob/main/vendor/github.com/urfave/cli/v2/godoc-current.txt Runs initialization code to ensure all data structures are ready for `Run` or inspection prior to `Run`. It is internally called by `Run`, but will return early if setup has already happened. ```APIDOC ## Setup ### Description Runs initialization code to ensure all data structures are ready for `Run` or inspection prior to `Run`. It is internally called by `Run`, but will return early if setup has already happened. ### Signature `func (a *App) Setup()` ``` -------------------------------- ### Install uuid Package Source: https://github.com/cri-o/cri-o/blob/main/vendor/github.com/google/uuid/README.md Use this command to install the uuid package using go get. ```sh go get github.com/google/uuid ``` -------------------------------- ### Go Git Tag Create and Push Example Source: https://github.com/cri-o/cri-o/blob/main/vendor/github.com/go-git/go-git/v5/COMPATIBILITY.md Demonstrates creating and pushing a tag in a go-git repository. This example is located at _examples/tag-create-push/main.go. ```go package main import ( "fmt" "os" "github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5/plumbing" "github.com/go-git/go-git/v5/plumbing/transport/http" ) func main() { // Open the repository in the current directory repo, err := git.PlainOpen(".") if err != nil { panic(err) } // Get the current HEAD head, err := repo.Head() if err != nil { panic(err) } // Create a new tag tagName := "v0.0.0" tagRef := plumbing.NewReferenceFromStrings(plumbing.NewTagReferenceName(tagName).String(), head.Hash().String()) err = repo.Storer().SetReference(tagRef) if err != nil { panic(err) } // Push the tag to the remote repository auth := http.BasicAuth{ Username: "", // no username needed Password: "", // no password needed } err = repo.Push(&git.PushOptions{ RemoteName: "origin", RefSpecs: []plumbing.RefSpec{plumbing.RefSpec("refs/tags/ ``` -------------------------------- ### Install Graphemes Package Source: https://github.com/cri-o/cri-o/blob/main/vendor/github.com/clipperhouse/uax29/v2/graphemes/README.md Use 'go get' to install the graphemes package for your Go project. ```bash go get "github.com/clipperhouse/uax29/v2/graphemes" ``` -------------------------------- ### Mock v0.0.5 Color Setting Example Source: https://github.com/cri-o/cri-o/blob/main/vendor/github.com/olekukonko/tablewriter/MIGRATION.md This mock example demonstrates how colors might have been set in v0.0.5 using specific color-setting methods and constants. Actual v0.0.5 definitions are not provided. ```go package main // Assuming tablewriter.Colors and color constants existed in v0.0.5 // This is a mock representation as the actual v0.0.5 definitions are not provided. // import "github.com/olekukonko/tablewriter" // import "os" // type Colors []interface{} // Mock // const ( // Bold = 1; FgGreenColor = 2; FgRedColor = 3 // Mock constants // ) func main() { // table := tablewriter.NewWriter(os.Stdout) // table.SetColumnColor( // tablewriter.Colors{tablewriter.Bold, tablewriter.FgGreenColor}, // Column 0 // tablewriter.Colors{tablewriter.FgRedColor}, // Column 1 // ) // table.SetHeader([]string{"Name", "Status"}) // table.Append([]string{"Node1", "Ready"}) // table.Render() } ``` -------------------------------- ### Proper Runtime Initialization in Go Source: https://github.com/cri-o/cri-o/blob/main/vendor/github.com/tetratelabs/wazero/RATIONALE.md Demonstrates the correct way to initialize a RuntimeConfig using the NewRuntimeConfig constructor, contrasting it with incorrect direct initialization. ```go rt := &RuntimeConfig{} // not initialized properly (fields are nil which shouldn't be) rt := RuntimeConfig{} // not initialized properly (should be a pointer) rt := wazero.NewRuntimeConfig() // initialized properly ``` -------------------------------- ### Install GoTree using Go Get Source: https://github.com/cri-o/cri-o/blob/main/vendor/github.com/disiqueira/gotree/v3/README.md Use this command to install the GoTree module into your Go project. ```bash go get github.com/disiqueira/gotree ``` -------------------------------- ### ModuleConfig with Options Pattern Source: https://github.com/cri-o/cri-o/blob/main/vendor/github.com/tetratelabs/wazero/RATIONALE.md Demonstrates an alternative Go pattern for configuration using option functions. ```go type ModuleConfig interface { } struct moduleConfig { name string fs fs.FS } type ModuleConfigOption func(c *moduleConfig) func ModuleConfigName(name string) ModuleConfigOption { return func(c *moduleConfig) { c.name = name } } func ModuleConfigFS(fs fs.FS) ModuleConfigOption { return func(c *moduleConfig) { c.fs = fs } } func (r *runtime) NewModuleConfig(opts ...ModuleConfigOption) ModuleConfig { ret := newModuleConfig() // defaults for _, opt := range opts { opt(&ret.config) } return ret } func (c *moduleConfig) WithOptions(opts ...ModuleConfigOption) ModuleConfig { ret := *c // copy base config for _, opt := range opts { opt(&ret.config) } return ret } config := r.NewModuleConfig(ModuleConfigFS(fs)) configDerived := config.WithOptions(ModuleConfigName("name")) ``` -------------------------------- ### Install go-md2man on RHEL 8 Source: https://github.com/cri-o/cri-o/blob/main/install.md Installs the go-md2man tool using 'go get', which is required for CRI-O. ```shell go get github.com/cpuguy83/go-md2man ``` -------------------------------- ### Install godbus/dbus Source: https://github.com/cri-o/cri-o/blob/main/vendor/github.com/godbus/dbus/v5/README.md Install the dbus package using the go get command. Requires Go 1.20 or later. ```go go get github.com/godbus/dbus/v5 ``` -------------------------------- ### Go Git Tag Example Source: https://github.com/cri-o/cri-o/blob/main/vendor/github.com/go-git/go-git/v5/COMPATIBILITY.md Demonstrates how to list tags in a go-git repository. This example is located at _examples/tag/main.go. ```go package main import ( "fmt" "os" "github.com/go-git/go-git/v5" ) func main() { // Open the repository in the current directory repo, err := git.PlainOpen(".") if err != nil { panic(err) } // Get the tag iterator tags, err := repo.Tags() if err != nil { panic(err) } // Iterate over the tags and print their names err = tags.ForEach(func(tag *object.Tag) error { fmt.Println(tag.Name) return nil }) if err != nil { panic(err) } } ``` -------------------------------- ### Go Git Log Example Source: https://github.com/cri-o/cri-o/blob/main/vendor/github.com/go-git/go-git/v5/COMPATIBILITY.md Demonstrates how to retrieve commit logs from a go-git repository. This example is located at _examples/log/main.go. ```go package main import ( "fmt" "os" "github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5/plumbing/object" ) func main() { // Open the repository in the current directory repo, err := git.PlainOpen(".") if err != nil { panic(err) } // Get the commit log iterator commits, err := repo.Log(&git.LogOptions{}) if err != nil { panic(err) } // Iterate over the commits and print their hash and message err = commits.ForEach(func(commit *object.Commit) error { fmt.Printf("Hash: %s\n", commit.Hash.String()) fmt.Printf("Message: %s\n", commit.Message) return nil }) if err != nil { panic(err) } } ``` -------------------------------- ### Run Benchmarks for Displaywidth Comparison Source: https://github.com/cri-o/cri-o/blob/main/vendor/github.com/clipperhouse/displaywidth/README.md Navigate to the comparison directory and execute the Go tests to benchmark the displaywidth package against others. ```bash cd comparison go test -bench=. -benchmem ``` -------------------------------- ### Install go-openapi/swag Module Source: https://github.com/cri-o/cri-o/blob/main/vendor/github.com/go-openapi/swag/README.md Use this command to get the go-openapi/swag module for your project. ```bash go get github.com/go-openapi/swag/{module} ``` -------------------------------- ### Example using TagSet and TagOptions Source: https://github.com/cri-o/cri-o/blob/main/vendor/github.com/fxamacker/cbor/v2/README.md Shows how to create a TagSet, register custom tags with specific options, and use it to create decoding and encoding modes for handling tagged CBOR data. ```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 } ``` -------------------------------- ### Install json-patch v5 Source: https://github.com/cri-o/cri-o/blob/main/vendor/gopkg.in/evanphx/json-patch.v4/README.md Use this command to get the latest version of the json-patch library. ```bash go get -u github.com/evanphx/json-patch/v5 ``` -------------------------------- ### Reinstall go-sqlite3 using go install Source: https://github.com/cri-o/cri-o/blob/main/vendor/github.com/mattn/go-sqlite3/README.md If 'go get' fails with a 'gcc: internal compiler error', try removing the existing download repository and using 'go install' instead. ```bash go install github.com/mattn/go-sqlite3 ``` -------------------------------- ### Get Latest wazero Version Source: https://github.com/cri-o/cri-o/blob/main/vendor/github.com/tetratelabs/wazero/README.md Installs the latest version of wazero using the Go toolchain. ```bash go get github.com/tetratelabs/wazero@latest ``` -------------------------------- ### SpdyStream Client Example Source: https://github.com/cri-o/cri-o/blob/main/vendor/github.com/moby/spdystream/README.md Connects to a mirroring server and creates a stream to send and receive data. Ensure a server is running on localhost:8080. ```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() } ```