Moge-Row commited on
Commit
89bdab6
·
1 Parent(s): 331b496

use apps script webhook for sheets

Browse files
Files changed (1) hide show
  1. internal/handler/sheets.go +4 -12
internal/handler/sheets.go CHANGED
@@ -3,22 +3,14 @@ package handler
3
  import (
4
  "bytes"
5
  "encoding/json"
6
- "fmt"
7
  "net/http"
8
  "os"
9
- "time"
10
  )
11
 
12
- var sheetID = os.Getenv("GOOGLE_SHEET_ID")
13
- var sheetKey = os.Getenv("GOOGLE_API_KEY")
14
 
15
  func BackupKeyToSheet(name, key string) {
16
- if sheetID == "" || sheetKey == "" { return }
17
- url := fmt.Sprintf(
18
- "https://sheets.googleapis.com/v4/spreadsheets/%s/values/Sheet1!A:C:append?valueInputOption=RAW&key=%s",
19
- sheetID, sheetKey)
20
- body, _ := json.Marshal(map[string]interface{}{
21
- "values": [][]interface{}{{name, key, time.Now().Format("2006-01-02")}},
22
- })
23
- http.Post(url, "application/json", bytes.NewReader(body))
24
  }
 
3
  import (
4
  "bytes"
5
  "encoding/json"
 
6
  "net/http"
7
  "os"
 
8
  )
9
 
10
+ var sheetsWebhook = os.Getenv("SHEETS_WEBHOOK")
 
11
 
12
  func BackupKeyToSheet(name, key string) {
13
+ if sheetsWebhook == "" { return }
14
+ body, _ := json.Marshal(map[string]string{"name": name, "key": key})
15
+ http.Post(sheetsWebhook, "application/json", bytes.NewReader(body))
 
 
 
 
 
16
  }