Row-proxy / internal /handler /sheets.go
Moge-Row's picture
simplify sheets no heavy deps
5c638ab
raw
history blame
601 Bytes
package handler
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"os"
"time"
)
var sheetID = os.Getenv("GOOGLE_SHEET_ID")
var sheetKey = os.Getenv("GOOGLE_API_KEY")
func BackupKeyToSheet(name, key string) {
if sheetID == "" || sheetKey == "" { return }
url := fmt.Sprintf(
"https://sheets.googleapis.com/v4/spreadsheets/%s/values/Sheet1!A:C:append?valueInputOption=RAW&key=%s",
sheetID, sheetKey)
body, _ := json.Marshal(map[string]interface{}{
"values": [][]interface{}{{name, key, time.Now().Format("2006-01-02")}},
})
http.Post(url, "application/json", bytes.NewReader(body))
}