Skip to content
Sanity client for Go.
Go
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
LICENSE
README.md
callbacks.go
client.go
errors.go
go.mod
go.sum
params.go
queries.go
utils.go

README.md

Sanity client in Go

Under development! For developers with an adventurous spirit only.

This is a client for Sanity written in Go.

Using

See the API reference for the full documentation.

package main

import (
  "log"
  "context"

  sanity "github.com/sanity-io/client-go"
)

func main() {
  client, err := sanity.New("zx3vzmn!",
    sanity.WithCallbacks(sanity.Callbacks{
      OnQueryResult: func(result *sanity.QueryResult) {
        log.Printf("Sanity queried in %d ms!", result.Ms)
      },
    }),
    sanity.WithToken("mytoken"),
    sanity.WithDataset("production"))
  if err != nil {
    log.Fatal(err)
  }

  var project struct {
    ID    string `json:"_id"`
    Title string
  }
  if err = client.Query(context.Background(), "*[_type == 'project' && _id == $id][0]", &project,
    sanity.Param("id", "123")); 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 file.

You can’t perform that action at this time.