Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zshipko/irmin-graphql-go
Go bindings to the Irmin GraphQL API
https://github.com/zshipko/irmin-graphql-go
Last synced: about 1 month ago
JSON representation
Go bindings to the Irmin GraphQL API
- Host: GitHub
- URL: https://github.com/zshipko/irmin-graphql-go
- Owner: zshipko
- License: isc
- Created: 2018-09-28T00:35:57.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2022-08-13T00:17:36.000Z (over 2 years ago)
- Last Synced: 2024-05-01T23:58:28.536Z (7 months ago)
- Language: Go
- Homepage:
- Size: 26.4 KB
- Stars: 5
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# irmin-graphql-go
Go bindings to [Irmin](https://github.com/mirage/irmin) using GraphQL.
## Installation
```shell
$ go get -u github.com/zshipko/irmin-graphql-go
```## Getting started
The following example will print the commit hash of the current `HEAD` of the main branch:
```go
package mainimport (
"fmt"
"context""github.com/zshipko/irmin-graphql-go"
)func main(){
client := irmin.New("http://localhost:8080/graphql", nil)
if client == nil {
panic("Unable to connect to irmin-graphql server")
}main := client.Main(context.Background())
fmt.Println(main.Head.Hash)
}
```## Writing custom queries
`irmin-go` provides many predefined queries, but at some point you may need to define your own query. Thanks to [github.com/shurcooL/graphql](https://github.com/shurcooL/graphql) this is very simple:
```go
package mainimport (
"context"
"log""github.com/shurcooL/graphql"
"github.com/zshipko/irmin-go"
)func main() {
client := irmin.New("http://localhost:8080/graphql", nil)
if client == nil {
panic("Unable to connect to irmin-graphql server")
}var query struct {
Main struct {
Tree struct {
Get *graphql.String `graphql:"get(key: $key)"`
}
}
}keys := map[string]interface{}{
"key": "a/b/c",
}err := client.Client.Query(context.Background(), &query, keys)
if err != nil {
log.Fatal(err)
}if query.Main.Tree.Get == nil {
log.Println("NULL")
} else {
log.Println(*query.Main.Tree.Get)
}
}
```