本文整理匯總了Golang中github.com/drone/drone/shared/model.User類的典型用法代碼示例。如果您正苦於以下問題:Golang User類的具體用法?Golang User怎麽用?Golang User使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了User類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: PutUser
// PutUser saves a user in the datastore.
func (db *Userstore) PutUser(user *model.User) error {
if user.Created == 0 {
user.Created = time.Now().UTC().Unix()
}
user.Updated = time.Now().UTC().Unix()
return meddler.Save(db, userTable, user)
}
示例2: SyncUser
func SyncUser(ctx context.Context, user *model.User, remote remote.Remote) {
repos, err := remote.GetRepos(user)
if err != nil {
log.Println("Error syncing user account, listing repositories", user.Login, err)
return
}
// insert all repositories
for _, repo := range repos {
var role = repo.Role
if err := datastore.PostRepo(ctx, repo); err != nil {
// typically we see a failure because the repository already exists
// in which case, we can retrieve the existing record to get the ID.
repo, err = datastore.GetRepoName(ctx, repo.Host, repo.Owner, repo.Name)
if err != nil {
log.Println("Error adding repo.", user.Login, repo.Name, err)
continue
}
}
// add user permissions
perm := model.Perm{
UserID: user.ID,
RepoID: repo.ID,
Read: role.Read,
Write: role.Write,
Admin: role.Admin,
}
if err := datastore.PostPerm(ctx, &perm); err != nil {
log.Println("Error adding permissions.", user.Login, repo.Name, err)
continue
}
log.Printf("Successfully synced repo. %s/%s\n", repo.Owner, repo.Name)
}
user.Synced = time.Now().UTC().Unix()
user.Syncing = false
if err := datastore.PutUser(ctx, user); err != nil {
log.Println("Error syncing user account, updating sync date", user.Login, err)
return
}
}
示例3: PostUser
// PostUser saves a User in the datastore.
func (db *Userstore) PostUser(user *model.User) error {
user.Created = time.Now().UTC().Unix()
user.Updated = time.Now().UTC().Unix()
return meddler.Insert(db, userTable, user)
}