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 expects CosmosDB database to to be present.
- 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
- Create
env
file fromenv.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)
- Run test
source ./env
make test
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/jewzaam/go-cosmosdb/cmd/gencosmosdb github.com/jewzaam/go-cosmosdb/example/types,Person,People
//go:generate gofmt -s -w .
Run example:
source ./env
go run ./example/hello-world