generated from layer5io/layer5-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Pranav Singh <pranavsingh02@hotmail.com>
- Loading branch information
1 parent
85162ea
commit 44f337d
Showing
2 changed files
with
55 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package utils | ||
|
||
import ( | ||
"context" | ||
"encoding/base64" | ||
|
||
"golang.org/x/oauth2/google" | ||
"google.golang.org/api/option" | ||
"google.golang.org/api/sheets/v4" | ||
) | ||
|
||
|
||
func NewSheetSRV(cred string) (*sheets.Service, error) { | ||
ctx := context.Background() | ||
byt, _ := base64.StdEncoding.DecodeString(cred) | ||
// authenticate and get configuration | ||
config, err := google.JWTConfigFromJSON(byt, "https://www.googleapis.com/auth/spreadsheets") | ||
if err != nil { | ||
return nil, err | ||
} | ||
// create client with config and context | ||
client := config.Client(ctx) | ||
// create new service using client | ||
srv, err := sheets.NewService(ctx, option.WithHTTPClient(client)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return srv, nil | ||
} |
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