{"id":21042693,"url":"https://github.com/yugabytedb-samples/yugabyte-simple-go-app","last_synced_at":"2025-05-15T17:31:04.279Z","repository":{"id":46264635,"uuid":"453190336","full_name":"YugabyteDB-Samples/yugabyte-simple-go-app","owner":"YugabyteDB-Samples","description":"A simple Go app that connects to a YugabyteDB database cluster and performs basic CRUD operations.","archived":false,"fork":false,"pushed_at":"2024-07-16T16:25:38.000Z","size":216,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":64,"default_branch":"main","last_synced_at":"2024-07-16T20:17:11.959Z","etag":null,"topics":["cloud-native","demos","distributed-database","distributed-sql","go","yugabyte","yugabytedb"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/YugabyteDB-Samples.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-01-28T19:23:02.000Z","updated_at":"2024-07-16T16:25:41.000Z","dependencies_parsed_at":"2022-09-24T15:51:37.207Z","dependency_job_id":null,"html_url":"https://github.com/YugabyteDB-Samples/yugabyte-simple-go-app","commit_stats":null,"previous_names":["yugabyte/yugabyte-simple-go-app"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YugabyteDB-Samples%2Fyugabyte-simple-go-app","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YugabyteDB-Samples%2Fyugabyte-simple-go-app/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YugabyteDB-Samples%2Fyugabyte-simple-go-app/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YugabyteDB-Samples%2Fyugabyte-simple-go-app/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/YugabyteDB-Samples","download_url":"https://codeload.github.com/YugabyteDB-Samples/yugabyte-simple-go-app/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225365975,"owners_count":17462973,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cloud-native","demos","distributed-database","distributed-sql","go","yugabyte","yugabytedb"],"created_at":"2024-11-19T14:08:41.445Z","updated_at":"2024-11-19T14:08:42.033Z","avatar_url":"https://github.com/YugabyteDB-Samples.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Simple Go Application for YugabyteDB\n\nThe application connects to your YugabyteDB instance via \n[Go PostgreSQL driver](https://docs.yugabyte.com/latest/reference/drivers/ysql-client-drivers/#go-postgresql-driver-pq) and performs basic SQL \noperations. The instructions below are provided for [YugabyteDB Aeon](https://cloud.yugabyte.com/) deployments. \nIf you use a different type of deployment, then update the `sample-app.go` file with proper connection parameters.\n\n## Prerequisites\n\n* Go version 1.17.6 or later is preffered. Earlier versions should work as well.\n* Command line tool or your favourite IDE, such as Visual Studio Code.\n\n## Start YugabyteDB Aeon Cluster\n\n* [Start YugabyteDB Aeon](https://docs.yugabyte.com/latest/yugabyte-cloud/cloud-quickstart/qs-add/) instance. Free tier exists.\n* Add an IP address of your machine/laptop to the [IP allow list](https://docs.yugabyte.com/latest/yugabyte-cloud/cloud-secure-clusters/add-connections/#manage-ip-allow-lists)\n\n## Clone Application Repository\n\nClone the application to your machine:\n\n```bash\ngit clone https://github.com/YugabyteDB-Samples/yugabyte-simple-go-app.git \u0026\u0026 cd yugabyte-simple-go-app\n```\n\n## Provide Cluster Connection Parameters\n\nThe application needs to establish a secured connection to your YugabyteDB Aeon instance.\n\nOpen the `sample-app.go` file and specify the following configuration parameters:\n* `host` - the hostname of your instance.\n* `port` - the port number of your instance (the default is `5433`).\n* `dbUser` - the username for your instance.\n* `dbPassword` - the database password.\n* `sslMode` - the SSL mode. Set to `verify-full` for YugabyteDB Aeon deployments.\n* `sslRootCert` - a full path to your CA root cert (for example, `/Users/dmagda/certificates/root.crt`) \n\nNote, you can easily find all the settings on the YugabyteDB Aeon dashboard:\n\n![image](resources/cloud_app_settings.png)\n\n## Build and Run Application\n\n1. Initialize the `GO111MODULE` variable:\n    ```bash\n    export GO111MODULE=auto\n    ```\n2. Import the Go PostgreSQL driver:\n    ```bash\n    go get github.com/lib/pq\n    ```\n3. Run the application:\n    ```bash\n    go run sample-app.go\n    ```\n\nUpon successful execution, you will see output similar to the following:\n\n```bash\n\u003e\u003e\u003e\u003e Successfully connected to YugabyteDB!\n\u003e\u003e\u003e\u003e Successfully created table DemoAccount.\n\u003e\u003e\u003e\u003e Selecting accounts:\nname = Jessica, age = 28, country = USA, balance = 10000\nname = John, age = 28, country = Canada, balance = 9000\n\u003e\u003e\u003e\u003e Transferred 800 between accounts.\n\u003e\u003e\u003e\u003e Selecting accounts:\nname = Jessica, age = 28, country = USA, balance = 9200\nname = John, age = 28, country = Canada, balance = 9800\n```\n\n## Explore App Logic\n\nCongrats! You've successfully executed a simple Go app that works with YugabyteDB.\n\nNow, explore the source code of `sample-app.go`:\n1. `main` function - establishes a connection with your cloud instance via Go PostgreSQL driver.\n2. `createDatabase` function - creates a table and populates it with sample data.\n3. `selectAccounts` function - queries the data with SQL `SELECT` statements.\n4. `transferMoneyBetweenAccounts` function - updates records consistently with distributed transactions.\n\n## Questions or Issues?\n\nHaving issues running this application or want to learn more from Yugabyte experts?\n\nJoin [our Slack channel](https://communityinviter.com/apps/yugabyte-db/register),\nor raise a question on StackOverflow and tag the question with `yugabytedb`!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyugabytedb-samples%2Fyugabyte-simple-go-app","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyugabytedb-samples%2Fyugabyte-simple-go-app","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyugabytedb-samples%2Fyugabyte-simple-go-app/lists"}