### Go Get v2+ Example Source: https://github.com/osbuild/osbuild-composer/blob/main/vendor/go.opentelemetry.io/otel/VERSIONING.md Example of go get command for v2 or higher modules. ```bash go get go.opentelemetry.io/otel/v2@v2.0.1 ``` -------------------------------- ### go-codegen Configuration Example Source: https://github.com/osbuild/osbuild-composer/blob/main/vendor/github.com/aws/smithy-go/README.md This example applies the `go-codegen` build plugin to the Smithy quickstart example created from `smithy init`. ```json { "version": "1.0", "sources": [ "models" ], "maven": { "dependencies": [ "software.amazon.smithy.go:smithy-go-codegen:0.1.0" ] }, "plugins": { "go-codegen": { "service": "example.weather#Weather", "module": "github.com/example/weather", "generateGoMod": true, "goDirective": "1.24" } } } ``` -------------------------------- ### Installation Source: https://github.com/osbuild/osbuild-composer/blob/main/vendor/github.com/hashicorp/go-version/README.md Installs the go-version package using the go get command. ```bash $ go get github.com/hashicorp/go-version ``` -------------------------------- ### Basic Example Source: https://github.com/osbuild/osbuild-composer/blob/main/vendor/github.com/labstack/echo/v4/README.md A simple example demonstrating how to create an Echo instance, use middleware, define a route, and start the server. ```go package main import ( "github.com/labstack/echo/v4" "github.com/labstack/echo/v4/middleware" "log/slog" "net/http" ) func main() { // Echo instance e := echo.New() // Middleware e.Use(middleware.RequestLogger()) // use the default RequestLogger middleware with slog logger e.Use(middleware.Recover()) // recover panics as errors for proper error handling // Routes e.GET("/", hello) // Start server if err := e.Start(":8080"); err != nil && !errors.Is(err, http.ErrServerClosed) { slog.Error("failed to start server", "error", err) } } // Handler func hello(c echo.Context) error { return c.String(http.StatusOK, "Hello, World!") } ``` -------------------------------- ### Basic Usage Example Source: https://github.com/osbuild/osbuild-composer/blob/main/vendor/github.com/julienschmidt/httprouter/README.md A simple example demonstrating how to set up routes for the root path and a path with a parameter, and start an HTTP server. ```go package main import ( "fmt" "net/http" "log" "github.com/julienschmidt/httprouter" ) func Index(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { fmt.Fprint(w, "Welcome!\n") } func Hello(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { fmt.Fprintf(w, "hello, %s!\n", ps.ByName("name")) } func main() { router := httprouter.New() router.GET("/", Index) router.GET("/hello/:name", Hello) log.Fatal(http.ListenAndServe(":8080", router)) } ``` -------------------------------- ### Install Mergo Source: https://github.com/osbuild/osbuild-composer/blob/main/vendor/dario.cat/mergo/README.md How to get the Mergo library using go get. ```go go get dario.cat/mergo ``` ```go // use in your .go code import ( "dario.cat/mergo" ) ``` -------------------------------- ### Installation Source: https://github.com/osbuild/osbuild-composer/blob/main/vendor/github.com/labstack/echo/v4/README.md Install the latest version of Echo using go get. ```go // go get github.com/labstack/echo/{version} go get github.com/labstack/echo/v4 ``` -------------------------------- ### Install Source: https://github.com/osbuild/osbuild-composer/blob/main/vendor/github.com/gobwas/glob/readme.md Install the glob library using go get. ```shell go get github.com/gobwas/glob ``` -------------------------------- ### Installation Source: https://github.com/osbuild/osbuild-composer/blob/main/vendor/github.com/proglottis/gpgme/README.md Install the GPGME Go wrapper using go get. ```go go get -u github.com/proglottis/gpgme ``` -------------------------------- ### Development Setup Source: https://github.com/osbuild/osbuild-composer/blob/main/vendor/github.com/apapsch/go-jsonmerge/v2/README.md Commands for installing dependencies and building the project. ```bash # Install depencencies ./init.sh # Build ./build.sh ``` -------------------------------- ### Installation Source: https://github.com/osbuild/osbuild-composer/blob/main/vendor/gopkg.in/ini.v1/README.md Command to install the ini package using go get. ```shell go get gopkg.in/ini.v1 ``` -------------------------------- ### Installation Source: https://github.com/osbuild/osbuild-composer/blob/main/vendor/github.com/klauspost/pgzip/README.md Installation instructions for pgzip. ```go go get github.com/klauspost/pgzip/... ``` ```go go get -u github.com/klauspost/compress ``` -------------------------------- ### Installation Source: https://github.com/osbuild/osbuild-composer/blob/main/vendor/go.opencensus.io/README.md Install the OpenCensus Go library using go get. ```bash $ go get -u go.opencensus.io ``` -------------------------------- ### Installation Source: https://github.com/osbuild/osbuild-composer/blob/main/vendor/github.com/mattn/go-isatty/README.md Command to install the go-isatty package. ```bash $ go get github.com/mattn/go-isatty ``` -------------------------------- ### Partition Table Configuration Source: https://github.com/osbuild/osbuild-composer/blob/main/image-types/rhel8/google-gce.md Example kickstart configuration for EFI partitioning and root filesystem setup. ```shell # EFI partitioning, creates a GPT partitioned disk. part /boot/efi --size=200 --fstype=efi --ondrive=sdb part / --size=100 --grow --ondrive=sdb --label=root --fstype=xfs ``` -------------------------------- ### Example Usage Source: https://github.com/osbuild/osbuild-composer/blob/main/vendor/github.com/mistifyio/go-zfs/v3/README.md Demonstrates creating a filesystem, taking a snapshot, cloning it, and then destroying them. ```go //assuming a zpool named test //error handling omitted f, err := zfs.CreateFilesystem("test/snapshot-test", nil) ok(t, err) s, err := f.Snapshot("test", nil) ok(t, err) // snapshot is named "test/snapshot-test@test" c, err := s.Clone("test/clone-test", nil) err := c.Destroy() err := s.Destroy() err := f.Destroy() ``` -------------------------------- ### Getting Started with govmomi Repository Setup Source: https://github.com/osbuild/osbuild-composer/blob/main/vendor/github.com/vmware/govmomi/CONTRIBUTING.md This snippet shows how to clone the govmomi repository, configure git to prevent accidental pushes to the upstream, and add a remote for your personal fork. ```bash git clone https://github.com/vmware/govmomi.git && cd govmomi # prevent accidentally pushing to vmware/govmomi git config push.default nothing git remote rename origin vmware # add your fork git remote add $USER git@github.com:$USER/govmomi.git git fetch -av ``` -------------------------------- ### Installation Source: https://github.com/osbuild/osbuild-composer/blob/main/vendor/github.com/mattn/go-sqlite3/README.md This package can be installed with the `go get` command. ```go go get github.com/mattn/go-sqlite3 ``` -------------------------------- ### Installation Source: https://github.com/osbuild/osbuild-composer/blob/main/vendor/github.com/sony/gobreaker/README.md Install the gobreaker package using go get. ```go go get github.com/sony/gobreaker ``` -------------------------------- ### Full Example: Small Mux Server Source: https://github.com/osbuild/osbuild-composer/blob/main/vendor/github.com/gorilla/mux/README.md A complete, runnable Go program demonstrating a basic server using Gorilla Mux, including route definition 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)) } ``` -------------------------------- ### Installation Source: https://github.com/osbuild/osbuild-composer/blob/main/vendor/github.com/labstack/gommon/bytes/README.md Install the gommon/bytes package using go get. ```go go get github.com/labstack/gommon/bytes ``` -------------------------------- ### Prepare kickstart configuration Source: https://github.com/osbuild/osbuild-composer/blob/main/image-types/rhel8/google-gce.md Copies the kickstart configuration and removes unnecessary files. ```shell # Send /root/anaconda-ks.cfg to our logs. cp /run/install/ks.cfg /tmp/anaconda-ks.cfg # Remove files which shouldn't make it into the image. Its possible these files # will not exist. rm -f /etc/boto.cfg /etc/udev/rules.d/70-persistent-net.rules # Remove ens4 config from installer. rm -f /etc/sysconfig/network-scripts/ifcfg-ens4 ``` -------------------------------- ### Install Marshmallow Source: https://github.com/osbuild/osbuild-composer/blob/main/vendor/github.com/perimeterx/marshmallow/README.md Install the Marshmallow package using go get. ```sh go get -u github.com/perimeterx/marshmallow ``` -------------------------------- ### Basic Examples Source: https://github.com/osbuild/osbuild-composer/blob/main/vendor/github.com/golang/glog/README.md Basic examples of using glog.Info and glog.Fatalf. ```go glog.Info("Prepare to repel boarders") glog.Fatalf("Initialization failed: %s", err) ``` -------------------------------- ### Installation Source: https://github.com/osbuild/osbuild-composer/blob/main/vendor/github.com/labstack/gommon/color/README.md Installs the gommon/color package using go get. ```sh go get github.com/labstack/gommon/color ``` -------------------------------- ### Create an Accounts Client Source: https://github.com/osbuild/osbuild-composer/blob/main/vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage/README.md Example of creating an Accounts client from the client factory. ```go client := clientFactory.NewAccountsClient() ``` -------------------------------- ### Example Usage Source: https://github.com/osbuild/osbuild-composer/blob/main/vendor/github.com/jackc/puddle/v2/README.md Demonstrates how to create and use a resource pool with Puddle, including acquiring, using, and releasing a resource. ```go package main import ( "context" "log" "net" "github.com/jackc/puddle/v2" ) func main() { constructor := func(context.Context) (net.Conn, error) { return net.Dial("tcp", "127.0.0.1:8080") } destructor := func(value net.Conn) { value.Close() } maxPoolSize := int32(10) pool, err := puddle.NewPool(&puddle.Config[net.Conn]{Constructor: constructor, Destructor: destructor, MaxSize: maxPoolSize}) if err != nil { log.Fatal(err) } // Acquire resource from the pool. res, err := pool.Acquire(context.Background()) if err != nil { log.Fatal(err) } // Use resource. _, err = res.Value().Write([]byte{1}) if err != nil { log.Fatal(err) } // Release when done. res.Release() } ``` -------------------------------- ### Copy kickstart configuration Source: https://github.com/osbuild/osbuild-composer/blob/main/image-types/rhel8/google-gce.md Copies the kickstart configuration to a temporary location for logging. ```bash cp /run/install/ks.cfg /tmp/anaconda-ks.cfg ``` -------------------------------- ### Installation Source: https://github.com/osbuild/osbuild-composer/blob/main/vendor/github.com/getsentry/sentry-go/logrus/README.md Install the sentry-go/logrus package using go get. ```sh go get github.com/getsentry/sentry-go/logrus ``` -------------------------------- ### Installation Source: https://github.com/osbuild/osbuild-composer/blob/main/vendor/github.com/getsentry/sentry-go/README.md Install the sentry-go SDK using go get. ```console go get github.com/getsentry/sentry-go@latest ``` -------------------------------- ### Example Source: https://github.com/osbuild/osbuild-composer/blob/main/vendor/github.com/gobwas/glob/readme.md Demonstrates various ways to compile and use glob patterns, including simple globs, quoted meta characters, custom delimiters, super wildcards, single symbol wildcards, character-list matchers, character-range matchers, and pattern-alternatives. ```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 ["early"] g = glob.MustCompile("api.*.com", '.') g.Match("api.github.com") // true g.Match("api.gi.hub.com") // false // create new glob with set of delimiters as ["early"] // but now with super wildcard g = glob.MustCompile("api.**.com", '.') g.Match("api.github.com") // true g.Match("api.gi.hub.com") // true // create glob with single symbol wildcard g = glob.MustCompile("?at") g.Match("cat") // true g.Match("fat") // true g.Match("at") // false // create glob with single symbol wildcard and delimiters ['f'] g = glob.MustCompile("?at", 'f') g.Match("cat") // true g.Match("fat") // false g.Match("at") // false // create glob with character-list matchers g = glob.MustCompile("[abc]at") g.Match("cat") // true g.Match("bat") // true g.Match("fat") // false g.Match("at") // false // create glob with character-list matchers g = glob.MustCompile("[!abc]at") g.Match("cat") // false g.Match("bat") // false g.Match("fat") // true g.Match("at") // false // create glob with character-range matchers g = glob.MustCompile("[a-c]at") g.Match("cat") // true g.Match("bat") // true g.Match("fat") // false g.Match("at") // false // create glob with character-range matchers g = glob.MustCompile("[!a-c]at") g.Match("cat") // false g.Match("bat") // false g.Match("fat") // true g.Match("at") // false // create glob with pattern-alternatives list g = glob.MustCompile("{cat,bat,[fr]at}") g.Match("cat") // true g.Match("bat") // true g.Match("fat") // true g.Match("rat") // true g.Match("at") // false g.Match("zat") // false } ``` -------------------------------- ### OpenStack instance configuration example Source: https://github.com/osbuild/osbuild-composer/blob/main/DEPLOYING.md Example JSON configuration for creating an OpenStack instance. ```json { "name": "composer-instance", "image": "fedora-32-x86_64", "flavor": "m1.small", "network": "my-network-id" } ``` -------------------------------- ### Installation Source: https://github.com/osbuild/osbuild-composer/blob/main/vendor/go.yaml.in/yaml/v3/README.md Install the `go.yaml.in/yaml/v3` package using go get. ```bash go get go.yaml.in/yaml/v3 ``` -------------------------------- ### Serving Static Files Source: https://github.com/osbuild/osbuild-composer/blob/main/vendor/github.com/gorilla/mux/README.md An example of how to serve static files using `PathPrefix` and `http.FileServer`. ```go func main() { var dir string flag.StringVar(&dir, "dir", ".", "the directory to serve files from. Defaults to the current dir") flag.Parse() r := mux.NewRouter() // This will serve files under http://localhost:8000/static/ r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir(dir)))) srv := &http.Server{ Handler: r, Addr: "127.0.0.1:8000", // Good practice: enforce timeouts for servers you create! WriteTimeout: 15 * time.Second, ReadTimeout: 15 * time.Second, } log.Fatal(srv.ListenAndServe()) } ``` -------------------------------- ### Example Connection Strings for User Authentication Source: https://github.com/osbuild/osbuild-composer/blob/main/vendor/github.com/mattn/go-sqlite3/README.md Demonstrates how to create a database with user authentication, including options for specifying username, password, and password encoding method. ```sql file:test.s3db?_auth&_auth_user=admin&_auth_pass=admin ``` ```sql file:test.s3db?_auth&_auth_user=admin&_auth_pass=admin&_auth_crypt=sha1 ``` -------------------------------- ### Install uuid package Source: https://github.com/osbuild/osbuild-composer/blob/main/vendor/github.com/google/uuid/README.md Command to install the uuid package using go get. ```sh go get github.com/google/uuid ``` -------------------------------- ### Usage Example Source: https://github.com/osbuild/osbuild-composer/blob/main/vendor/github.com/mattn/go-colorable/README.md Demonstrates how to use go-colorable with logrus to enable colored output on Windows. ```go logrus.SetFormatter(&logrus.TextFormatter{ForceColors: true}) logrus.SetOutput(colorable.NewColorableStdout()) logrus.Info("succeeded") logrus.Warn("not correct") logrus.Error("something error") logrus.Fatal("panic") ``` -------------------------------- ### Install Source: https://github.com/osbuild/osbuild-composer/blob/main/vendor/cloud.google.com/go/compute/metadata/README.md Command to install the metadata library. ```bash go get cloud.google.com/go/compute/metadata ``` -------------------------------- ### Example Usage Source: https://github.com/osbuild/osbuild-composer/blob/main/vendor/github.com/sony/gobreaker/README.md An example demonstrating how to use gobreaker to wrap an HTTP GET request. ```go var cb *breaker.CircuitBreaker func Get(url string) ([]byte, error) { body, err := cb.Execute(func() (interface{}, error) { resp, err := http.Get(url) if err != nil { return nil, err } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { return nil, err } return body, nil }) if err != nil { return nil, err } return body.([]byte), nil } ``` -------------------------------- ### Routing Tree Example Source: https://github.com/osbuild/osbuild-composer/blob/main/vendor/github.com/julienschmidt/httprouter/README.md An example visualization of the routing tree structure for GET requests. ```Go Priority Path Handle 9 \ *<1> 3 ├s nil 2 |├earch\ *<2> 1 |└upport\ *<3> 2 ├blog\ *<4> 1 | └:post nil 1 | └\ *<5> 2 ├about-us\ *<6> 1 | └team\ *<7> 1 └contact\ *<8> ``` -------------------------------- ### Installation Source: https://github.com/osbuild/osbuild-composer/blob/main/vendor/github.com/rivo/uniseg/README.md Install the uniseg package using go get. ```bash go get github.com/rivo/uniseg ``` -------------------------------- ### Go commands for development Source: https://github.com/osbuild/osbuild-composer/blob/main/CONTRIBUTING.md Example commands using 'go' to generate, build, and test code. ```bash $ go test ./... $ go build ./... $ go generate ./... ``` -------------------------------- ### Installation Source: https://github.com/osbuild/osbuild-composer/blob/main/vendor/github.com/getsentry/sentry-go/echo/README.md Install the sentry-go/echo package using go get. ```sh go get github.com/getsentry/sentry-go/echo ``` -------------------------------- ### Install ksuid Source: https://github.com/osbuild/osbuild-composer/blob/main/vendor/github.com/segmentio/ksuid/README.md Command to install the ksuid library using go get. ```sh go get -u github.com/segmentio/ksuid ``` -------------------------------- ### View Registration Example Source: https://github.com/osbuild/osbuild-composer/blob/main/vendor/go.opencensus.io/README.md Shows how to register a view with a DistributionAggregation for processed video size. ```go if err := view.Register(&view.View{ Name: "example.com/video_size_distribution", Description: "distribution of processed video size over time", Measure: videoSize, Aggregation: view.Distribution(1<<32, 2<<32, 3<<32), }); err != nil { log.Fatalf("Failed to register view: %v", err) } ``` -------------------------------- ### Install the package Source: https://github.com/osbuild/osbuild-composer/blob/main/vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5/README.md Install the Azure Compute module using go get. ```shell go get github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5 ```