### Install goquery Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/PuerkitoBio/goquery/README.md Use go get to install the goquery library. Ensure you have Go 1.1+ installed. ```bash $ go get github.com/PuerkitoBio/goquery ``` -------------------------------- ### Install uilive Go Library Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/slimtoolkit/uilive/README.md Use the go get command to install the uilive library. This command fetches and installs the specified package. ```sh $ go get -v github.com/gosuri/uilive ``` -------------------------------- ### Install go-gitignore Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/monochromegane/go-gitignore/README.md Install the go-gitignore library using the go get command. Ensure you have Go installed and configured correctly. ```sh $ go get github.com/monochromegane/go-gitignore ``` -------------------------------- ### Install Diskv Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/peterbourgon/diskv/README.md Install the diskv package using the Go get command. Ensure Go 1 is installed. ```bash go get github.com/peterbourgon/diskv ``` -------------------------------- ### Install xmlquery Package Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/antchfx/xmlquery/README.md Use 'go get' to install the xmlquery package. ```bash $ go get github.com/antchfx/xmlquery ``` -------------------------------- ### Install Golang Color Library Source: https://github.com/slimtoolkit/slim/blob/master/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/slimtoolkit/slim/blob/master/vendor/github.com/mattn/go-isatty/README.md Use the go get command to install the go-isatty package. This command fetches and installs the package and its dependencies. ```bash go get github.com/mattn/go-isatty ``` -------------------------------- ### Install go-colorable Package Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/mattn/go-colorable/README.md Install the go-colorable package using the go get command. ```bash $ go get github.com/mattn/go-colorable ``` -------------------------------- ### Install and Import kubernetes-sigs/yaml Source: https://github.com/slimtoolkit/slim/blob/master/vendor/sigs.k8s.io/yaml/README.md Install the library using go get and import it into your Go project. ```bash $ go get sigs.k8s.io/yaml ``` ```go import "sigs.k8s.io/yaml" ``` -------------------------------- ### Install and Run Local Go Doc Site Source: https://github.com/slimtoolkit/slim/blob/master/vendor/go.opentelemetry.io/otel/CONTRIBUTING.md Installs and runs a local Go Doc site using pkgsite. Ensure you have Go installed. ```sh go install golang.org/x/pkgsite/cmd/pkgsite@latest pkgsite ``` -------------------------------- ### Install GoDotEnv as a Binary Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/ulyssessouza/godotenv/README.md Install the GoDotEnv command-line utility. Ensure your $GOPATH/bin is in your $PATH to use it. ```shell go get github.com/joho/godotenv/cmd/godotenv ``` -------------------------------- ### Install gobwas/glob Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/gobwas/glob/readme.md Use 'go get' to install the gobwas/glob library. ```shell go get github.com/gobwas/glob ``` -------------------------------- ### Installation and Import Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/bmatcuk/doublestar/v3/README.md Instructions on how to install the doublestar package and import it into your Go project. ```APIDOC ## Installation **doublestar** can be installed via `go get`: ```bash go get github.com/bmatcuk/doublestar/v2 ``` To use it in your code, you must import it: ```go import "github.com/bmatcuk/doublestar/v2" ``` ``` -------------------------------- ### Install dsnet/compress Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/dsnet/compress/README.md Run this command to install the library. Requires Go 1.9 or higher. ```bash go get -u github.com/dsnet/compress ``` -------------------------------- ### Install htmlquery Package Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/antchfx/htmlquery/README.md Use 'go get' to install the htmlquery package. This is the standard way to add Go packages to your project. ```go go get github.com/antchfx/htmlquery ``` -------------------------------- ### Install Doublestar Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/bmatcuk/doublestar/README.md Install the doublestar package using go get. This command fetches and installs the package and its dependencies. ```bash go get github.com/bmatcuk/doublestar ``` -------------------------------- ### Install Mergo Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/imdario/mergo/README.md Use 'go get' to install the Mergo library. This command fetches and installs the package and its dependencies. ```bash go get github.com/imdario/mergo ``` -------------------------------- ### Install go-tty Package Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/mattn/go-tty/README.md Installs the go-tty package using the go get command. ```bash $ go get github.com/mattn/go-tty ``` -------------------------------- ### Full Cobra Application Example in Go Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/spf13/cobra/user_guide.md A complete example demonstrating how to set up a multi-command Cobra application with flags and nested commands. This includes defining commands for printing, echoing, and echoing multiple times. ```go package main import ( "fmt" "strings" "github.com/spf13/cobra" ) func main() { var echoTimes int var cmdPrint = &cobra.Command{ Use: "print [string to print]", Short: "Print anything to the screen", Long: `print is for printing anything back to the screen. For many years people have printed back to the screen.`, Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { fmt.Println("Print: " + strings.Join(args, " ")) }, } var cmdEcho = &cobra.Command{ Use: "echo [string to echo]", Short: "Echo anything to the screen", Long: `echo is for echoing anything back. Echo works a lot like print, except it has a child command.`, Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { fmt.Println("Echo: " + strings.Join(args, " ")) }, } var cmdTimes = &cobra.Command{ Use: "times [string to echo]", Short: "Echo anything to the screen more times", Long: `echo things multiple times back to the user by providing a count and a string.`, Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { for i := 0; i < echoTimes; i++ { fmt.Println("Echo: " + strings.Join(args, " ")) } }, } cmdTimes.Flags().IntVarP(&echoTimes, "times", "t", 1, "times to echo the input") var rootCmd = &cobra.Command{Use: "app"} rootCmd.AddCommand(cmdPrint, cmdEcho) cmdEcho.AddCommand(cmdTimes) rootCmd.Execute() } ``` -------------------------------- ### Quick Seccomp Example Source: https://github.com/slimtoolkit/slim/blob/master/README.md Provides a concise example of using seccomp profiles with Slim. This snippet is useful for quickly understanding how to apply seccomp to container security. ```bash docker run --rm -it --security-opt seccomp=unconfined alpine sh ``` -------------------------------- ### Install pgzip Package Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/klauspost/pgzip/README.md Use 'go get' to install the pgzip package. You may need to update its dependencies. ```go go get github.com/klauspost/pgzip/... ``` ```go go get -u github.com/klauspost/compress ``` -------------------------------- ### Install KSUID Command Line Tool Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/segmentio/ksuid/README.md Install the ksuid command-line tool using Go's install command. Ensure you have a Go build environment set up. ```sh $ go install github.com/segmentio/ksuid/cmd/ksuid ``` -------------------------------- ### Verify Examples Build Source: https://github.com/slimtoolkit/slim/blob/master/vendor/go.opentelemetry.io/otel/RELEASING.md Execute this script after releasing to ensure that examples build correctly outside the repository, confirming they work with the published release. ```sh ./verify_examples.sh ``` -------------------------------- ### Install mapstructure Go Library Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/mitchellh/mapstructure/README.md Use `go get` to install the mapstructure library. This command fetches and installs the library and its dependencies. ```bash $ go get github.com/mitchellh/mapstructure ``` -------------------------------- ### Define a RESTful WebService Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/emicklei/go-restful/v3/README.md Example of creating a new WebService, defining its path, supported content types, and routes. This snippet demonstrates setting up a GET route for retrieving a user by ID. ```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") ... } ``` -------------------------------- ### Clone Examples Repository Source: https://github.com/slimtoolkit/slim/blob/master/README.md Clone the examples repository to use sample applications. This step can be skipped if you have your own application. ```bash git clone https://github.com/slimtoolkit/examples.git ``` -------------------------------- ### Install Cobra Library Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/spf13/cobra/README.md Use 'go get' to install the latest version of the Cobra library. This command fetches and installs the library, making it available for use in your Go projects. ```go go get -u github.com/spf13/cobra@latest ``` -------------------------------- ### Install Doublestar Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/bmatcuk/doublestar/v3/README.md Install the doublestar package using go get. This command fetches and installs the latest version of the package. ```bash go get github.com/bmatcuk/doublestar/v2 ``` -------------------------------- ### Install treeprint Package Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/xlab/treeprint/README.md Use 'go get' to install the treeprint package. This command fetches and installs the package and its dependencies. ```bash go get github.com/xlab/treeprint ``` -------------------------------- ### Installation Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/bmatcuk/doublestar/README.md Instructions on how to install and import the doublestar package. ```APIDOC ## Installation **doublestar** can be installed via `go get`: ```bash go get github.com/bmatcuk/doublestar ``` To use it in your code, you must import it: ```go import "github.com/bmatcuk/doublestar" ``` ``` -------------------------------- ### Install json-iterator/go Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/json-iterator/go/README.md Install the json-iterator/go package using the go get command. ```go go get github.com/json-iterator/go ``` -------------------------------- ### Install blackfriday-tool Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/russross/blackfriday/v2/README.md Install the blackfriday-tool command-line utility. This tool provides a standalone way to process markdown files and also installs the blackfriday library. ```bash go get github.com/russross/blackfriday-tool ``` -------------------------------- ### Install uiprogress Go Package Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/slimtoolkit/uiprogress/README.md Command to install the uiprogress Go package using the go get command. It includes verbose output. ```sh $ go get -v github.com/docker-slim/uiprogress ``` -------------------------------- ### Install and Import YAML Package in Go Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/ghodss/yaml/README.md Instructions for installing the go-yaml wrapper package and importing it into your Go project. ```bash go get github.com/ghodss/yaml ``` ```go import "github.com/ghodss/yaml" ``` -------------------------------- ### Install ksuid Go Library Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/segmentio/ksuid/README.md Use this command to install the ksuid Go library. Ensure you are using Go modules. ```sh go get -u github.com/segmentio/ksuid ``` -------------------------------- ### Install Slim Toolkit with Script Source: https://context7.com/slimtoolkit/slim/llms.txt Installs Slim Toolkit using a script for Linux and macOS. Ensure you have curl installed. ```bash curl -sL https://raw.githubusercontent.com/slimtoolkit/slim/master/scripts/install-slim.sh | sudo -E bash - ``` -------------------------------- ### Build Slim Natively (Linux) Source: https://github.com/slimtoolkit/slim/blob/master/README.md Use this command to build Slim natively on Linux. This requires Go to be installed locally. ```bash make build ``` -------------------------------- ### Install Additional Tools Source: https://github.com/slimtoolkit/slim/blob/master/README.md Use this script to install optional tools like license-bill-of-materials and golint. Ensure you have the necessary permissions. ```bash ./scripts/tools.get.sh ``` -------------------------------- ### Build Slim Natively (Mac) Source: https://github.com/slimtoolkit/slim/blob/master/README.md Use this command to build Slim natively on Macs. This requires Go to be installed locally. ```bash make build_m1 ``` -------------------------------- ### Install Marshmallow Go Package Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/perimeterx/marshmallow/README.md Use 'go get' to install the Marshmallow package. Ensure you are using the '-u' flag to get the latest version. ```sh go get -u github.com/perimeterx/marshmallow ``` -------------------------------- ### Basic Diskv Usage Example Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/peterbourgon/diskv/README.md Demonstrates the simplest way to use diskv: initializing a store, writing a key-value pair, reading it back, and then erasing it. Uses a flat transform function and specifies a cache size. ```go package main import ( "fmt" "github.com/peterbourgon/diskv" ) func main() { // Simplest transform function: put all the data files into the base dir. flatTransform := func(s string) []string { return []string{} } // Initialize a new diskv store, rooted at "my-data-dir", with a 1MB cache. d := diskv.New(diskv.Options{ BasePath: "my-data-dir", Transform: flatTransform, CacheSizeMax: 1024 * 1024, }) // Write three bytes to the key "alpha". key := "alpha" d.Write(key, []byte{'1', '2', '3'}) // Read the value back out of the store. value, _ := d.Read(key) fmt.Printf("%v\n", value) // Erase the key+value from the store (and the disk). d.Erase(key) } ``` -------------------------------- ### Example .env File with Comments and Exports Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/ulyssessouza/godotenv/README.md Demonstrates a valid .env file format including comments and export directives. ```shell # I am a comment and that is OK SOME_VAR=someval FOO=BAR # comments at line end are OK too export BAR=BAZ ``` -------------------------------- ### Install GoDotEnv as a Library Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/ulyssessouza/godotenv/README.md Use this command to add the GoDotEnv library to your project dependencies. ```shell go get github.com/joho/godotenv ``` -------------------------------- ### Install aec Go Package Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/morikuni/aec/README.md Use 'go get' to install the aec package. This command fetches and installs the package and its dependencies. ```bash go get github.com/morikuni/aec ``` -------------------------------- ### Basic Interactive Prompt with Auto-completion in Go Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/c-bata/go-prompt/README.md This example demonstrates how to set up a basic interactive prompt using go-prompt. It includes a completer function that provides suggestions based on user input, enabling auto-completion for commands or options. Ensure the 'github.com/c-bata/go-prompt' package is imported. ```go package main import ( "fmt" "github.com/c-bata/go-prompt" ) func completer(d prompt.Document) []prompt.Suggest { s := []prompt.Suggest{ {Text: "users", Description: "Store the username and age"}, {Text: "articles", Description: "Store the article text posted by user"}, {Text: "comments", Description: "Store the text commented to articles"}, } return prompt.FilterHasPrefix(s, d.GetWordBeforeCursor(), true) } func main() { fmt.Println("Please select table.") t := prompt.Input("> ", completer) fmt.Println("You selected " + t) } ``` -------------------------------- ### Install Stable jsonpatch Versions Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/evanphx/json-patch/README.md Install specific stable versions of the jsonpatch library using these go get commands. ```bash go get -u gopkg.in/evanphx/json-patch.v5 ``` ```bash go get -u gopkg.in/evanphx/json-patch.v4 ``` -------------------------------- ### Show Command Help Function Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/urfave/cli/v2/godoc-current.txt Prints help information for the specified command. ```go func ShowCommandHelp(ctx *Context, command string) error ShowCommandHelp prints help for the given command ``` -------------------------------- ### Instantiation with Functional Options Source: https://github.com/slimtoolkit/slim/blob/master/vendor/go.opentelemetry.io/otel/CONTRIBUTING.md Demonstrates how to instantiate a type using a variadic functional options parameter. This allows for flexible initialization. ```go func NewT(options ...Option) T {…} ``` -------------------------------- ### Get Container Image Information Source: https://github.com/slimtoolkit/slim/blob/master/README.md The 'images' command retrieves information about container images. For example, 'slim --quiet images' can be used to get this information. ```bash images ``` ```bash slim --quiet images ``` -------------------------------- ### List Docker Images Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/fsouza/go-dockerclient/README.md Instantiate a client from environment variables and list all Docker images. Ensure the Docker daemon is accessible via environment variables. ```go package main import ( "fmt" docker "github.com/fsouza/go-dockerclient" ) func main() { client, err := docker.NewClientFromEnv() if err != nil { panic(err) } imgs, err := client.ListImages(docker.ListImagesOptions{All: false}) if err != nil { panic(err) } for _, img := range imgs { fmt.Println("ID: ", img.ID) fmt.Println("RepoTags: ", img.RepoTags) fmt.Println("Created: ", img.Created) fmt.Println("Size: ", img.Size) fmt.Println("VirtualSize: ", img.VirtualSize) fmt.Println("ParentId: ", img.ParentID) } } ``` -------------------------------- ### Install uniseg Package Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/rivo/uniseg/README.md Use this command to get the package. It has no external dependencies. ```bash go get github.com/rivo/uniseg ``` -------------------------------- ### List Tags for a Repository in Go Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/google/go-containerregistry/pkg/v1/remote/transport/README.md This example demonstrates how to list tags for a specific repository (e.g., gcr.io/google-containers/pause) and write the output to stdout. It utilizes authentication from the default Docker config and constructs an authorized HTTP client. ```go package main import ( "io" "net/http" "os" "github.com/google/go-containerregistry/pkg/authn" "github.com/google/go-containerregistry/pkg/name" "github.com/google/go-containerregistry/pkg/v1/remote/transport" ) func main() { repo, err := name.NewRepository("gcr.io/google-containers/pause") if err != nil { panic(err) } // Fetch credentials based on your docker config file, which is $HOME/.docker/config.json or $DOCKER_CONFIG. auth, err := authn.DefaultKeychain.Resolve(repo.Registry) if err != nil { panic(err) } // Construct an http.Client that is authorized to pull from gcr.io/google-containers/pause. scopes := []string{repo.Scope(transport.PullScope)} t, err := transport.New(repo.Registry, auth, http.DefaultTransport, scopes) if err != nil { panic(err) } client := &http.Client{Transport: t} // Make the actual request. resp, err := client.Get("https://gcr.io/v2/google-containers/pause/tags/list") if err != nil { panic(err) } // Assert that we get a 200, otherwise attempt to parse body as a structured error. if err := transport.CheckError(resp, http.StatusOK); err != nil { panic(err) } // Write the response to stdout. if _, err := io.Copy(os.Stdout, resp.Body); err != nil { panic(err) } } ``` -------------------------------- ### Install Latest jsonpatch Version Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/evanphx/json-patch/README.md Use this command to get the latest version of the jsonpatch library for Go. ```bash go get -u github.com/evanphx/json-patch/v5 ``` -------------------------------- ### CLI for Applying JSON Patches Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/evanphx/json-patch/README.md The `json-patch` CLI tool allows applying multiple JSON patch files to a JSON document provided via stdin. Install using `go install`. Example usage provided. ```json [ {"op": "replace", "path": "/name", "value": "Jane"}, {"op": "remove", "path": "/height"} ] ``` ```json [ {"op": "add", "path": "/address", "value": "123 Main St"}, {"op": "replace", "path": "/age", "value": "21"} ] ``` ```json { "name": "John", "age": 24, "height": 3.21 } ``` ```bash $ go install github.com/evanphx/json-patch/cmd/json-patch $ cat document.json | json-patch -p patch.1.json -p patch.2.json ``` -------------------------------- ### Show Help Information Source: https://github.com/slimtoolkit/slim/blob/master/README.md The 'help' command displays available commands and global flags for the Slim tool. ```bash help ``` -------------------------------- ### Get/Set Interface{} Value with reflect2 Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/modern-go/reflect2/README.md This example demonstrates how to get and set values of an interface{} type using reflect2. To modify the value, always provide a pointer to the type. ```go valType := reflect2.TypeOf(1) i := 1 j := 10 valType.Set(&i, &j) // i will be 10 ``` -------------------------------- ### Install Docker on Ubuntu Source: https://github.com/slimtoolkit/slim/blob/master/README.md Installs the Docker engine on your Ubuntu virtual machine. Ensure Docker is running after installation. ```bash sudo apt install docker -y ``` ```bash sudo systemctl start docker ``` ```bash sudo usermod -aG docker ec2-user ``` -------------------------------- ### Initialize Gitignore Matcher Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/monochromegane/go-gitignore/README.md Create a new Gitignore matcher by providing the path to the .gitignore file. This is the primary way to start using the library. ```go gitignore, _ := gitignore.NewGitIgnore("/path/to/gitignore") path := "/path/to/file" isDir := false gitignore.Match(path, isDir) ``` -------------------------------- ### Create and Use Radix Tree in Go Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/armon/go-radix/README.md Demonstrates basic usage of the radix tree, including insertion of key-value pairs and finding the longest prefix match. Ensure the radix package is imported. ```go // Create a tree r := radix.New() r.Insert("foo", 1) r.Insert("bar", 2) r.Insert("foobar", 2) // Find the longest prefix match m, _, _ := r.LongestPrefix("foozip") if m != "foo" { panic("should be foo") } ``` -------------------------------- ### SpdyStream Server Example Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/moby/spdystream/README.md Listens for incoming TCP connections on localhost:8080, accepts them, and serves streams using the MirrorStreamHandler. This acts as a basic mirroring server. ```go package main import ( "github.com/moby/spdystream" "net" ) func main() { listener, err := net.Listen("tcp", "localhost:8080") if err != nil { panic(err) } for { conn, err := listener.Accept() if err != nil { panic(err) } spdyConn, err := spdystream.NewConnection(conn, true) if err != nil { panic(err) } go spdyConn.Serve(spdystream.MirrorStreamHandler) } } ``` -------------------------------- ### Coexist with klog/v1 and klog/v2 Source: https://github.com/slimtoolkit/slim/blob/master/vendor/k8s.io/klog/v2/README.md Example demonstrating how to use both klog/v1 and klog/v2 within the same project. This is useful during migration or when dependencies use different versions. ```go // See examples/coexist_klog_v1_and_v2/ ``` -------------------------------- ### Run Benchmarks for goquery Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/PuerkitoBio/goquery/README.md Navigate to the goquery source directory and run go test with the -bench flag to execute benchmarks. This may take a few minutes. ```bash cd $GOPATH/src/github.com/PuerkitoBio/goquery go test -bench=".*" ``` -------------------------------- ### Manual Download and Install Slim Toolkit Source: https://context7.com/slimtoolkit/slim/llms.txt Manually downloads, extracts, and installs Slim Toolkit on Linux systems. Ensure you have curl and tar installed. ```bash curl -L -o ds.tar.gz https://github.com/slimtoolkit/slim/releases/download/1.40.11/dist_linux.tar.gz tar -xvf ds.tar.gz mv dist_linux/slim /usr/local/bin/ mv dist_linux/slim-sensor /usr/local/bin/ ``` -------------------------------- ### Install Git on macOS Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/c4milo/unpackit/CONTRIBUTING.md Use this command to install Git on macOS using Homebrew. ```bash brew install git ``` -------------------------------- ### Update Slim Toolkit Installation Source: https://context7.com/slimtoolkit/slim/llms.txt Updates an existing Slim Toolkit installation to the latest version. ```bash slim update ``` -------------------------------- ### Configured CLI Application Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/urfave/cli/v2/godoc-current.txt An example of a more functional CLI application with a name, usage string, and a simple action. The Action is executed when the application is run without subcommands. ```go func main() { app := &cli.App{ Name: "greet", Usage: "say a greeting", Action: func(c *cli.Context) error { fmt.Println("Greetings") return nil }, } app.Run(os.Args) } ``` -------------------------------- ### Install Git on Debian-based systems Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/c4milo/unpackit/CONTRIBUTING.md Use this command to install Git on Debian-based Linux distributions. ```bash apt-get install git-core ``` -------------------------------- ### SpdyStream Client Example Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/moby/spdystream/README.md Connects to a mirroring server without authentication, creates a stream, writes data, reads data, and closes the stream. Requires a running spdy server 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() } ``` -------------------------------- ### Get the unpackit package Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/c4milo/unpackit/CONTRIBUTING.md Use 'go get' to download the unpackit package. This is a prerequisite for contributing to the project. ```bash go get github.com/c4milo/unpackit ``` -------------------------------- ### Run Native Build Script (Linux) Source: https://github.com/slimtoolkit/slim/blob/master/README.md Execute this script to build Slim natively on Linux. It's an alternative to using the make command and requires Go to be installed. ```bash ./scripts/src.build.sh ``` -------------------------------- ### JSON Log Output Example Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/sirupsen/logrus/README.md Example of a log entry with caller information included, formatted as JSON. ```json {"animal":"penguin","level":"fatal","method":"github.com/sirupsen/arcticcreatures.migrate","msg":"a penguin swims by", "time":"2014-03-10 19:57:38.562543129 -0400 EDT"} ``` -------------------------------- ### Install YAML Package Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/imdario/mergo/README.md If tests fail due to a missing YAML package, run this command to install 'gopkg.in/yaml.v3'. ```bash go get gopkg.in/yaml.v3 ``` -------------------------------- ### Apply Kubernetes Manifest Source: https://github.com/slimtoolkit/slim/blob/master/README.md Apply the example Kubernetes manifest to set up a minimal Nginx pod for debugging. Ensure your target environment is running. ```bash kubectl apply -f examples/k8s_nginx_cgr/manifest.yaml ``` -------------------------------- ### Cobra Command Hooks Example Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/spf13/cobra/user_guide.md Demonstrates the usage of PersistentPreRun, PreRun, Run, PostRun, and PersistentPostRun hooks in root and subcommands. Shows how hooks are executed in a hierarchical manner. ```go package main import ( "fmt" "github.com/spf13/cobra" ) func main() { var rootCmd = &cobra.Command{ Use: "root [sub]", Short: "My root command", PersistentPreRun: func(cmd *cobra.Command, args []string) { fmt.Printf("Inside rootCmd PersistentPreRun with args: %v\n", args) }, PreRun: func(cmd *cobra.Command, args []string) { fmt.Printf("Inside rootCmd PreRun with args: %v\n", args) }, Run: func(cmd *cobra.Command, args []string) { fmt.Printf("Inside rootCmd Run with args: %v\n", args) }, PostRun: func(cmd *cobra.Command, args []string) { fmt.Printf("Inside rootCmd PostRun with args: %v\n", args) }, PersistentPostRun: func(cmd *cobra.Command, args []string) { fmt.Printf("Inside rootCmd PersistentPostRun with args: %v\n", args) }, } var subCmd = &cobra.Command{ Use: "sub [no options!]", Short: "My subcommand", PreRun: func(cmd *cobra.Command, args []string) { fmt.Printf("Inside subCmd PreRun with args: %v\n", args) }, Run: func(cmd *cobra.Command, args []string) { fmt.Printf("Inside subCmd Run with args: %v\n", args) }, PostRun: func(cmd *cobra.Command, args []string) { fmt.Printf("Inside subCmd PostRun with args: %v\n", args) }, PersistentPostRun: func(cmd *cobra.Command, args []string) { fmt.Printf("Inside subCmd PersistentPostRun with args: %v\n", args) }, } rootCmd.AddCommand(subCmd) rootCmd.SetArgs([]string{}) rootCmd.Execute() fmt.Println() rootCmd.SetArgs([]string{"sub", "arg1", "arg2"}) rootCmd.Execute() } ``` -------------------------------- ### Install Slim Toolkit with Homebrew Source: https://context7.com/slimtoolkit/slim/llms.txt Installs Slim Toolkit on macOS and Linux using the Homebrew package manager. ```bash brew install docker-slim ``` -------------------------------- ### Text Log Output Example Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/sirupsen/logrus/README.md Example of a log entry with caller information included, formatted as plain text. ```text time="2015-03-26T01:27:38-04:00" level=fatal method=github.com/sirupsen/arcticcreatures.migrate msg="a penguin swims by" animal=penguin ``` -------------------------------- ### Minification Examples for Go Source: https://github.com/slimtoolkit/slim/blob/master/README.md Details the significant size reduction for Go application images, highlighting the effectiveness of Slim in minimizing large Go binaries. ```text from golang:latest - 700MB => 1.56MB (minified by **448.76X**) from ubuntu:14.04 - 531MB => 1.87MB (minified by **284.10X**) from golang:alpine - 258MB => 1.56MB (minified by **165.61X**) from centos:7 - 615MB => 1.87MB (minified by **329.14X**) ``` -------------------------------- ### Float64Flag Get Method Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/urfave/cli/v2/godoc-current.txt Get returns the flag’s value in the given Context. This method is part of the Float64Flag struct. ```go func (f *Float64Flag) Get(ctx *Context) float64 ``` -------------------------------- ### Show App Help and Exit Function Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/urfave/cli/v2/godoc-current.txt Prints the list of subcommands for the app and exits with a specified code. ```go func ShowAppHelpAndExit(c *Context, exitCode int) ShowAppHelpAndExit - Prints the list of subcommands for the app and exits with exit code. ``` -------------------------------- ### Get opentelemetry-go Package Source: https://github.com/slimtoolkit/slim/blob/master/vendor/go.opentelemetry.io/otel/CONTRIBUTING.md Use `go get` to download the opentelemetry-go package. This command may produce warnings that can be ignored. ```go go get -d go.opentelemetry.io/otel ``` -------------------------------- ### Show Version Function Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/urfave/cli/v2/godoc-current.txt Prints the version number of the application. ```go func ShowVersion(cCtx *Context) ShowVersion prints the version number of the App ``` -------------------------------- ### Basic Glob Matching in Go Source: https://github.com/slimtoolkit/slim/blob/master/vendor/github.com/gobwas/glob/readme.md Demonstrates creating and matching simple glob patterns. Ensure the pattern is valid before compilation. ```go package main import "github.com/gobwas/glob" func main() { var g glob.Glob // create simple glob g = glob.MustCompile("*.github.com") g.Match("api.github.com") // true // quote meta characters and then create simple glob g = glob.MustCompile(glob.QuoteMeta("*.github.com")) g.Match("*.github.com") // true // create new glob with set of delimiters as [". ```