https://github.com/sanity-io/client-go
Sanity client for Go.
https://github.com/sanity-io/client-go
go sanity-io
Last synced: 9 months ago
JSON representation
Sanity client for Go.
- Host: GitHub
- URL: https://github.com/sanity-io/client-go
- Owner: sanity-io
- License: mit
- Created: 2019-09-26T20:41:34.000Z (almost 7 years ago)
- Default Branch: main
- Last Pushed: 2025-07-05T13:44:54.000Z (about 1 year ago)
- Last Synced: 2025-10-02T06:56:46.639Z (9 months ago)
- Topics: go, sanity-io
- Language: Go
- Homepage: https://www.sanity.io
- Size: 45.9 KB
- Stars: 18
- Watchers: 15
- Forks: 6
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Sanity client in Go
> **Under development!** For developers *with an adventurous spirit only*.
This is a client for [Sanity](https://www.sanity.io) written in Go.
## Using
See the [API reference](https://godoc.org/github.com/sanity-io/client-go) for the full documentation.
```go
package main
import (
"context"
"log"
sanity "github.com/sanity-io/client-go"
)
func main() {
client, err := sanity.VersionV20210325.NewClient("zx3vzmn!", sanity.DefaultDataset,
sanity.WithCallbacks(sanity.Callbacks{
OnQueryResult: func(result *sanity.QueryResult) {
log.Printf("Sanity queried in %d ms!", result.Time.Milliseconds())
},
}),
sanity.WithToken("mytoken"))
if err != nil {
log.Fatal(err)
}
var project struct {
ID string `json:"_id"`
Title string
}
result, err := client.
Query("*[_type == 'project' && _id == $id][0]").
Param("id", "123").
Do(context.Background())
if err != nil {
log.Fatal(err)
}
if err := result.Unmarshal(&project); err != nil {
log.Fatal(err)
}
log.Printf("Project: %+v", project)
}
```
## Installation
```
go get github.com/sanity-io/client-go
```
## Requirements
Go 1.13 or later.
# License
See [`LICENSE`](https://github.com/sanity-io/client-go/blob/master/LICENSE) file.