Skip to content

Latest commit

 

History

History
48 lines (33 loc) · 1.45 KB

File metadata and controls

48 lines (33 loc) · 1.45 KB

Examples

Want to run an example? Follow the instructions below and change the commands based on which example you want to run, etc.

Download an Example

You can copy/paste the examples in any of these subfolders into a local file. You can also just use curl:

# Download an example. Replace /tables/typed/ with whatever example you want to download.
curl -L https://raw.githubusercontent.com/datastax/astra-db-go/main/examples/tables/typed/main.go -o main.go

Initialize a go module and get dependencies

Next, initialize a go module using go mod init and get dependencies (you can use go mod tidy):

# Initialize a go module
go mod init github.com/example/module
# Get dependencies
go mod tidy

Configure the example with your database endpoint / token

Create a .env file with the following values:

ASTRA_DB_API_ENDPOINT="https://my-database-id-my-region.apps.astra.datastax.com"
ASTRA_DB_APPLICATION_TOKEN="AstraCS:myToken"

If you have the Astra CLI installed, you can have it create the .env file for you:

# Replace <db_name> with the name of your database
astra db create-dotenv <db_name> --preset data_api_client 

Run the example

You can now run the example and interact with your database:

# Run the example
go run .