Skip to content

Commit

Permalink
add utils for registry publish
Browse files Browse the repository at this point in the history
Signed-off-by: Pranav Singh <pranavsingh02@hotmail.com>
  • Loading branch information
theBeginner86 committed Jan 27, 2024
1 parent 85162ea commit 44f337d
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
29 changes: 29 additions & 0 deletions utils/google.go
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
}
26 changes: 26 additions & 0 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,3 +276,29 @@ func IsClosed[K any](ch chan K) bool {
return false
}
}

// WriteToFile writes the given content to the given file path
func WriteToFile(path string, content string) error {
file, err := os.Create(path)
if err != nil {
return err
}

_, err = file.WriteString(content)
if err != nil {
return err
}
// Close the file to save the changes.
err = file.Close()
if err != nil {
return err
}
return nil
}

// FormatName formats the given string to by replacing " " with "-"
func FormatName(input string) string {
formatedName := strings.ReplaceAll(input, " ", "-")
formatedName = strings.ToLower(formatedName)
return formatedName
}

0 comments on commit 44f337d

Please sign in to comment.