### Basic WebService Setup and Route Definition Source: https://github.com/dotmesh-io/dotmesh/blob/master/vendor/github.com/emicklei/go-restful/README.md Demonstrates how to initialize a WebService, set its path and content types, and define a GET route with a path parameter. This is a foundational example for setting up API endpoints. ```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{})) ``` -------------------------------- ### Go Get Installation Source: https://github.com/dotmesh-io/dotmesh/blob/master/vendor/github.com/dsnet/compress/README.md Install the compression library using the Go get command. Requires Go 1.9 or higher. ```bash go get -u github.com/dsnet/compress ``` -------------------------------- ### Install pb.v1 Package Source: https://github.com/dotmesh-io/dotmesh/blob/master/cmd/dm/vendor/gopkg.in/cheggaaa/pb.v1/README.md Install the pb.v1 package using the go get command. ```bash go get gopkg.in/cheggaaa/pb.v1 ``` -------------------------------- ### Install go-metrics Source: https://github.com/dotmesh-io/dotmesh/blob/master/cmd/dm/vendor/github.com/rcrowley/go-metrics/README.md Command to install the go-metrics library using go get. ```sh go get github.com/rcrowley/go-metrics ``` -------------------------------- ### Install GoDotEnv as a Library Source: https://github.com/dotmesh-io/dotmesh/blob/master/vendor/github.com/joho/godotenv/README.md Install the GoDotEnv library using the go get command. ```shell go get github.com/joho/godotenv ``` -------------------------------- ### Install GoDotEnv as a Binary Source: https://github.com/dotmesh-io/dotmesh/blob/master/vendor/github.com/joho/godotenv/README.md Install the GoDotEnv command-line tool using the go get command. ```shell go get github.com/joho/godotenv/cmd/godotenv ``` -------------------------------- ### Install etcd/clientv3 Source: https://github.com/dotmesh-io/dotmesh/blob/master/vendor/github.com/coreos/etcd/clientv3/README.md Install the etcd/clientv3 Go package using the go get command. ```bash go get github.com/coreos/etcd/clientv3 ``` -------------------------------- ### Install bbolt Source: https://github.com/dotmesh-io/dotmesh/blob/master/vendor/github.com/coreos/bbolt/README.md Install the bbolt library and command-line utility using go get. ```sh go get github.com/coreos/bbolt/... ``` -------------------------------- ### Install Diskv using Go Get Source: https://github.com/dotmesh-io/dotmesh/blob/master/cmd/operator/vendor/github.com/peterbourgon/diskv/README.md Installs the diskv package using the Go build tool. Ensure Go is installed first. ```bash $ go get github.com/peterbourgon/diskv ``` -------------------------------- ### Install NUID Source: https://github.com/dotmesh-io/dotmesh/blob/master/vendor/github.com/nats-io/nuid/README.md Use the go get command to install the NUID library. ```bash $ go get github.com/nats-io/nuid ``` -------------------------------- ### Install Mergo Source: https://github.com/dotmesh-io/dotmesh/blob/master/cmd/operator/vendor/github.com/imdario/mergo/README.md Use 'go get' to install the Mergo library. Then, import it into your Go code. ```go go get github.com/imdario/mergo // use in your .go code import ( "github.com/imdario/mergo" ) ``` -------------------------------- ### Install go-codec Library Source: https://github.com/dotmesh-io/dotmesh/blob/master/vendor/github.com/hashicorp/go-msgpack/codec/README.md Install the go-codec library using the go get command. This command fetches and installs the specified package and its dependencies. ```bash go get github.com/ugorji/go/codec ``` -------------------------------- ### Complete Runnable Mux Server Example Source: https://github.com/dotmesh-io/dotmesh/blob/master/cmd/operator/vendor/github.com/gorilla/mux/README.md Provides a full, runnable example of a small HTTP server using Gorilla Mux. ```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 pgzip Source: https://github.com/dotmesh-io/dotmesh/blob/master/vendor/github.com/klauspost/pgzip/README.md Install the pgzip library using the go get command. You may also need to update its dependency. ```go go get github.com/klauspost/pgzip/... ``` ```go go get -u github.com/klauspost/compress ``` -------------------------------- ### Install json-iterator/go Source: https://github.com/dotmesh-io/dotmesh/blob/master/cmd/operator/vendor/github.com/json-iterator/go/README.md Install the json-iterator/go library using the go get command. ```go go get github.com/json-iterator/go ``` -------------------------------- ### Initialize Helm and Install GitLab Source: https://github.com/dotmesh-io/dotmesh/blob/master/kubernetes/gke-demo.md Initialize the Helm package manager, add the GitLab Helm repository, and install GitLab using a custom values file. ```bash helm init helm repo add gitlab https://charts.gitlab.io helm install --namespace gitlab --name gitlab -f gitlab/helm/values.yaml gitlab/gitlab ``` -------------------------------- ### Install etcd/client Go Package Source: https://github.com/dotmesh-io/dotmesh/blob/master/cmd/dm/vendor/github.com/coreos/etcd/client/README.md Use 'go get' to install the etcd client library. This command fetches and installs the package, making it available for import in your Go projects. ```bash go get github.com/coreos/etcd/client ``` -------------------------------- ### Setup Discovery Service Source: https://github.com/dotmesh-io/dotmesh/blob/master/docs/dev-commands.md Clones the discovery.dotmesh.io repository and starts a local discovery service. This is necessary for running tests offline. ```bash cd ~/ git clone git@github.com:dotmesh-io/discovery.dotmesh.io cd discovery.dotmesh.io ./start-local.sh ``` -------------------------------- ### Install blang/semver Source: https://github.com/dotmesh-io/dotmesh/blob/master/vendor/github.com/blang/semver/README.md Install the library using go get. It is recommended to vendor dependencies or fix on a specific version tag. ```bash $ go get github.com/blang/semver ``` -------------------------------- ### Install Bolt DB Source: https://github.com/dotmesh-io/dotmesh/blob/master/vendor/github.com/boltdb/bolt/README.md Install Bolt DB and its command-line utility using go get. ```sh $ go get github.com/boltdb/bolt/... ``` -------------------------------- ### Install Cobra Library Source: https://github.com/dotmesh-io/dotmesh/blob/master/cmd/dm/vendor/github.com/spf13/cobra/README.md Install the latest version of the Cobra library using go get. ```bash > go get -v github.com/spf13/cobra/cobra ``` -------------------------------- ### Install ugorji/go/codec Source: https://github.com/dotmesh-io/dotmesh/blob/master/cmd/dm/vendor/github.com/ugorji/go/codec/README.md Install the codec library using go get. Use the 'unsafe' tag to enable bypassing allocation and copying overhead for byte to string conversions during decoding. ```bash go get github.com/ugorji/go/codec ``` ```bash go install -tags=unsafe github.com/ugorji/go/codec ``` -------------------------------- ### Install XZ Package Source: https://github.com/dotmesh-io/dotmesh/blob/master/vendor/github.com/xi2/xz/README.md Download and install the XZ package using the Go tool. ```bash go get github.com/xi2/xz ``` -------------------------------- ### Install Semver Library Source: https://github.com/dotmesh-io/dotmesh/blob/master/cmd/dm/vendor/github.com/blang/semver/README.md Use 'go get' to install the semver library. It's recommended to vendor dependencies or fix to a specific version tag. ```bash go get github.com/blang/semver ``` -------------------------------- ### Install gRPC-Go Package Source: https://github.com/dotmesh-io/dotmesh/blob/master/vendor/google.golang.org/grpc/README.md Installs the gRPC-Go library using the go get command. Requires Go and a configured Go workspace. ```bash $ go get -u google.golang.org/grpc ``` -------------------------------- ### Install Gorilla Mux Source: https://github.com/dotmesh-io/dotmesh/blob/master/cmd/operator/vendor/github.com/gorilla/mux/README.md Install the gorilla/mux package using the go get command. Ensure your Go toolchain is correctly configured. ```go go get -u github.com/gorilla/mux ``` -------------------------------- ### Ubuntu 18.04 Setup for Dotmesh Development Source: https://github.com/dotmesh-io/dotmesh/blob/master/docs/dev-commands.md Installs Go, Docker, and other necessary packages for Dotmesh development on Ubuntu 18.04. Includes Docker configuration and systemctl restarts. ```bash # install go snap install go --classic # install docker apt-get update apt-get install apt-transport-https ca-certificates curl software-properties-common curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - apt-key fingerprint 0EBFCD88 add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) \ stable" apt-get update apt-get install docker-ce # configure docker cat << EOT > /etc/docker/daemon.json { "storage-driver": "overlay2", "insecure-registries": ["$(hostname).local:80"] } EOT systemctl restart docker # install packages apt install zfsutils-linux jq moreutils echo 'vm.max_map_count=262144' >> /etc/sysctl.conf sysctl vm.max_map_count=262144 # install docker-compose sudo curl -L https://github.com/docker/compose/releases/download/1.22.0/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose sudo chmod +x /usr/local/bin/docker-compose # update hosts cat <> /etc/hosts 127.0.0.1 $(hostname).local EOF # install bazel apt-get -y install pkg-config zip g++ zlib1g-dev unzip python git-core curl -L -o bazel-installer.sh https://github.com/bazelbuild/bazel/releases/download/0.15.2/bazel-0.15.2-installer-linux-x86_64.sh chmod +x bazel-installer.sh && ./bazel-installer.sh --user ``` -------------------------------- ### Install Datamesh Locally Source: https://github.com/dotmesh-io/dotmesh/blob/master/kubernetes/gke-demo.md Download and install the Datamesh CLI locally. Ensure the binary is executable and then initialize a local Datamesh cluster. ```bash sudo curl -o /usr/local/bin/dm \ https://get.datamesh.io/$(uname -s)/dm sudo chmod +x /usr/local/bin/dm dm cluster init ``` -------------------------------- ### Install mapstructure Go Library Source: https://github.com/dotmesh-io/dotmesh/blob/master/vendor/github.com/mitchellh/mapstructure/README.md Use 'go get' to install the mapstructure library. This is the standard method for obtaining Go packages. ```bash go get github.com/mitchellh/mapstructure ``` -------------------------------- ### Install go-ini/ini (Latest Changes) Source: https://github.com/dotmesh-io/dotmesh/blob/master/cmd/dm/vendor/github.com/go-ini/ini/README.md Use this command to get the latest development version of the go-ini/ini library. Add the -u flag for future updates. ```bash $ go get github.com/go-ini/ini ``` -------------------------------- ### Install Dotmesh Client Source: https://github.com/dotmesh-io/dotmesh/blob/master/README.md Downloads and installs the dotmesh client binary to /usr/local/bin/dm. Ensure you have curl installed. ```plain sudo curl -sSL -o /usr/local/bin/dm \ https://get.dotmesh.io/$(uname -s)/dm ``` -------------------------------- ### Install and Configure GitLab Runner Source: https://github.com/dotmesh-io/dotmesh/blob/master/docs/dev-commands.md Installs the GitLab runner binary, sets permissions, and installs it as a service. The runner is configured to run as the gitlab-runner user. ```bash # install gitlab runner sudo wget -O /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64 sudo chmod +x /usr/local/bin/gitlab-runner sudo gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner ``` -------------------------------- ### Install go-sockaddr CLI Source: https://github.com/dotmesh-io/dotmesh/blob/master/vendor/github.com/hashicorp/go-sockaddr/README.md Installs the go-sockaddr command-line utility. This tool exposes most of the library's functionality. ```bash go get -u github.com/hashicorp/go-sockaddr/cmd/sockaddr ``` -------------------------------- ### Setup Dotmesh Instrumentation Source: https://github.com/dotmesh-io/dotmesh/blob/master/docs/dev-commands.md Clones the dotmesh-instrumentation repository and runs its setup script. This includes setting up a local registry required for integration tests. ```bash cd ~/ git clone git@github.com:dotmesh-io/dotmesh-instrumentation cd dotmesh-instrumentation ./up.sh ``` -------------------------------- ### Install Swagger Service Configuration Source: https://github.com/dotmesh-io/dotmesh/blob/master/vendor/github.com/emicklei/go-restful-swagger12/README.md Configuration for installing the Swagger service to serve the API specification. Ensure the SwaggerPath and SwaggerFilePath are set correctly for your project. ```go config := swagger.Config{ WebServices: restful.RegisteredWebServices(), ApiPath: "/apidocs.json", SwaggerPath: "/apidocs/", SwaggerFilePath: "/Users/emicklei/Projects/swagger-ui/dist"} swagger.InstallSwaggerService(config) ``` -------------------------------- ### GitLab Runner Registration Example Source: https://github.com/dotmesh-io/dotmesh/blob/master/docs/dev-commands.md An example of the interactive prompts and expected inputs for registering a GitLab runner. This includes providing the coordinator URL, token, description, tags, and executor type. ```bash gitlab-runner@gitlab-dawdler:~$ sudo gitlab-runner register Running in system-mode. Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/): https://gitlab.dotmesh.com/ Please enter the gitlab-ci token for this runner: XXX Please enter the gitlab-ci description for this runner: [gitlab-dawdler]: Please enter the gitlab-ci tags for this runner (comma separated): fast,ubuntu-bionic Registering runner... succeeded runner=WyJjQ2zg Please enter the executor: docker-ssh, parallels, shell, ssh, virtualbox, kubernetes, docker, docker-ssh+machine, docker+machine: shell Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded! ``` -------------------------------- ### Basic Diskv Usage Example Source: https://github.com/dotmesh-io/dotmesh/blob/master/cmd/operator/vendor/github.com/peterbourgon/diskv/README.md Demonstrates the simplest way to initialize and use a diskv store, including 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 govalidator Package Source: https://github.com/dotmesh-io/dotmesh/blob/master/vendor/github.com/asaskevich/govalidator/README.md Install the govalidator package using go get. You can also get a specified release using gopkg.in. ```bash go get github.com/asaskevich/govalidator or you can get specified release of the package with `gopkg.in`: go get gopkg.in/asaskevich/govalidator.v4 ``` -------------------------------- ### Basic Example with Logging and Compression Source: https://github.com/dotmesh-io/dotmesh/blob/master/vendor/github.com/gorilla/handlers/README.md Demonstrates how to use LoggingHandler for request logging and CompressHandler for response compression in a Go HTTP server. Requires importing the 'net/http' and 'github.com/gorilla/handlers' packages. ```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)) } ``` -------------------------------- ### Initialize Local Git Repository Source: https://github.com/dotmesh-io/dotmesh/blob/master/kubernetes/gke-demo.md Copy the example application, initialize a new Git repository, add all files, and create an initial commit. ```bash cp -r example_app ~/dm_example_app cd ~/dm_example_app git init git add -A git commit -m "initial commit" ``` -------------------------------- ### Install urlesc Package Source: https://github.com/dotmesh-io/dotmesh/blob/master/cmd/dotmesh-server/pkg/dind-dynamic-provisioning/vendor/github.com/PuerkitoBio/urlesc/README.md Use 'go get' to install the urlesc package. This command fetches and installs the package and its dependencies. ```go go get github.com/PuerkitoBio/urlesc ``` -------------------------------- ### Configure Codec Handles and Extensions Source: https://github.com/dotmesh-io/dotmesh/blob/master/vendor/github.com/ugorji/go/codec/README.md Demonstrates how to create and configure codec handles (like Binc, Msgpack, Cbor) and set up custom extensions for specific types, such as time.Time for Msgpack. ```go 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) ``` -------------------------------- ### RPC Client Codec Setup Source: https://github.com/dotmesh-io/dotmesh/blob/master/vendor/github.com/ugorji/go/codec/README.md Demonstrates how to establish an RPC client connection and create a client codec using either the generic Go RPC codec or a Msgpack-specific one. ```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) ``` -------------------------------- ### RPC Client Setup with go-codec Source: https://github.com/dotmesh-io/dotmesh/blob/master/cmd/dm/vendor/github.com/ugorji/go/codec/README.md Demonstrates how to establish an RPC client connection using go-codec, dialing a server and creating an RPC client with either the standard Go RPC codec or Msgpack-spec RPC codec. ```Go conn, err = net.Dial("tcp", "localhost:5555") rpcCodec := codec.GoRpc.ClientCodec(conn, h) //OR rpcCodec := codec.MsgpackSpecRpc.ClientCodec(conn, h) client := rpc.NewClientWithCodec(rpcCodec) ``` -------------------------------- ### RPC Server Setup with go-codec Source: https://github.com/dotmesh-io/dotmesh/blob/master/cmd/dm/vendor/github.com/ugorji/go/codec/README.md Illustrates how to set up an RPC server using go-codec, accepting connections and serving RPC requests with either the standard Go RPC codec or Msgpack-spec RPC codec. ```Go go func() { for { conn, err := listener.Accept() rpcCodec := codec.GoRpc.ServerCodec(conn, h) //OR rpcCodec := codec.MsgpackSpecRpc.ServerCodec(conn, h) rpc.ServeCodec(rpcCodec) } }() ``` -------------------------------- ### Basic etcd Client Usage in Go Source: https://github.com/dotmesh-io/dotmesh/blob/master/cmd/dm/vendor/github.com/coreos/etcd/client/README.md Demonstrates how to initialize an etcd client, create a keys API, and perform basic operations like setting and getting a key-value pair. Ensure etcd is running and accessible at the specified endpoint. ```go package main import ( "log" "time" "golang.org/x/net/context" "github.com/coreos/etcd/client" ) func main() { cfg := client.Config{ Endpoints: []string{"http://127.0.0.1:2379"}, Transport: client.DefaultTransport, // set timeout per request to fail fast when the target endpoint is unavailable HeaderTimeoutPerRequest: time.Second, } c, err := client.New(cfg) if err != nil { log.Fatal(err) } kapi := client.NewKeysAPI(c) // set "/foo" key with "bar" value log.Print("Setting '/foo' key with 'bar' value") resp, err := kapi.Set(context.Background(), "/foo", "bar", nil) if err != nil { log.Fatal(err) } else { // print common key info log.Printf("Set is done. Metadata is %q\n", resp) } // get "/foo" key's value log.Print("Getting '/foo' key value") resp, err = kapi.Get(context.Background(), "/foo", nil) if err != nil { log.Fatal(err) } else { // print common key info log.Printf("Get is done. Metadata is %q\n", resp) // print value log.Printf("%q key has %q value\n", resp.Node.Key, resp.Node.Value) } } ``` -------------------------------- ### Basic Connection Multiplexing with cmux Source: https://github.com/dotmesh-io/dotmesh/blob/master/vendor/github.com/soheilhy/cmux/README.md Demonstrates how to set up a listener, create a cmux instance, match different protocols (gRPC, HTTP, Any), and serve them concurrently using their respective servers. This is the primary usage pattern for cmux. ```go import ( "log" "net" "google.golang.org/grpc" "net/http" "github.com/soheilhy/cmux" "path/to/your/grpcs/package" "path/to/your/rpc/package" ) // Create the main listener. l, err := net.Listen("tcp", ":23456") if err != nil { log.Fatal(err) } // Create a cmux. m := cmux.New(l) // Match connections in order: // First grpc, then HTTP, and otherwise Go RPC/TCP. grpcL := m.Match(cmux.HTTP2HeaderField("content-type", "application/grpc")) httpL := m.Match(cmux.HTTP1Fast()) trpcL := m.Match(cmux.Any()) // Any means anything that is not yet matched. // Create your protocol servers. grpcS := grpc.NewServer() grpchello.RegisterGreeterServer(grpcs, &server{}) httpS := &http.Server{ Handler: &helloHTTP1Handler{}, } trpcS := rpc.NewServer() trpcS.Register(&ExampleRPCRcvr{}) // Use the muxed listeners for your servers. go grpcS.Serve(grpcL) go httpS.Serve(httpL) go trpcS.Accept(trpcL) // Start serving! m.Serve() ``` -------------------------------- ### RPC Server Codec Setup Source: https://github.com/dotmesh-io/dotmesh/blob/master/vendor/github.com/ugorji/go/codec/README.md Illustrates how to set up an RPC server codec using either the generic Go RPC codec or a Msgpack-specific one, integrating with the standard net/rpc package. ```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) } }() ``` -------------------------------- ### Install Cobra CLI Source: https://github.com/dotmesh-io/dotmesh/blob/master/vendor/github.com/spf13/cobra/README.md Install the latest version of the Cobra generator executable and the library using `go get`. ```bash go get -u github.com/spf13/cobra/cobra ``` -------------------------------- ### Create a KVDB Instance Source: https://github.com/dotmesh-io/dotmesh/blob/master/vendor/github.com/portworx/kvdb/README.md Demonstrates how to create a new instance of the Kvdb object, specifying the key-value store implementation, base path, discovery endpoints, and options. Includes a panic handler for critical errors. ```Go package main import ( "github.com/portworx/kvdb" "github.com/portworx/kvdb/etcd/v3" "github.com/libopenstorage/openstorage/pkg/dbg" ) func getKvdb( kvdbName string, // Use one of the kv store implementation names basePath string, // The path under which all the keys will be created by this kv instance discoveryEndpoints []string, // A list of kv store endpoints options map[string]string, // Options that need to be passed to the kv store panicHandler kvdb.FatalErrorCB, // A callback function to execute when the library needs to panic ) (kvdb.Kvdb, error) { kv, err := kvdb.New( kvdbName, basePath, discoveryEndpoints, options, panicHandler, ) return kv, err } type A struct { a1 string a2 int } func main() { // An example kvdb using etcd v3 as a key value store kv, err := getKvdb( v3.Name, "root/", []{"127.0.0.1:2379"}, nil, dbg.Panicf, ) if err != nil { fmt.Println("Failed to create a kvdb instance: ", err) return } // Put a key value pair foo=bar a := &A{"bar", 1} _, err = kv.Put("foo", &a, 0) if err != nil { fmt.Println("Failed to put a key in kvdb: ", err) return } // Get a key value := A{} _, err = kv.GetVal("foo", &value) if err != nil { fmt.Println("Failed to get a key from kvdb: ", err) return } } ``` -------------------------------- ### Using Real Clock in Production Source: https://github.com/dotmesh-io/dotmesh/blob/master/vendor/github.com/jonboulle/clockwork/README.md Illustrates how to inject the real clock implementation in production builds. ```go my_func(clockwork.NewRealClock()) ``` -------------------------------- ### Build and Push Installer Image Source: https://github.com/dotmesh-io/dotmesh/blob/master/kubernetes/gke-demo.md Build the Datamesh Kubernetes installer Docker image. This is typically used for rebuilding images for the setup. ```bash make k8s.installer ``` -------------------------------- ### Install NATS Go Client and Server Source: https://github.com/dotmesh-io/dotmesh/blob/master/tests/vendor/github.com/nats-io/go-nats/README.md Installs the NATS Go client and the NATS server (gnatsd) using the go get command. ```bash # Go client go get github.com/nats-io/go-nats # Server go get github.com/nats-io/gnatsd ``` -------------------------------- ### Install YAML dependency Source: https://github.com/dotmesh-io/dotmesh/blob/master/vendor/github.com/imdario/mergo/README.md If tests fail due to a missing package, execute 'go get gopkg.in/yaml.v2'. ```go go get gopkg.in/yaml.v2 ``` -------------------------------- ### Install Swagger Service Configuration Source: https://github.com/dotmesh-io/dotmesh/blob/master/cmd/dynamic-provisioner/vendor/github.com/emicklei/go-restful/swagger/README.md Configure and install the Swagger service to serve the API documentation. Ensure the ApiPath and SwaggerPath match your service endpoints and the SwaggerFilePath points to the downloaded Swagger UI 'dist' folder. ```go config := swagger.Config{ WebServices: restful.RegisteredWebServices(), ApiPath: "/apidocs.json", SwaggerPath: "/apidocs/", SwaggerFilePath: "/Users/emicklei/Projects/swagger-ui/dist"} swagger.InstallSwaggerService(config) ``` -------------------------------- ### Install go-ini/ini (Tagged Revision) Source: https://github.com/dotmesh-io/dotmesh/blob/master/cmd/dm/vendor/github.com/go-ini/ini/README.md Use this command to get a specific tagged version of the go-ini/ini library. ```bash $ go get gopkg.in/ini.v1 ``` -------------------------------- ### Configure Handles and Encode/Decode Source: https://github.com/dotmesh-io/dotmesh/blob/master/cmd/dm/vendor/github.com/ugorji/go/codec/README.md Shows how to create and configure different codec handles (Binc, Msgpack, CBOR) and use them for encoding and decoding data with readers, writers, and byte slices. ```Go 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) ``` -------------------------------- ### Register GitLab Runner Source: https://github.com/dotmesh-io/dotmesh/blob/master/docs/dev-commands.md Registers a new GitLab runner with the specified coordinator URL, token, description, tags, and executor. This command is run after the runner is installed and started. ```bash sudo gitlab-runner start sudo gitlab-runner register ``` -------------------------------- ### Initialize Global Tracer Source: https://github.com/dotmesh-io/dotmesh/blob/master/vendor/github.com/opentracing/opentracing-go/README.md Call this as early as possible in your main function to set up the global tracer implementation. ```go import "github.com/opentracing/opentracing-go" import ".../some_tracing_impl" func main() { opentracing.InitGlobalTracer( // tracing impl specific: some_tracing_impl.New(...), ) ... } ``` -------------------------------- ### Clone and Setup Dotmesh Repositories Source: https://github.com/dotmesh-io/dotmesh/blob/master/docs/dev-commands.md Clones and sets up the dotmesh-instrumentation, dotmesh, and discovery.dotmesh.io repositories. This requires SSH access to the runner and the gitlab-runner user context. ```bash exit exit # you should now have accesss because we added authorized_keys ssh gitlab-runner@ su - gitlab-runner # clone & setup the dotmesh-instrumentation repo cd ~/ git clone git@github.com:dotmesh-io/dotmesh-instrumentation cd dotmesh-instrumentation ./up.sh # clone the dotmesh repo mkdir -p $GOPATH/src/github.com/dotmesh-io cd $GOPATH/src/github.com/dotmesh-io git clone git@github.com:dotmesh-io/dotmesh.git cd dotmesh ./prime.sh # clone & setup the discovery.dotmesh.io repo cd ~/ git clone git@github.com:dotmesh-io/discovery.dotmesh.io cd discovery.dotmesh.io ./start-local.sh ``` -------------------------------- ### Run PostgreSQL with Dotmesh Datadot Source: https://github.com/dotmesh-io/dotmesh/blob/master/README.md Starts a PostgreSQL container, creating a datadot named 'myapp' and mounting its master branch to the container's data directory. Assumes Docker and Dotmesh are installed. ```bash docker run -d --volume-driver dm \ -v myapp:/var/lib/postgresql/data --name postgres postgres:9.6.6 ``` -------------------------------- ### Import and Use Citools in Go Tests Source: https://github.com/dotmesh-io/dotmesh/blob/master/tests/vendor/github.com/dotmesh-io/citools/README.md Import the citools package into your Go test files to utilize its testing utilities. This example shows basic setup for testing default dot selection. ```go import ( "github.com/dotmesh-io/citools" ) func TestDefaultDot(t *testing.T) { // Test default dot select on a totally fresh cluster citools.teardownFinishedTestRuns() f := citools.Federation{citools.NewCluster(1)} citools.startTiming() } ``` -------------------------------- ### Initialize Dependencies and Add Citools Source: https://github.com/dotmesh-io/dotmesh/blob/master/tests/vendor/github.com/dotmesh-io/citools/README.md Use `dep init` to initialize Go dependencies and `dep ensure` to add the citools library and its dependencies. ```bash dep init dep ensure -add github.com/dotmesh-io/citools github.com/dotmesh-io/citools ``` -------------------------------- ### Configuration Loading Logic Source: https://github.com/dotmesh-io/dotmesh/blob/master/vendor/github.com/spf13/cobra/README.md Implement the `initConfig` function to read configuration from a specified file or the user's home directory using Viper. ```go func initConfig() { // Don't forget to read config either from cfgFile or from home directory! if cfgFile != "" { // Use config file from the flag. viper.SetConfigFile(cfgFile) } else { // Find home directory. home, err := homedir.Dir() if err != nil { fmt.Println(err) os.Exit(1) } // Search config in home directory with name ".cobra" (without extension). viper.AddConfigPath(home) viper.SetConfigName(".cobra") } if err := viper.ReadInConfig(); err != nil { fmt.Println("Can't read config:", err) os.Exit(1) } } ```