コード例 #1
0
ファイル: subscriptions.go プロジェクト: fbwotjq/gdrive2slack
func LoadSubscriptions(filename string) (*Subscriptions, error) {
	var subscriptions = &Subscriptions{
		Source: filename,
		Info:   make(map[string]*Subscription),
		States: make(map[string]*UserState),
	}
	file, err := os.Open(filename)
	if err != nil {
		return subscriptions, nil
	}
	defer file.Close()
	err = json.NewDecoder(file).Decode(&subscriptions.Info)
	if err != nil {
		return nil, err
	}
	for k, sub := range subscriptions.Info {
		subscriptions.States[k] = &UserState{
			Gdrive:            drive.NewState(),
			GoogleAccessToken: "",
		}
		// handle migration from versions prior to folder filtering
		if sub.GoogleInterestingFolderIds == nil {
			sub.GoogleInterestingFolderIds = make([]string, 0)
		}
	}
	return subscriptions, nil
}
コード例 #2
0
ファイル: subscriptions.go プロジェクト: fbwotjq/gdrive2slack
func (subscriptions *Subscriptions) Add(subscription *Subscription, googleAccessToken string) {
	subscriptions.Info[subscription.GoogleUserInfo.Email] = subscription
	subscriptions.States[subscription.GoogleUserInfo.Email] = &UserState{
		Gdrive:            drive.NewState(),
		GoogleAccessToken: googleAccessToken,
	}
	subscriptions.save()
}