本文整理匯總了Golang中github.com/juju/names.UserTag.Provider方法的典型用法代碼示例。如果您正苦於以下問題:Golang UserTag.Provider方法的具體用法?Golang UserTag.Provider怎麽用?Golang UserTag.Provider使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/juju/names.UserTag
的用法示例。
在下文中一共展示了UserTag.Provider方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: AddEnvironmentUser
// AddEnvironmentUser adds a new user to the database.
func (st *State) AddEnvironmentUser(user, createdBy names.UserTag, displayName string) (*EnvironmentUser, error) {
// Ensure local user exists in state before adding them as an environment user.
if user.Provider() == names.LocalProvider {
if _, err := st.User(user.Name()); err != nil {
return nil, errors.Annotate(err, fmt.Sprintf("user %q does not exist locally", user.Name()))
}
}
// Ensure local createdBy user exists.
if createdBy.Provider() == names.LocalProvider {
if _, err := st.User(createdBy.Name()); err != nil {
return nil, errors.Annotate(err, fmt.Sprintf("createdBy user %q does not exist locally", createdBy.Name()))
}
}
username := user.Username()
envuuid := st.EnvironTag().Id()
id := envUserID(envuuid, username)
envUser := &EnvironmentUser{
st: st,
doc: envUserDoc{
ID: id,
EnvUUID: envuuid,
UserName: username,
DisplayName: displayName,
CreatedBy: createdBy.Username(),
DateCreated: nowToTheSecond(),
}}
ops := []txn.Op{{
C: envUsersC,
Id: id,
Assert: txn.DocMissing,
Insert: &envUser.doc,
}}
err := st.runTransaction(ops)
if err == txn.ErrAborted {
err = errors.New("env user already exists")
}
if err != nil {
return nil, errors.Trace(err)
}
return envUser, nil
}