package main
import (
"time"
stein "github.com/nasrul21/go-stein"
)
funcmain() {
client:=stein.NewClient(
"https://api.steinhq.com/v1/storages/5cca0542e52a3545102c1665", // STEIN URL // you can set the option nil, if your stein doesn't need authentication&stein.Option{
Username: "user", // your STEIN API usernamePassword: "password", // your STEIN API passwordTimeout: 20*time.Second, // set timeout for Stein Request, default: 15s
},
)
...
}
Read Data
client.Read(sheetName, filter, v)
Arguments
Name
Description
Format
Requirement
sheetName
Your sheet name
String
Required
filter
Filter / Query data by column name
map[string]interface{}
Optional (nil)
v
The result will be given to v
Struct / map[string]interface{}
Required
Example
// set your filterfilter:=map[string]interface{
"ID": 134,
}
result:=&YourStruct{}
status, err:=client.Read("Sheet1", filter, &result)
// if you want to get the data without filter// status, err := client.Read("Sheet1", nil, &result)iferr!=nil {
log.Fatal("Error read from stein: "+err)
return
}
fmt.Printf("HTTP Status: %d \n", status)
fmt.Printf("Result : %v \n", result)
Insert Data / Add Rows
client.Insert(sheetName, body) (status, res, err)
Arguments
Name
Description
Format
Requirement
sheetName
Your sheet's name
String
Required
body
The data you want to add
Array of Struct
Required
Return Value
Name
Description
Format
status
HTTP Status Response
Number (Status Code)
res
Response of updated range
InsertResponse
err
Error message
error
Example
typeEmployeestruct {
Namestring`json:"name"`Departmentstring`json:"department"`Positionstring`json:"position"`
}
employees:= []Employee{
{
Name: "Nasrul",
Department: "Technology",
Position: "Software Engineer",
},
// add another field of you want to insert multiple rows// {// ...// },
}
status, res, err:=client.Insert("Sheet1", employees)
iferr!=nil {
log.Fatal("Error insert data to stein: ", status, err.Error())
return
}
fmt.Printf("HTTP Status: %d \n", status)
fmt.Printf("Updated Range : %v \n", res)
current condition, the read data function still displays all the data. hopefully, we can do pagination by adding limit and offset parameters according to this stein API documentation: https://docs.steinhq.com/read-data#optional-request-parameters