### Quick Start: Basic gws Server Setup Source: https://github.com/longhorn/cli/blob/master/vendor/github.com/lxzan/gws/README.md A minimal example demonstrating how to create and run a new gws server on a specified port. ```go package main import "github.com/lxzan/gws" func main() { gws.NewServer(&gws.BuiltinEventHandler{}, nil).Run(":6666") } ``` -------------------------------- ### Install and Test Go OLE Source: https://github.com/longhorn/cli/blob/master/vendor/github.com/go-ole/go-ole/README.md Instructions for getting the go-ole library, navigating to its directory, running tests, and executing an example program for Excel. ```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 go-ps Source: https://github.com/longhorn/cli/blob/master/vendor/github.com/mitchellh/go-ps/README.md Install the go-ps library using the standard go get command. ```bash $ go get github.com/mitchellh/go-ps ``` -------------------------------- ### Install Battery Library Source: https://github.com/longhorn/cli/blob/master/vendor/github.com/distatus/battery/README.md Install the battery library using go get. ```bash $ go get -u github.com/distatus/battery ``` -------------------------------- ### Install plist Library Source: https://github.com/longhorn/cli/blob/master/vendor/howett.net/plist/README.md Installs the plist library using the go get command. ```bash $ go get howett.net/plist ``` -------------------------------- ### Install go-shlex Source: https://github.com/longhorn/cli/blob/master/vendor/github.com/anmitsu/go-shlex/README.md Install the go-shlex library using the go get command. ```bash go get -u "github.com/anmitsu/go-shlex" ``` -------------------------------- ### Basic SSH Server Example Source: https://github.com/longhorn/cli/blob/master/vendor/github.com/gliderlabs/ssh/README.md A simple example demonstrating how to start an SSH server that responds with 'Hello world' to any connection. It uses the ssh.Handle and ssh.ListenAndServe functions. ```go package main import ( "github.com/gliderlabs/ssh" "io" "log" ) func main() { ssh.Handle(func(s ssh.Session) { io.WriteString(s, "Hello world\n") }) log.Fatal(ssh.ListenAndServe(":2222", nil)) } ``` -------------------------------- ### Install Diskv using Go Get Source: https://github.com/longhorn/cli/blob/master/vendor/github.com/peterbourgon/diskv/README.md Installs the diskv package using the Go build tool. Ensure Go is installed and configured. ```bash $ go get github.com/peterbourgon/diskv ``` -------------------------------- ### Install go.yaml.in/yaml/v3 Source: https://github.com/longhorn/cli/blob/master/vendor/go.yaml.in/yaml/v3/README.md Install the YAML package for Go using the go get command. ```bash go get go.yaml.in/yaml/v3 ``` -------------------------------- ### Install json-iterator/go Source: https://github.com/longhorn/cli/blob/master/vendor/github.com/json-iterator/go/README.md Use the go get command to install the json-iterator/go library. ```bash go get github.com/json-iterator/go ``` -------------------------------- ### Successful Preflight Installation Output Source: https://github.com/longhorn/cli/blob/master/docs/longhornctl_install_preflight.md Example output showing successful installation of dependencies and probing of modules. On some operating systems, a reboot might be required before running this command again. ```bash $ longhornctl install preflight INFO[2024-07-16T17:06:55+08:00] Initializing preflight installer INFO[2024-07-16T17:06:55+08:00] Cleaning up preflight installer INFO[2024-07-16T17:06:55+08:00] Running preflight installer INFO[2024-07-16T17:06:55+08:00] Installing dependencies with package manager INFO[2024-07-16T17:09:08+08:00] Installed dependencies with package manager INFO[2024-07-16T17:09:08+08:00] Retrieved preflight installer result: ip-192-168-208-117: info: - Successfully installed package nfs-client - Successfully installed package open-iscsi - Successfully installed package cryptsetup - Successfully probed module nfs - Successfully probed module iscsi_tcp - Successfully probed module dm_crypt - Successfully started service iscsid INFO[2024-07-16T17:09:08+08:00] Cleaning up preflight installer INFO[2024-07-16T17:09:08+08:00] Completed preflight installer. Use 'longhornctl check preflight' to check the result (on some os a reboot is required first) ``` -------------------------------- ### Install uuid Package Source: https://github.com/longhorn/cli/blob/master/vendor/github.com/google/uuid/README.md Installs the uuid package using the go get command. ```shell go get github.com/google/uuid ``` -------------------------------- ### Install Cobra Library Source: https://github.com/longhorn/cli/blob/master/vendor/github.com/spf13/cobra/README.md Install the latest version of the Cobra library using go get. ```bash go get -u github.com/spf13/cobra@latest ``` -------------------------------- ### Install Battery CLI Utility Source: https://github.com/longhorn/cli/blob/master/vendor/github.com/distatus/battery/README.md Install the battery command-line utility using go install. ```bash $ go install github.com/distatus/battery/cmd/battery@latest ``` -------------------------------- ### Install Sentry Go SDK Source: https://github.com/longhorn/cli/blob/master/vendor/github.com/getsentry/sentry-go/README.md Install the latest version of the sentry-go SDK using go get. ```console go get github.com/getsentry/sentry-go@latest ``` -------------------------------- ### Install Heredoc Package Source: https://github.com/longhorn/cli/blob/master/vendor/github.com/MakeNowJust/heredoc/README.md Use this command to install the heredoc package using go get. ```console $ go get github.com/MakeNowJust/heredoc ``` -------------------------------- ### Install CamelCase Package Source: https://github.com/longhorn/cli/blob/master/vendor/github.com/fatih/camelcase/README.md Install the CamelCase package using the go get command. ```bash go get github.com/fatih/camelcase ``` -------------------------------- ### Install sigs.k8s.io/yaml Source: https://github.com/longhorn/cli/blob/master/vendor/sigs.k8s.io/yaml/README.md Run this command to install the YAML package for Go. ```bash $ go get sigs.k8s.io/yaml ``` -------------------------------- ### KCP Server Example Source: https://github.com/longhorn/cli/blob/master/vendor/github.com/lxzan/gws/README.md Demonstrates how to set up a gws server using the KCP protocol for reliable UDP communication. ```go package main import ( "log" "github.com/lxzan/gws" kcp "github.com/xtaci/kcp-go" ) func main() { listener, err := kcp.Listen(":6666") if err != nil { log.Println(err.Error()) return } app := gws.NewServer(&gws.BuiltinEventHandler{}, nil) app.RunListener(listener) } ``` -------------------------------- ### Install treeprint Package Source: https://github.com/longhorn/cli/blob/master/vendor/github.com/xlab/treeprint/README.md Use 'go get' to install the treeprint package. This command fetches and installs the package into your Go workspace. ```bash $ go get github.com/xlab/treeprint ``` -------------------------------- ### Install blang/semver Source: https://github.com/longhorn/cli/blob/master/vendor/github.com/blang/semver/README.md Install the semver library using go get. It is recommended to vendor dependencies or fix on a specific version tag. ```bash $ go get github.com/blang/semver ``` -------------------------------- ### KCP Client Example Source: https://github.com/longhorn/cli/blob/master/vendor/github.com/lxzan/gws/README.md Shows how to establish a gws client connection over KCP, enabling communication with a KCP server. ```go package main import ( "github.com/lxzan/gws" kcp "github.com/xtaci/kcp-go" "log" ) func main() { conn, err := kcp.Dial("127.0.0.1:6666") if err != nil { log.Println(err.Error()) return } app, _, err := gws.NewClientFromConn(&gws.BuiltinEventHandler{}, nil, conn) if err != nil { log.Println(err.Error()) return } app.ReadLoop() } ``` -------------------------------- ### Install GWS Package Source: https://github.com/longhorn/cli/blob/master/vendor/github.com/lxzan/gws/README.md Install the latest version of the GWS package using go get. ```bash go get -v github.com/lxzan/gws@latest ``` -------------------------------- ### Install Gorilla WebSocket Source: https://github.com/longhorn/cli/blob/master/vendor/github.com/gorilla/websocket/README.md Use this command to install the Gorilla WebSocket package for your Go project. ```bash go get github.com/gorilla/websocket ``` -------------------------------- ### Basic Logging and Compression Example Source: https://github.com/longhorn/cli/blob/master/vendor/github.com/gorilla/handlers/README.md Demonstrates how to use LoggingHandler for selective request logging and CompressHandler for gzipping responses. ```go import ( "net/http" "github.com/gorilla/handlers" ) func main() { r := http.NewServeMux() // Only log requests to our admin dashboard to stdout r.Handle("/admin", handlers.LoggingHandler(os.Stdout, http.HandlerFunc(ShowAdminDashboard))) r.HandleFunc("/", ShowIndex) // Wrap our server with our gzip handler to gzip compress all responses. http.ListenAndServe(":8000", handlers.CompressHandler(r)) } ``` -------------------------------- ### Start Span with Description Option Source: https://github.com/longhorn/cli/blob/master/vendor/github.com/getsentry/sentry-go/CHANGELOG.md Demonstrates how to start a span and provide a description using the `WithDescription` option. This is useful for adding context to spans. ```go span := sentry.StartSpan(ctx, "http.client", WithDescription("GET /api/users")) ``` -------------------------------- ### Install go-openapi/jsonpointer Source: https://github.com/longhorn/cli/blob/master/vendor/github.com/go-openapi/jsonpointer/README.md Use this command to add the jsonpointer library to your Go project. ```cmd go get github.com/go-openapi/jsonpointer ``` -------------------------------- ### Install godbus/dbus Source: https://github.com/longhorn/cli/blob/master/vendor/github.com/godbus/dbus/v5/README.md Install the dbus library using the go get command. Requires Go 1.20 or later. ```go go get github.com/godbus/dbus/v5 ``` -------------------------------- ### Install Sentry Go SDK and OpenTelemetry Module Source: https://github.com/longhorn/cli/blob/master/vendor/github.com/getsentry/sentry-go/CHANGELOG.md Install the necessary packages for Sentry Go SDK and its OpenTelemetry integration using go get. ```bash go get github.com/getsentry/sentry-go \ github.com/getsentry/sentry-go/otel ``` -------------------------------- ### longhornctl install Options Source: https://github.com/longhorn/cli/blob/master/docs/longhornctl_install.md Lists the available options for the 'longhornctl install' command, including image configuration, Kubernetes namespace, and node selection. ```bash -h, --help help for install --image string Image containing longhornctl-local (default "longhornio/longhorn-cli:v1.12.0-dev") --image-pull-secret string Secret with registry credentials for pulling images --image-registry string Registry to apply to all images (CLI, engine, pause, BCI, etc.), replacing any registry already specified in those images. --kubeconfig string Kubernetes config (kubeconfig) path -l, --log-level string Log level (default "info") --namespace string The namespace to run DaemonSet pods. (default "longhorn-system") --node-selector string Comma-separated list of key=value pairs to match against node labels, selecting the nodes the DaemonSet will run on (e.g. env=prod,zone=us-west). ``` -------------------------------- ### Install and Run JSON Patch CLI Source: https://github.com/longhorn/cli/blob/master/vendor/gopkg.in/evanphx/json-patch.v4/README.md Instructions for installing the json-patch CLI and applying multiple patches to a document from stdin. ```bash $ go install github.com/evanphx/json-patch/cmd/json-patch $ cat document.json | json-patch -p patch.1.json -p patch.2.json {"address":"123 Main St","age":"21","name":"Jane"} ``` -------------------------------- ### Install go-gitignore Source: https://github.com/longhorn/cli/blob/master/vendor/github.com/monochromegane/go-gitignore/README.md Command to install the go-gitignore library using the Go build tool. Ensure your Go environment is set up correctly. ```sh go get github.com/monochromegane/go-gitignore ``` -------------------------------- ### Coexisting with glog Source: https://github.com/longhorn/cli/blob/master/vendor/k8s.io/klog/v2/README.md Example demonstrating how to initialize and synchronize flags between klog and glog, and redirect output to stderr. ```go package main import ( flag "flag" "k8s.io/klog/v2" "github.com/golang/glog" ) func main() { // Initialize klog flags klog.InitFlags(nil) // Initialize glog flags (if glog is also used) flag.Parse() // Set klog to log to stderr klog.SetFlags(klog.CopyStandardFlags(klog.InfoLevel)) klog.SetOutput(os.Stderr) // Set glog to log to stderr flag.Set("logtostderr", "true") klog.Info("This is a klog message.") glog.Info("This is a glog message.") } ``` -------------------------------- ### Install go-xgettext for String Extraction Source: https://github.com/longhorn/cli/blob/master/vendor/k8s.io/kubectl/pkg/util/i18n/translations/README.md Installs the go-xgettext tool, which is used to extract translatable strings from Go files. ```console go get github.com/gosexy/gettext/go-xgettext ``` -------------------------------- ### Longhornctl Install Preflight Command Source: https://github.com/longhorn/cli/blob/master/docs/longhornctl_install_preflight.md The basic command to initiate the Longhorn preflight installation process. ```bash longhornctl install preflight [flags] ``` -------------------------------- ### Longhornctl Install Preflight Options Source: https://github.com/longhorn/cli/blob/master/docs/longhornctl_install_preflight.md Configuration options for the 'longhornctl install preflight' command, including PCI device specification, driver overrides, SPDK enablement, and image details. ```bash --allow-pci string Specify a comma-separated (,) list of allowed PCI devices. By default, all PCI devices are blocked by a non-valid address. (default "none") --driver-override string Userspace driver for device bindings. Override default driver for PCI devices. --enable-spdk Enable installation of SPDK required packages, modules, and setup. -h, --help help for preflight --huge-page-size int Specify the huge page size in MiB for SPDK. (default 2048) --image string Image containing longhornctl-local (default "longhornio/longhorn-cli:v1.12.0-dev") --image-pull-secret string Secret with registry credentials for pulling images --image-registry string Registry to apply to all images (CLI, engine, pause, BCI, etc.), replacing any registry already specified in those images. --kubeconfig string Kubernetes config (kubeconfig) path -l, --log-level string Log level (default "info") --namespace string The namespace to run DaemonSet pods. (default "longhorn-system") --node-selector string Comma-separated list of key=value pairs to match against node labels, selecting the nodes the DaemonSet will run on (e.g. env=prod,zone=us-west). --operating-system string Specify the operating system ("", cos). Leave this empty to use the package manager for installation. --restart-kubelet Enable automatic kubelet service restart to apply changes to huge page size --restart-kubelet-window string Time window for randomized restart (e.g., 10s, 2m). Kubelet will restart at a random time within this window. (default "1m") --spdk-options string Specify a comma-separated (,) list of custom options for configuring SPDK environment. --update-packages Update packages before installing required dependencies. (default true) ``` -------------------------------- ### Footnote Syntax Example Source: https://github.com/longhorn/cli/blob/master/vendor/github.com/russross/blackfriday/v2/README.md Demonstrates the syntax for creating footnotes, including the marker in the text and the footnote definition. ```markdown This is a footnote.[^1] [^1]: the footnote text. ``` -------------------------------- ### Definition List Syntax Example Source: https://github.com/longhorn/cli/blob/master/vendor/github.com/russross/blackfriday/v2/README.md Shows the syntax for creating definition lists, with terms followed by a colon and their definitions. ```markdown Cat : Fluffy animal everyone likes Internet : Vector of transmission for pictures of cats ``` -------------------------------- ### Example Document Source: https://github.com/longhorn/cli/blob/master/vendor/gopkg.in/evanphx/json-patch.v4/README.md A sample JSON document to which patches will be applied. ```json { "name": "John", "age": 24, "height": 3.21 } ``` -------------------------------- ### Download and Install longhornctl Binary Source: https://github.com/longhorn/cli/blob/master/README.md Download the appropriate `longhornctl` release for your OS and architecture, make it executable, and move it to `/usr/local/bin`. ```bash curl -L https://github.com/longhorn/cli/releases/download/${LonghornVersion}/longhornctl-${OS}-${ARCH} -o longhornctl chmod +x longhornctl mv ./longhornctl /usr/local/bin/longhornctl ``` -------------------------------- ### Basic Diskv Usage Example Source: https://github.com/longhorn/cli/blob/master/vendor/github.com/peterbourgon/diskv/README.md Demonstrates the simplest way to initialize and use a diskv store. Includes writing, reading, and erasing a key-value pair. ```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) } ``` -------------------------------- ### Install Latest JSON-Patch Source: https://github.com/longhorn/cli/blob/master/vendor/gopkg.in/evanphx/json-patch.v4/README.md Install the latest version of the jsonpatch library using go get. ```bash go get -u github.com/evanphx/json-patch/v5 ``` -------------------------------- ### Best Practice: gws Server with Options and Event Handling Source: https://github.com/longhorn/cli/blob/master/vendor/github.com/lxzan/gws/README.md Demonstrates a more robust gws server setup including parallel processing, exception recovery, compression, and detailed event handling for connection lifecycle and messages. ```go package main import ( "github.com/lxzan/gws" "net/http" "time" ) const ( PingInterval = 5 * time.Second PingWait = 10 * time.Second ) func main() { upgrader := gws.NewUpgrader(&Handler{}, &gws.ServerOption{ ParallelEnabled: true, // Parallel message processing Recovery: gws.Recovery, // Exception recovery PermessageDeflate: gws.PermessageDeflate{Enabled: true}, // Enable compression }) http.HandleFunc("/connect", func(writer http.ResponseWriter, request *http.Request) { socket, err := upgrader.Upgrade(writer, request) if err != nil { return } go func() { socket.ReadLoop() // Blocking prevents the context from being GC. }() }) http.ListenAndServe(":6666", nil) } type Handler struct{} func (c *Handler) OnOpen(socket *gws.Conn) { _ = socket.SetDeadline(time.Now().Add(PingInterval + PingWait)) } func (c *Handler) OnClose(socket *gws.Conn, err error) {} func (c *Handler) OnPing(socket *gws.Conn, payload []byte) { _ = socket.SetDeadline(time.Now().Add(PingInterval + PingWait)) _ = socket.WritePong(nil) } func (c *Handler) OnPong(socket *gws.Conn, payload []byte) {} func (c *Handler) OnMessage(socket *gws.Conn, message *gws.Message) { defer message.Close() socket.WriteMessage(message.Opcode, message.Bytes()) } ``` -------------------------------- ### SpdyStream Client Example Source: https://github.com/longhorn/cli/blob/master/vendor/github.com/moby/spdystream/README.md Connects to a mirroring server and creates a stream to send and receive data. 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() } ``` -------------------------------- ### Verify longhornctl Installation Source: https://github.com/longhorn/cli/blob/master/README.md Check the installed `longhornctl` version to confirm the installation was successful. ```bash longhornctl version ``` -------------------------------- ### Remove Previous longhornctl Installation Source: https://github.com/longhorn/cli/blob/master/README.md Before installing a new version, remove any existing `longhornctl` installation from `/usr/local/bin/longhornctl`. ```bash rm -rf /usr/local/bin/longhornctl ``` -------------------------------- ### Full Version Object Example Source: https://github.com/longhorn/cli/blob/master/vendor/github.com/blang/semver/README.md Illustrates parsing a complex version string and accessing its components like Major, Minor, Patch, Pre-release, and Build metadata. Also shows how to manipulate and validate version objects. ```go import "github.com/blang/semver" import "fmt" v, err := semver.Make("0.0.1-alpha.preview+123.github") fmt.Printf("Major: %d\n", v.Major) fmt.Printf("Minor: %d\n", v.Minor) fmt.Printf("Patch: %d\n", v.Patch) fmt.Printf("Pre: %s\n", v.Pre) fmt.Printf("Build: %s\n", v.Build) // Prerelease versions array if len(v.Pre) > 0 { fmt.Println("Prerelease versions:") for i, pre := range v.Pre { fmt.Printf("%d: %q\n", i, pre) } } // Build meta data array if len(v.Build) > 0 { fmt.Println("Build meta data:") for i, build := range v.Build { fmt.Printf("%d: %q\n", i, build) } } v001, err := semver.Make("0.0.1") // Compare using helpers: v.GT(v2), v.LT, v.GTE, v.LTE v001.GT(v) == true v.LT(v001) == true v.GTE(v) == true v.LTE(v) == true // Or use v.Compare(v2) for comparisons (-1, 0, 1): v001.Compare(v) == 1 v.Compare(v001) == -1 v.Compare(v) == 0 // Manipulate Version in place: v.Pre[0], err = semver.NewPRVersion("beta") if err != nil { fmt.Printf("Error parsing pre release version: %q", err) } fmt.Println("\nValidate versions:") v.Build[0] = "?" err = v.Validate() if err != nil { fmt.Printf("Validation failed: %s\n", err) } ``` -------------------------------- ### Install JSON-Patch Version 4 Source: https://github.com/longhorn/cli/blob/master/vendor/gopkg.in/evanphx/json-patch.v4/README.md Install a specific older version (v4) of the jsonpatch library. ```bash go get -u gopkg.in/evanphx/json-patch.v4 ``` -------------------------------- ### Build longhornctl Binary from Source Source: https://github.com/longhorn/cli/blob/master/README.md Navigate into the cloned `cli` directory and use `make` to build the `longhornctl` and `longhornctl-local` binaries. ```bash cd cli make ``` -------------------------------- ### Install Cobra CLI Generator Source: https://github.com/longhorn/cli/blob/master/vendor/github.com/spf13/cobra/README.md Install the cobra-cli tool, which generates Cobra application scaffolding. ```bash go install github.com/spf13/cobra-cli@latest ``` -------------------------------- ### Initialize GitIgnore and Match Path Source: https://github.com/longhorn/cli/blob/master/vendor/github.com/monochromegane/go-gitignore/README.md Initializes a new GitIgnore instance with a specified gitignore file path and then matches a given path against the loaded patterns. This is the primary usage pattern for the library. ```go gitignore, _ := gitignore.NewGitIgnore("/path/to/gitignore") path := "/path/to/file" isDir := false gitignore.Match(path, isDir) ``` -------------------------------- ### Stop Longhorn Preflight Installer Source: https://github.com/longhorn/cli/blob/master/docs/longhornctl_install_preflight_stop.md Use this command to stop the Longhorn preflight installer. It provides feedback on the stopping process. ```bash $ longhornctl install preflight stop INFO[2024-07-16T17:21:32+08:00] Stopping preflight installer INFO[2024-07-16T17:21:32+08:00] Successfully stopped preflight installer ``` -------------------------------- ### BindLocale with FileSystem Interface Source: https://github.com/longhorn/cli/blob/master/vendor/github.com/chai2010/gettext-go/README.md Demonstrates how to use the FileSystem interface with BindLocale to bind translation domains from different sources, including directories and zip archives. ```go // Use FileSystem: // BindLocale(New("poedit", "name", OS("path/to/dir"))) // bind "poedit" domain // BindLocale(New("poedit", "name", OS("path/to.zip"))) // bind "poedit" domain ``` -------------------------------- ### Get a Translated Plural String Source: https://github.com/longhorn/cli/blob/master/vendor/k8s.io/kubectl/pkg/util/i18n/translations/README.md Shows how to get a translated string that includes a pluralizable count. The %d placeholder is used for the count. ```go import pkg/i18n ... // Get a translated plural string translated := i18n.T("You had %d items", items) ``` -------------------------------- ### Basic Version Parsing and Comparison Source: https://github.com/longhorn/cli/blob/master/vendor/github.com/blang/semver/README.md Demonstrates parsing version strings into semver objects and comparing them. Ensure error handling for parsing operations. ```go import "github.com/blang/semver" v1, err := semver.Make("1.0.0-beta") v2, err := semver.Make("2.0.0-beta") v1.Compare(v2) ``` -------------------------------- ### longhornctl get Inherited Options Source: https://github.com/longhorn/cli/blob/master/docs/longhornctl_get.md Shows options inherited from parent commands for 'longhornctl get', such as tolerations for DaemonSet pods. ```bash longhornctl get --tolerations "key=value:NoSchedule;:NoExecute" ``` -------------------------------- ### longhornctl global-options Help Flag Source: https://github.com/longhorn/cli/blob/master/docs/longhornctl_global-options.md Shows help information for the global-options command. ```bash -h, --help help for global-options ``` -------------------------------- ### Commit Message Format Example Source: https://github.com/longhorn/cli/blob/master/vendor/github.com/godbus/dbus/v5/CONTRIBUTING.md An example demonstrating the required format for commit messages, including subject, body, and footer. ```git commit scripts: add the test-cluster command this uses tmux to setup a test cluster that you can easily kill and start for debugging. Fixes #38 ``` -------------------------------- ### Install go-bindata for Bindata Regeneration Source: https://github.com/longhorn/cli/blob/master/vendor/k8s.io/kubectl/pkg/util/i18n/translations/README.md Installs the go-bindata tool, used to convert translation files into generated Go code for embedding into binaries. ```console go get github.com/go-bindata/go-bindata/... ``` -------------------------------- ### longhornctl install Inherited Options Source: https://github.com/longhorn/cli/blob/master/docs/longhornctl_install.md Lists options inherited by the 'longhornctl install' command from its parent commands, specifically tolerations for DaemonSet pods. ```bash --tolerations string Semicolon-separated list of tolerations for DaemonSet pods (e.g. key=value:NoSchedule;:NoExecute). ``` -------------------------------- ### Initialize and Use Structured Logging Source: https://github.com/longhorn/cli/blob/master/vendor/github.com/getsentry/sentry-go/CHANGELOG.md Demonstrates how to initialize a logger and send an informational message using Sentry's structured logging feature. Ensure the Sentry SDK is properly initialized before using this. ```go logger := sentry.NewLogger(ctx) logger.Info(ctx, "Hello, Logs!") ``` -------------------------------- ### Basic Word Wrapping Example Source: https://github.com/longhorn/cli/blob/master/vendor/github.com/mitchellh/go-wordwrap/README.md Demonstrates basic usage of the WrapString function to wrap a given string to a specified width. This is useful for formatting CLI output. ```go wrapped := wordwrap.WrapString("foo bar baz", 3) fmt.Println(wrapped) ``` -------------------------------- ### longhornctl get Options Source: https://github.com/longhorn/cli/blob/master/docs/longhornctl_get.md Displays the available options for the 'longhornctl get' command, including image configuration, Kubernetes context, logging level, and node selectors. ```bash longhornctl get --help ``` -------------------------------- ### Basic Assertions in Go with Mint Source: https://github.com/longhorn/cli/blob/master/vendor/github.com/otiai10/mint/README.md Demonstrates fundamental assertion patterns in Go using the mint library, including checking equality, type, and non-nil values. It also shows how to assert function exit codes and handle assertion failures. ```go package your_test import ( "testing" "pkg/your" . "github.com/otiai10/mint" ) func TestFoo(t *testing.T) { foo := your.Foo() Expect(t, foo).ToBe(1234) Expect(t, foo).TypeOf("int") Expect(t, foo).Not().ToBe(nil) Expect(t, func() { yourFunc() }).Exit(1) // If assertion failed, exit 1 with message. Expect(t, foo).ToBe("foobarbuz") // You can run assertions without os.Exit res := Expect(t, foo).Dry().ToBe("bar") // res.OK() == false // You can omit repeated `t`. m := mint.Blend(t) m.Expect(foo).ToBe(1234) } ```