Connecting to ClickHouse with Go

In this example we will show how you can use the official Go driver for ClickHouse to connect to your cluster. Before you begin, it is imperative to review the general steps and considerations for connecting to a ClickHouse cluster as outlined in Connecting to a ClickHouse Cluster. 

1. First, make sure you have go installed. Run the below command to confirm.

If not installed, download the latest go using curl and then install the package or msi file: 

To find more about the installation process please check out: https://go.dev/doc/install

2. Initialize a module by running the following in command:

3. Copy the below code into the clickhouse-golang-example directory as main.go:

4. Next, run go mod tidy in command:

5. Finally, run the example:

To learn more about ClickHouse Go see https://github.com/ClickHouse/clickhouse-docs/blob/main/docs/integrations/language-clients/go/index.md