func CreateDriveService(ctx context.Context, opt *Options) (*drive.Service, error) {
	var err error

	var ts oauth2.TokenSource

	scope := drive.DriveFileScope
	if opt.ReadOnly {
		scope = drive.DriveReadonlyScope
	}

	if sa := opt.ServiceAccountCredentialJSON; len(sa) > 0 {
		ts, err = tokenSourceFromCredentialsJSON(ctx, sa, scope)
	} else if sa := opt.ServiceAccountCredentialsFile; sa != "" {
		ts, err = tokenSourceFromCredentialsFile(ctx, sa, scope)
	} else {
		ts, err = google.DefaultTokenSource(ctx, scope)
	}

	if err != nil {
		return nil, errors.Wrap(err, "unable to initialize token source")
	}

	hc := oauth2.NewClient(ctx, ts)

	service, err := drive.NewService(ctx, option.WithHTTPClient(hc))
	if err != nil {
		return nil, errors.Wrap(err, "unable to create Drive client")
	}

	return service, nil
}
// CreateDriveService creates a new Google Drive service, which encapsulates multiple clients
// used to access different Google Drive functionality.
// Exported for tests only.
CreateDriveService creates a new Google Drive service, which encapsulates multiple clients
used to access different Google Drive functionality.
Exported for tests only.
// CreateDriveService creates a new Google Drive service which encapsulates multiple clients // used to access different Google Drive functionality . // Exported for tests only .
func CreateDriveService(ctx context.Context, opt *Options) (*drive.Service, error) {
	var err error
	var ts oauth2.TokenSource
	scope := drive.DriveFileScope
	if opt.ReadOnly {
		scope = drive.DriveReadonlyScope
	}
	if sa := opt.ServiceAccountCredentialJSON; len(sa) > 0 {
		ts, err = tokenSourceFromCredentialsJSON(ctx, sa, scope)
	} else if sa := opt.ServiceAccountCredentialsFile; sa != "" {
		ts, err = tokenSourceFromCredentialsFile(ctx, sa, scope)
	} else {
		ts, err = google.DefaultTokenSource(ctx, scope)
	}
	if err != nil {
		return nil, errors.Wrap(err, "unable to initialize token source")
	}
	hc := oauth2.NewClient(ctx, ts)
	service, err := drive.NewService(ctx, option.WithHTTPClient(hc))
	if err != nil {
		return nil, errors.Wrap(err, "unable to create Drive client")
	}
	return service, nil
}
func CreateDriveService ( ctx context . Context , opt * Options ) ( * drive . Service , error ) { var err error var ts oauth2 . TokenSource scope := drive . DriveFileScope if opt . ReadOnly { scope = drive . DriveReadonlyScope } if sa := opt . ServiceAccountCredentialJSON ; len ( sa ) > 0 { ts , err = tokenSourceFromCredentialsJSON ( ctx , sa , scope ) } else if sa := opt . ServiceAccountCredentialsFile ; sa != " " { ts , err = tokenSourceFromCredentialsFile ( ctx , sa , scope ) } else { ts , err = google . DefaultTokenSource ( ctx , scope ) } if err != nil { return nil , errors . Wrap ( err , " " ) } hc := oauth2 . NewClient ( ctx , ts ) service , err := drive . NewService ( ctx , option . WithHTTPClient ( hc ) ) if err != nil { return nil , errors . Wrap ( err , " " ) } return service , nil }
CreateDriveService creates a new Google Drive service, which encapsulates multiple clients
used to access different Google Drive functionality.
CreateDriveService creates a new Google Drive service which encapsulates multiple clients used to access different Google Drive functionality .