-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ttl feature and redirection complete
- Loading branch information
Showing
2 changed files
with
195 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"google.golang.org/api/sheets/v4" | ||
|
||
"log" | ||
) | ||
|
||
type sheet struct { | ||
Name string | ||
Id string | ||
} | ||
|
||
func (s *sheet) Query() ([][]interface{}, error) { | ||
|
||
srv, err := sheets.NewService(context.TODO()) | ||
|
||
if err != nil { | ||
log.Fatalf("Unable to retrieve Sheets client: %v", err) | ||
} | ||
|
||
if s.Id == "" { | ||
|
||
log.Fatal("Google Sheets ID not specified") | ||
|
||
return nil, errors.New("Google Sheets ID not specified") | ||
|
||
} | ||
|
||
//NOTE: Set env variable | ||
spreadsheetId := s.Id | ||
readRange := "A:B" | ||
|
||
if s.Name != "" { | ||
|
||
readRange = s.Name + "!A:B" | ||
} | ||
|
||
resp, err := srv.Spreadsheets.Values.Get(spreadsheetId, readRange).Do() | ||
if err != nil { | ||
log.Fatalf("Unable to retrieve data from sheet: %v", err) | ||
|
||
return nil, err | ||
} | ||
|
||
log.Printf("Number of quering rows: %d\n", len(resp.Values)) | ||
|
||
return resp.Values, nil | ||
} |