ctx := context.Background()
credentials, err := ioutil.ReadFile("../googlecredentialsfile.json")
if err != nil {
return nil, err
}
config, err := google.JWTConfigFromJSON(credentials, playintegrity.PlayintegrityScope)
if err != nil {
return nil, err
}
var client *http.Client
if viper.GetString("ENABLE_PROXY") == "TRUE" {
// Set up an HTTP transport that uses the proxy
proxyUrl := viper.GetString("PROXY_URL")
proxy, _ := url.Parse(proxyUrl)
transport := &http.Transport{
Proxy: http.ProxyURL(proxy),
}
// Create an OAuth2 token source using the JWT config
tokenSource := config.TokenSource(ctx)
// Create a new http.Client with custom transport for proxy and OAuth2
client = &http.Client{
Transport: &oauth2.Transport{
Base: transport,
Source: tokenSource,
},
}
} else {
// No proxy, just use the default client with OAuth2
client = config.Client(ctx)
}
// Create the Play Integrity service with the HTTP client
playIntegrityService, err := playintegrity.NewService(ctx, option.WithHTTPClient(client))
if err != nil {
return nil, err
}
.....