Skip to content

Commit

Permalink
ignore litner
Browse files Browse the repository at this point in the history
  • Loading branch information
JunNishimura committed Jul 21, 2023
1 parent 52f07f3 commit fd8f9c8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 28 deletions.
30 changes: 16 additions & 14 deletions env.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"fmt"
"os"
"path/filepath"
"strconv"
"time"

"github.com/spf13/viper"
"golang.org/x/oauth2"
Expand Down Expand Up @@ -96,20 +98,20 @@ func saveToken(token *oauth2.Token) error {
return nil
}

// func getToken() *oauth2.Token {
// accessToken := tokenViper.GetString(AccessTokenKeyName)
// refreshToken := tokenViper.GetString(RefreshTokenKeyName)
// expiration := tokenViper.GetString(ExpirationKeyName)
// unix, _ := strconv.ParseInt(expiration, 10, 64)
// expiry := time.Unix(unix, 0)

// return &oauth2.Token{
// AccessToken: accessToken,
// TokenType: "bearer",
// RefreshToken: refreshToken,
// Expiry: expiry,
// }
// }
func getToken() *oauth2.Token {
accessToken := tokenViper.GetString(AccessTokenKeyName)
refreshToken := tokenViper.GetString(RefreshTokenKeyName)
expiration := tokenViper.GetString(ExpirationKeyName)
unix, _ := strconv.ParseInt(expiration, 10, 64)
expiry := time.Unix(unix, 0)

return &oauth2.Token{
AccessToken: accessToken,
TokenType: "bearer",
RefreshToken: refreshToken,
Expiry: expiry,
}
}

func askClientInfo() error {
// get spotify ID
Expand Down
28 changes: 14 additions & 14 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,24 @@ func main() {

authorize()
} else {
// ctx := context.Background()
// token := getToken()
ctx := context.Background()
token := getToken()

// newToken, err := auth.RefreshToken(ctx, token)
// if err != nil {
// log.Fatalf("fail to get a new access token: %v", err)
// }
newToken, err := auth.RefreshToken(ctx, token)
if err != nil {
log.Fatalf("fail to get a new access token: %v", err)
}

// // update an access token if it has expired
// if token.AccessToken != newToken.AccessToken {
// if err := saveToken(newToken); err != nil {
// log.Fatalf("fail to save token: %v", err)
// }
// }
// update an access token if it has expired
if token.AccessToken != newToken.AccessToken {
if err := saveToken(newToken); err != nil {
log.Fatalf("fail to save token: %v", err)
}
}

// spotifyClient := spotify.New(auth.Client(ctx, newToken))
spotifyClient := spotify.New(auth.Client(ctx, newToken))

// clientChannel <- spotifyClient
clientChannel <- spotifyClient
}

client := <-clientChannel
Expand Down

0 comments on commit fd8f9c8

Please sign in to comment.