API for the Metadata Completeness Dashboard
The API requires a tunnel into OpenSearch. This can be set up using the instructions here: https://datacite.atlassian.net/wiki/spaces/DAT/pages/1038811137/How+to+SSH+tunnel+to+ElasticSearch.
You may need to prepend 0.0.0.0 to your local forward in the .ssh/config to allow Docker to connect to OpenSearch:
Host es-stage
...
LocalForward 0.0.0.0:9202 ...
ssh es-stagedocker-compose --profile dev up(in a separate terminal)
The API is served on http://localhost:8080/
Currently there is only one endpoint at the root
Example URL that fetches present and distribution aggregations for DataCite, along with a test query:
http://localhost:8080/?client_id=datacite.datacite&present=creators,creators.name&distribution=types.resourceTypeGeneral&query=test
Supported Query Parameters
client_id: stringprovider_id: stringquery: stringpresent: []string - comma separated list of fields for which to fetch the present/absent countsdistribution: []string - comma separated list of fields for which to fetch the distribution valuesdistribution_size: number - specifies the number of top results to return for each distribution field
net/http (Standard library for API routing)
I chose to use the standard net/http library because the needs for thes project are minimal. If it needs more features in the future - such as middleware or auth - I would switch to the Chi framework
defensestation/osquery (An idiomatic Go query builder for OpenSearch)
Without this package, writing OpenSearch queries in Go is quite tedious, especially if you need to do anything conditionally.