Spaces:
Paused
Paused
| 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)) | |
| } |