### Basic Gin Web Server Example Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/gin-gonic/gin/README.md A simple 'Hello World' example demonstrating how to create a Gin router, define a GET route for '/ping', and start the server. The server listens on 0.0.0.0:8080 by default. ```go package main import ( "net/http" "github.com/gin-gonic/gin" ) func main() { r := gin.Default() r.GET("/ping", func(c *gin.Context) { c.JSON(http.StatusOK, gin.H{ "message": "pong", }) }) r.Run() // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080") } ``` -------------------------------- ### Install Objx Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/stretchr/objx/README.md Install the Objx package using the `go get` command. ```bash go get github.com/stretchr/objx ``` -------------------------------- ### Install the library Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/samber/lo/README.md Use the go get command to add the library to your project. ```sh go get github.com/samber/lo@v1 ``` -------------------------------- ### Install goccy/go-json Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/goccy/go-json/README.md Use go get to install the library. This command fetches and installs the package, making it available for use in your Go projects. ```go go get github.com/goccy/go-json ``` -------------------------------- ### Install color library Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/fatih/color/README.md Command to install the package via go get. ```bash go get github.com/fatih/color ``` -------------------------------- ### Install go-colorable Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/mattn/go-colorable/README.md Use the go get command to add the package to your project. ```bash $ go get github.com/mattn/go-colorable ``` -------------------------------- ### Install treeprint Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/xlab/treeprint/README.md Use the go get command to install the package. ```bash $ go get github.com/xlab/treeprint ``` -------------------------------- ### Install Ethtool Go Package Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/safchain/ethtool/README.md Use 'go get' to install the ethtool package. This is the initial step before importing it into your Go projects. ```shell go get github.com/safchain/ethtool ``` -------------------------------- ### Install go-urn Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/leodido/go-urn/README.md Use the go get command to add the library to your project. ```bash go get github.com/leodido/go-urn ``` -------------------------------- ### Install and Test Go OLE Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/go-ole/go-ole/README.md Instructions for installing the go-ole library, running tests, and executing an example program for Excel integration. Ensure you are in the correct directory before running commands. ```bash 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 blackfriday-tool Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/russross/blackfriday/v2/README.md Install the blackfriday-tool command-line utility using 'go get'. This tool provides a standalone way to process Markdown files. ```go go get github.com/russross/blackfriday-tool ``` -------------------------------- ### Full Example: Get Info, Index Documents, and Search Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/elastic/go-elasticsearch/v7/README.md Demonstrates a comprehensive usage scenario including fetching cluster info, indexing documents concurrently, and processing search results. Ensure response bodies are closed and consumed. ```golang // $ go run _examples/main.go package main import ( "bytes" "context" "encoding/json" "log" "strconv" "strings" "sync" "bytes" "github.com/elastic/go-elasticsearch/v7" "github.com/elastic/go-elasticsearch/v7/esapi" ) func main() { log.SetFlags(0) var ( r map[string]interface{} wg sync.WaitGroup ) // Initialize a client with the default settings. // // An `ELASTICSEARCH_URL` environment variable will be used when exported. // es, err := elasticsearch.NewDefaultClient() if err != nil { log.Fatalf("Error creating the client: %s", err) } // 1. Get cluster info // res, err := es.Info() if err != nil { log.Fatalf("Error getting response: %s", err) } defer res.Body.Close() // Check response status if res.IsError() { log.Fatalf("Error: %s", res.String()) } // Deserialize the response into a map. if err := json.NewDecoder(res.Body).Decode(&r); err != nil { log.Fatalf("Error parsing the response body: %s", err) } // Print client and server version numbers. log.Printf("Client: %s", elasticsearch.Version) log.Printf("Server: %s", r["version"].(map[string]interface{})["number"]) log.Println(strings.Repeat("~", 37)) // 2. Index documents concurrently // for i, title := range []string{"Test One", "Test Two"} { wg.Add(1) go func(i int, title string) { defer wg.Done() // Build the request body. data, err := json.Marshal(struct{ Title string }{Title: title}) if err != nil { log.Fatalf("Error marshaling document: %s", err) } // Set up the request object. req := esapi.IndexRequest{ Index: "test", DocumentID: strconv.Itoa(i + 1), Body: bytes.NewReader(data), Refresh: "true", } // Perform the request with the client. res, err := req.Do(context.Background(), es) if err != nil { log.Fatalf("Error getting response: %s", err) } defer res.Body.Close() if res.IsError() { log.Printf("[%s] Error indexing document ID=%d", res.Status(), i+1) } else { // Deserialize the response into a map. var r map[string]interface{} ``` -------------------------------- ### Install Tablewriter Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/olekukonko/tablewriter/README.md Install the tablewriter package using the go get command. ```bash go get github.com/olekukonko/tablewriter ``` -------------------------------- ### Install the YAML package Source: https://github.com/ccfos/huatuo/blob/main/vendor/gopkg.in/yaml.v2/README.md Use the go get command to install the package into your Go environment. ```bash go get gopkg.in/yaml.v2 ``` -------------------------------- ### Full Mux Server Example in Go Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/gorilla/mux/README.md A complete, runnable example of a basic Mux-based web server in Go, demonstrating route registration and server startup. ```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 json-iterator/go Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/json-iterator/go/README.md Command to install the package via go get. ```bash go get github.com/json-iterator/go ``` -------------------------------- ### Install Dependencies and Run Tests Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/uber/jaeger-client-go/CONTRIBUTING.md Install project dependencies using 'make install' and run tests with 'make test'. ```bash make install make test ``` -------------------------------- ### Install Multierr Source: https://github.com/ccfos/huatuo/blob/main/vendor/go.uber.org/multierr/README.md Use 'go get' to install the latest version of the multierr package. ```bash go get -u go.uber.org/multierr@latest ``` -------------------------------- ### Install uniseg package Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/rivo/uniseg/README.md Use the go get command to add the package to your project. ```bash go get github.com/rivo/uniseg ``` -------------------------------- ### Install gorilla/mux Source: https://github.com/ccfos/huatuo/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 ``` -------------------------------- ### Install the YAML package Source: https://github.com/ccfos/huatuo/blob/main/vendor/gopkg.in/yaml.v3/README.md Use the go get command to add the package to your project. ```bash go get gopkg.in/yaml.v3 ``` -------------------------------- ### Install and use tomll Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/pelletier/go-toml/README.md Install the linting tool and display help information. ```bash go install github.com/pelletier/go-toml/cmd/tomll tomll --help ``` -------------------------------- ### Install mimetype package Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/gabriel-vasile/mimetype/README.md Use the go get command to add the package to your project. ```bash go get github.com/gabriel-vasile/mimetype ``` -------------------------------- ### Install etcd/clientv3 Source: https://github.com/ccfos/huatuo/blob/main/vendor/go.etcd.io/etcd/client/v3/README.md Commands to install the etcd client library using Go modules. ```bash go get go.etcd.io/etcd/client/v3 ``` ```bash go get go.etcd.io/etcd/client/v3@v3.5.0-pre ``` -------------------------------- ### Install Universal Translator Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/go-playground/universal-translator/README.md Use 'go get' to install the Universal Translator library. This is the standard method for adding Go packages to your project. ```shell go get github.com/go-playground/universal-translator ``` -------------------------------- ### Install Go Locales Library Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/go-playground/locales/README.md Use 'go get' to install the locales library. This command fetches and installs the specified package and its dependencies. ```shell go get github.com/go-playground/locales ``` -------------------------------- ### Install mapstructure Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/mitchellh/mapstructure/README.md Use the standard go get command to add the library to your project. ```bash $ go get github.com/mitchellh/mapstructure ``` -------------------------------- ### Install and Import pprof Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/gin-contrib/pprof/README.md Commands to install the package and import it into a Go project. ```bash go get github.com/gin-contrib/pprof ``` ```go import "github.com/gin-contrib/pprof" ``` -------------------------------- ### Consul KV Client Implementation Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/hashicorp/consul/api/README.md Example demonstrating how to create a Consul client and perform basic PUT and GET operations on the KV store. ```go package main import ( "fmt" capi "github.com/hashicorp/consul/api" ) func main() { // Get a new client client, err := capi.NewClient(capi.DefaultConfig()) if err != nil { panic(err) } // Get a handle to the KV API kv := client.KV() // PUT a new KV pair p := &capi.KVPair{Key: "REDIS_MAXCLIENTS", Value: []byte("1000")} _, err = kv.Put(p, nil) if err != nil { panic(err) } // Lookup the pair pair, _, err := kv.Get("REDIS_MAXCLIENTS", nil) if err != nil { panic(err) } fmt.Printf("KV: %v %s\n", pair.Key, pair.Value) } ``` -------------------------------- ### Install and Run Local Go Doc Site Source: https://github.com/ccfos/huatuo/blob/main/vendor/go.opentelemetry.io/otel/CONTRIBUTING.md Installs the pkgsite tool and runs a local Go Doc site. This is useful for previewing package documentation. ```sh go install golang.org/x/pkgsite/cmd/pkgsite@latest pkgsite ``` -------------------------------- ### Install go-sockaddr CLI Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/hashicorp/go-sockaddr/README.md Installs the go-sockaddr command-line utility using go install. This tool exposes much of the library's functionality. ```text $ go install github.com/hashicorp/go-sockaddr/cmd/sockaddr@latest ``` -------------------------------- ### Install Gin Package Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/gin-gonic/gin/README.md If not using Go modules, you can install the Gin package globally using the 'go get' command. ```sh $ go get -u github.com/gin-gonic/gin ``` -------------------------------- ### Install godbus/dbus Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/godbus/dbus/v5/README.md Use the go get command to add the library to your project. Requires Go 1.12 or later. ```bash go get github.com/godbus/dbus/v5 ``` -------------------------------- ### Install Blackfriday v2 Package Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/russross/blackfriday/v2/README.md Use 'go get' to install the v2 version of the Blackfriday package. This command adds the package to your module and builds it. ```go go get github.com/russross/blackfriday/v2 ``` -------------------------------- ### Install go-toml module Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/pelletier/go-toml/v2/README.md Command to install the library for Go versions 1.13 and above. ```bash GO111MODULE=on go get github.com/pelletier/go-toml/v2 ``` -------------------------------- ### Run Consul Client Example Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/hashicorp/consul/api/README.md Command to execute the Go application. ```shell go run . ``` -------------------------------- ### Check Go Installation Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/hashicorp/memberlist/README.md Verify that Go version 1.2 or higher is installed on your system. ```bash go version ``` -------------------------------- ### Install and use tomll Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/pelletier/go-toml/v2/README.md Installation and help command for the tomll utility. ```bash $ go install github.com/pelletier/go-toml/v2/cmd/tomll@latest $ tomll --help ``` -------------------------------- ### Install and use jsontoml Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/pelletier/go-toml/README.md Install the JSON to TOML conversion tool and display help information. ```bash go install github.com/pelletier/go-toml/cmd/jsontoml jsontoml --help ``` -------------------------------- ### Run Gin Example Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/gin-gonic/gin/README.md Command to execute a Go file containing a Gin web server example. After running, you can access the defined routes via a web browser or tool like curl. ```sh # run example.go and visit 0.0.0.0:8080/ping on browser $ go run example.go ``` -------------------------------- ### Install go-isatty Package Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/mattn/go-isatty/README.md Run this command in your terminal to install the go-isatty package using the Go build tool. ```bash go get github.com/mattn/go-isatty ``` -------------------------------- ### Install and use tomljson Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/pelletier/go-toml/README.md Install the TOML to JSON conversion tool and display help information. ```bash go install github.com/pelletier/go-toml/cmd/tomljson tomljson --help ``` -------------------------------- ### Install lz4 package Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/pierrec/lz4/v4/README.md Use the go toolchain to fetch the lz4 package. ```bash go get github.com/pierrec/lz4/v4 ``` -------------------------------- ### Install Jaeger Client Go via go get Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/uber/jaeger-client-go/README.md Install the latest version of the Jaeger client Go library using go get. Note that this may lead to build errors due to incompatible dependencies. Running 'make install' after 'go get' can help resolve these issues. ```shell go get -u github.com/uber/jaeger-client-go/ cd $GOPATH/src/github.com/uber/jaeger-client-go/ git submodule update --init --recursive make install ``` -------------------------------- ### Basic Elasticsearch Client Initialization and Info Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/elastic/go-elasticsearch/v7/README.md A complete example demonstrating how to set up a Go project with the go-elasticsearch client, initialize a default client, and log the client version and cluster info. Ensure you have a running Elasticsearch instance. ```bash mkdir my-elasticsearch-app && cd my-elasticsearch-app cat > go.mod <<-"END" module my-elasticsearch-app require github.com/elastic/go-elasticsearch/v8 main END cat > main.go <<-"END" package main import ( "log" "github.com/elastic/go-elasticsearch/v7" ) func main() { es, _ := elasticsearch.NewDefaultClient() log.Println(elasticsearch.Version) log.Println(es.Info()) } END go run main.go ``` -------------------------------- ### Clone and Setup Repository Source: https://github.com/ccfos/huatuo/blob/main/vendor/go.uber.org/zap/CONTRIBUTING.md Initializes the local development environment by cloning the repository and configuring the upstream remote. ```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 ``` -------------------------------- ### RPC Client Codec Setup Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/ugorji/go/codec/README.md Demonstrates setting up an RPC client codec for communication. It shows how to establish a network connection and create a client codec, compatible with both Go RPC and MsgpackSpec RPC. ```go //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 uuid Package Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/google/uuid/README.md Use 'go get' to install the uuid package. This command fetches and installs the package and its dependencies. ```sh go get github.com/google/uuid ``` -------------------------------- ### Install Validator Package Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/go-playground/validator/v10/README.md Command to install the validator package via go get. ```bash go get github.com/go-playground/validator/v10 ``` -------------------------------- ### Install Uber Atomic Package Source: https://github.com/ccfos/huatuo/blob/main/vendor/go.uber.org/atomic/README.md Install the latest version of the Uber Atomic package using go get. ```shell go get -u go.uber.org/atomic@v1 ``` -------------------------------- ### RPC Server Codec Setup Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/ugorji/go/codec/README.md Illustrates how to set up an RPC server codec using the go-codec package. It shows how to accept connections and create a server codec for either the standard Go RPC or MsgpackSpec RPC. ```go //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) } }() ``` -------------------------------- ### Implement a Connect RPC Client Source: https://github.com/ccfos/huatuo/blob/main/vendor/connectrpc.com/connect/README.md Demonstrates how to initialize a client and perform a remote procedure call with custom headers. ```go package main import ( "context" "log" "net/http" "connectrpc.com/connect" pingv1 "connectrpc.com/connect/internal/gen/connect/ping/v1" "connectrpc.com/connect/internal/gen/connect/ping/v1/pingv1connect" ) func main() { client := pingv1connect.NewPingServiceClient( http.DefaultClient, "http://localhost:8080/", ) req := connect.NewRequest(&pingv1.PingRequest{ Number: 42, }) req.Header().Set("Some-Header", "hello from connect") res, err := client.Ping(context.Background(), req) if err != nil { log.Fatalln(err) } log.Println(res.Msg) log.Println(res.Header().Get("Some-Other-Header")) } ``` -------------------------------- ### Basic Structured Logging Example Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/go-kit/log/README.md Illustrates the difference between unstructured and structured logging. Use structured logging for richer contextual information. ```go // Unstructured log.Printf("HTTP server listening on %s", addr) // Structured logger.Log("transport", "HTTP", "addr", addr, "msg", "listening") ``` -------------------------------- ### Define a CLI application with commands Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/urfave/cli/v2/godoc-current.txt Configure an application with a name, usage description, and an action to execute. ```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) } ``` -------------------------------- ### Initialize and Use Codec Handle Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/ugorji/go/codec/README.md Demonstrates the creation and configuration of a Handle for encoding and decoding. Supports different codec types like Binc, Msgpack, and Cbor. Extensions can be configured for specific types. ```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) ``` -------------------------------- ### Clone Jaeger Repository and Update Submodules Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/uber/jaeger-client-go/CONTRIBUTING.md Clone the Jaeger client Go repository into the correct GOPATH location and update its submodules to get started. ```bash mkdir -p $GOPATH/src/github.com/uber cd $GOPATH/src/github.com/uber git clone git@github.com:jaegertracing/jaeger-client-go.git jaeger-client-go cd jaeger-client-go git submodule update --init --recursive ``` -------------------------------- ### Create and Join Memberlist Cluster Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/hashicorp/memberlist/README.md Initialize a memberlist from a default configuration and join an existing cluster by providing at least one known member's address. This snippet demonstrates basic setup and cluster joining. ```go /* Create the initial memberlist from a safe configuration. Please reference the godoc for other default config types. http://godoc.org/github.com/hashicorp/memberlist#Config */ list, err := memberlist.Create(memberlist.DefaultLocalConfig()) if err != nil { panic("Failed to create memberlist: " + err.Error()) } // Join an existing cluster by specifying at least one known member. n, err := list.Join([]string{"1.2.3.4"}) if err != nil { panic("Failed to join cluster: " + err.Error()) } // Ask for members of the cluster for _, member := range list.Members() { fmt.Printf("Member: %s %s\n", member.Name, member.Addr) } // Continue doing whatever you need, memberlist will maintain membership // information in the background. Delegates can be used for receiving // events when members join or leave. ``` -------------------------------- ### Load System Library and Call C Function in Go Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/ebitengine/purego/README.md This example demonstrates how to dynamically load a system library (like libc) and register a C function (puts) to be called from Go. It handles platform-specific library paths for macOS and Linux. Ensure CGO_ENABLED is set to 0 when running. ```go package main import ( "fmt" runtime "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!") } ``` -------------------------------- ### Typical Application Logging with Logfmt Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/go-kit/log/README.md Demonstrates basic structured logging using the Logfmt format. Ensure os.Stderr is accessible for output. ```go w := log.NewSyncWriter(os.Stderr) logger := log.NewLogfmtLogger(w) logger.Log("question", "what is the meaning of life?", "answer", 42) // Output: // question="what is the meaning of life?" answer=42 ``` -------------------------------- ### List all containers using the Docker Go client Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/docker/docker/client/README.md Initializes a Docker client from environment variables and retrieves a list of all containers, similar to running 'docker ps --all'. ```go package main import ( "context" "fmt" "github.com/docker/docker/api/types/container" "github.com/docker/docker/client" ) func main() { apiClient, err := client.NewClientWithOpts(client.FromEnv) if err != nil { panic(err) } defer apiClient.Close() containers, err := apiClient.ContainerList(context.Background(), container.ListOptions{All: true}) if err != nil { panic(err) } for _, ctr := range containers { fmt.Printf("%s %s (status: %s)\n", ctr.ID, ctr.Image, ctr.Status) } } ``` -------------------------------- ### Logrus Output Examples Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/sirupsen/logrus/README.md Example output formats when caller reporting is enabled. ```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"} ``` ```text time="2015-03-26T01:27:38-04:00" level=fatal method=github.com/sirupsen/arcticcreatures.migrate msg="a penguin swims by" animal=penguin ``` -------------------------------- ### YAML example output Source: https://github.com/ccfos/huatuo/blob/main/vendor/gopkg.in/yaml.v3/README.md The expected output generated by the provided Go example code. ```text --- t: {Easy! {2 [3 4]}} --- t dump: a: Easy! b: c: 2 d: [3, 4] --- m: map[a:Easy! b:map[c:2 d:[3 4]]] --- m dump: a: Easy! b: c: 2 d: - 3 - 4 ``` -------------------------------- ### Install lz4c CLI tool Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/pierrec/lz4/v4/README.md Install the command-line interface tool for LZ4 file operations. ```bash go install github.com/pierrec/lz4/v4/cmd/lz4c@latest ``` -------------------------------- ### Start Local Environment Source: https://github.com/ccfos/huatuo/blob/main/docs/quick-start_en.md Deploys the full HUATUO stack including Elasticsearch, Prometheus, and Grafana using Docker Compose. ```bash $ docker compose --project-directory ./build/docker up ``` -------------------------------- ### Start Local Consul Agent Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/hashicorp/consul/api/README.md Command to start a local Consul agent in development mode. ```shell consul agent -dev -node machine ``` -------------------------------- ### Install cpuid via Homebrew Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/klauspost/cpuid/v2/README.md Installs the cpuid command-line tool on macOS/Linux systems using Homebrew. ```sh $ brew install cpuid ``` -------------------------------- ### Show Command Help Function Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/urfave/cli/v2/godoc-current.txt Prints help information for a specified command. ```go func ShowCommandHelp(ctx *Context, command string) error ShowCommandHelp prints help for the given command ``` -------------------------------- ### Install HUATUO on OC8 Source: https://github.com/ccfos/huatuo/blob/main/docs/deployment/systemd_en.md Install the downloaded RPM package using the rpm command with sudo privileges. ```bash sudo rpm -ivh huatuo-bamai*.rpm ``` -------------------------------- ### Build All Files (Old System) Source: https://github.com/ccfos/huatuo/blob/main/vendor/golang.org/x/sys/unix/README.md Use this script to generate Go files for your current OS and architecture with the old build system. Ensure GOOS and GOARCH are set correctly. ```bash mkall.sh ``` -------------------------------- ### Slice Source: https://github.com/ccfos/huatuo/blob/main/vendor/github.com/samber/lo/README.md Returns a copy of a slice from `start` up to, but not including `end`. Like `slice[start:end]`, but does not panic on overflow. ```APIDOC ## Slice ### Description Returns a copy of a slice from `start` up to, but not including `end`. Like `slice[start:end]`, but does not panic on overflow. ### Method N/A (Function Call) ### Endpoint N/A ### Parameters - **slice** (interface{}) - The input slice. - **start** (int) - The starting index (inclusive). - **end** (int) - The ending index (exclusive). ### Request Example ```go in := []int{0, 1, 2, 3, 4} slice := lo.Slice(in, 2, 3) // []int{2} ``` ### Response #### Success Response (Slice) - Returns a new slice containing the specified range of elements. #### Response Example ```json [2] ``` ```