https://github.com/ross-spencer/spargo
SPARQL helper library for Golang
https://github.com/ross-spencer/spargo
cli-app golang-package linked-open-data sparql wikidata
Last synced: about 1 month ago
JSON representation
SPARQL helper library for Golang
- Host: GitHub
- URL: https://github.com/ross-spencer/spargo
- Owner: ross-spencer
- License: apache-2.0
- Created: 2020-01-27T03:26:19.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2021-05-17T06:14:40.000Z (about 5 years ago)
- Last Synced: 2025-12-25T19:37:55.535Z (6 months ago)
- Topics: cli-app, golang-package, linked-open-data, sparql, wikidata
- Language: Go
- Size: 65.4 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# spargo
SPARQL helper library for Golang
[](https://github.com/ross-spencer/spargo/actions/workflows/github-actions.yml)
[](https://godoc.org/github.com/ross-spencer/spargo/pkg/spargo)
[](https://goreportcard.com/report/github.com/ross-spencer/spargo/pkg/spargo)
## .sparql File Format
The .sparql file format can be written as follows, note `#!spargo` is a magic
number when used like this.
```
#!spargo
ENDPOINT=...
# Comment
{sparql query}
```
## spargo interpreter
Borrowing from the above, with spargo reachable via a path such as
`/usr/bin/spargo` then a .sparql file can be configured like an interpretable
script, so:
```
#!/usr/bin/spargo
ENDPOINT=...
# Comment
{sparql query}
```
Lets call it `mysparql.sparql`. It can be run with executable permissions:
```
$ ./mysparql.sparql
```
And a JSON response will be returned to the caller.
## spargo Command
The `spargo` command supports piped input, and there are some example queries
that can help demonstrate that.
In the spargo cmd folder, one can do the following:
```
github.com/ross-spencer/spargo/cmd/spargo$ cat examples/5-describe-wikidata.sparql | ./spargo
Connecting to: https://query.wikidata.org/sparql
Query: #! spargo
# Describe JPEG2000 in Wikidata database.
describe wd:Q931783
...{result}...
```
> **NB.** output via CLI args may be supported in the future. The placeholders
are there, but the capability is not. The user is given clear feedback on this
when run via args.
## spargo Package
The important part of this repository is the `spargo` package. To use it we
can do something like as follows once it is imported.
```golang
package ...
import (
...
...
"github.com/ross-spencer/spargo/pkg/spargo"
)
func ...() {
sparqlMe := spargo.SPARQLClient{}
sparqlMe.ClientInit(url, queryString)
res, _ := sparqlMe.SPARQLGo()
}
```
And the results will be available in the `res` variable to be consumed by your
application.
## License
Apache License 2.0. More info [here](LICENSE).