Skip to content

Latest commit

 

History

History
50 lines (37 loc) · 1.26 KB

README.md

File metadata and controls

50 lines (37 loc) · 1.26 KB

go-cosmosdb

Minimal go cosmosdb rest client generator. Repository helps to generate go clients for cosmosdb based on the go structs.

https://docs.microsoft.com/en-gb/rest/api/cosmos-db

Tests

Tests expects CosmosDB database to to be present.

  1. Create cosmosdb for our example:
# create resource group
az group create --name  go-cosmosdb-test-rg --location eastus
# create cosmosdb
az cosmosdb create --name go-cosmosdb-test --resource-group go-cosmosdb-test-rg
  1. Create env file from env.example example
export RESOURCEGROUP=go-cosmosdb-test-rg
export COSMOSDB_ACCOUNT=go-cosmosdb-test
export COSMOSDB_KEY=$(az cosmosdb keys list -g $RESOURCEGROUP -n $COSMOSDB_ACCOUNT --query primaryMasterKey -o tsv)
  1. Run test
source ./env
make test

Example

See example/hello-world folder for code example.

Clients are generated by executing make generate. Generators are defined in example/cosmosdb/generate.go where we tell library to generate us clients for Person and People structures/documents.

//go:generate go run github.com/julienstroheker/go-cosmosdb/cmd/gencosmosdb github.com/julienstroheker/go-cosmosdb/example/types,Person,People
//go:generate gofmt -s -w .

Run example:

source ./env
go run ./example/hello-world