# README
Sheets
Lightweight Google Spreadsheets Client written in Go.
This package is under active development and a work-in-progress project. You should NOT use it on production. Please consider using the official Google's Sheets client for Go instead.
Installation
The only requirement is the Go Programming Language.
$ go get github.com/kataras/sheets@latest
Getting Started
First of all, navigate to https://developers.google.com/sheets/api and enable the Sheets API Service in your Google Console. Place the secret client service account or token file as client_secret.json
near the executable example.
Example Code:
package main
import (
"context"
"time"
"github.com/kataras/sheets"
)
func main() {
ctx := context.TODO()
// or .Token(ctx, ...)
client := sheets.NewClient(sheets.ServiceAccount(ctx, "client_secret.json"))
var (
spreadsheetID := "1Ku0YXrcy8Nqmji7ABS8AmLAyxP5duQIRwmaAJAqyMYY"
dataRange := "NamedRange or selectors like A1:E4 or *"
records []struct{
Timestamp time.Time
Email string
Username string
IgnoredMe string `sheets:"-"`
}{}
)
// Fill the "records" slice from a spreadsheet of one or more data range.
err := client.ReadSpreadsheet(ctx, &records, spreadsheetID, dataRange)
if err != nil {
panic(err)
}
// Update a spreadsheet on specific range.
updated, err := client.UpdateSpreadsheet(ctx, spreadsheetID, sheets.ValueRange{
Range: "A2:Z",
MajorDimension: sheets.Rows,
Values: [][]interface{}{
{"updated record value: 1.1", "updated record value: 1.2"},
{"updated record value: 2.1", "updated record value: 2.2"},
},
})
// Clears record values of a spreadsheet.
cleared, err := client.ClearSpreadsheet(ctx, spreadsheetID, "A1:E5")
// [...]
}
License
This software is licensed under the MIT License.
# Functions
DecodeValueRange binds "rangeValues" to the "dest" pointer of a struct instance.
IsResourceError reports whether "target" is "e" ResourceError.
IsStatusError reports whether a "target" error is type of `ResourceError` and the status code is the provided "statusCode" one.
NewClient creates and returns a new spreadsheet HTTP Client.
ServiceAccount is an oauth2 authentication function which can be passed on the `New` package-level function.
Token is an oauth2 authentication function which can be passed on the `New` package-level function.
# Constants
Grid is a Sheet type.
Rows is the default "ROWS" ValueRange.MajorDimension value.
ScopeReadOnly is the readonly oauth2 scope.
ScopeReadWrite is the full-access oauth2 scope.
# Variables
ErrOK can be returned from a custom `FieldDecoder` when it should use the default implementation to decode a specific struct's field.
# Structs
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Client holds the google spreadsheet custom API Client.
No description provided by the author
Header is the row's header of a struct field.
No description provided by the author
No description provided by the author
ResourceError is a Client type error.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Interfaces
FieldDecoder is an inteface which a struct can implement to select custom decode implementation instead of the default one, if `ErrOK` is returned then it will fill the field with the default implementation.
A RequestOption can be passed on `Do` method to modify a Request.