From 32f07ce90b15c7b7d2efc56f72bce409076a6c96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=27Kama=C5=9B=27=20Bruchal?= Date: Wed, 17 Jun 2026 20:08:16 +0200 Subject: [PATCH] Feat: Sheet parsing --- fetch-sheet.go | 21 +++++++++++++++------ main.go | 1 + scheduler.go | 1 + 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/fetch-sheet.go b/fetch-sheet.go index 721c119..5c12f32 100644 --- a/fetch-sheet.go +++ b/fetch-sheet.go @@ -1,20 +1,29 @@ -package rota +package dyzurbot import ( "context" "fmt" + "os" + "github.com/joho/godotenv" "google.golang.org/api/option" "google.golang.org/api/sheets/v4" ) // ReadRota czyta zadany zakres z arkusza i zwraca wiersze. // spreadsheetID to ID z URL-a arkusza, readRange np. "Dyżury!A1:C30". -func ReadSheet(ctx context.Context, credsPath, spreadsheetID, readRange string) ([][]interface{}, error) { - srv, err := sheets.NewService(ctx, - option.WithAuthCredentialsFile(option.ServiceAccount, credsPath), - option.WithScopes(sheets.SpreadsheetsReadonlyScope), - ) +// Klucz API jest wczytywany z pliku .env (zmienna GOOGLE_API_KEY). +func ReadSheet(ctx context.Context, spreadsheetID, readRange string) ([][]interface{}, error) { + // godotenv.Load nie nadpisuje już ustawionych zmiennych środowiskowych; + // brak pliku .env nie jest błędem (na produkcji zmienne mogą być ustawione inaczej). + _ = godotenv.Load() + + apiKey := os.Getenv("GOOGLE_API_KEY") + if apiKey == "" { + return nil, fmt.Errorf("missing GOOGLE_API_KEY in environment/.env") + } + + srv, err := sheets.NewService(ctx, option.WithAPIKey(apiKey)) if err != nil { return nil, fmt.Errorf("init sheets service: %w", err) } diff --git a/main.go b/main.go index e69de29..d131ba0 100644 --- a/main.go +++ b/main.go @@ -0,0 +1 @@ +package dyzurbot diff --git a/scheduler.go b/scheduler.go index e69de29..d131ba0 100644 --- a/scheduler.go +++ b/scheduler.go @@ -0,0 +1 @@ +package dyzurbot