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 (
	"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 file.

About

Sanity client for Go.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages