Skip to content

sanity-io/client-go

Repository files navigation

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.

Releases

No releases published

Packages

 
 
 

Contributors 4

  •  
  •  
  •  
  •  

Languages