本文整理汇总了Golang中github.com/ubuntu-core/snappy/overlord/state.State.Set方法的典型用法代码示例。如果您正苦于以下问题:Golang State.Set方法的具体用法?Golang State.Set怎么用?Golang State.Set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/ubuntu-core/snappy/overlord/state.State
的用法示例。
在下文中一共展示了State.Set方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: NewUser
// NewUser tracks a new authenticated user and saves its details in the state
func NewUser(st *state.State, username, macaroon string, discharges []string) (*UserState, error) {
var authStateData AuthState
err := st.Get("auth", &authStateData)
if err == state.ErrNoState {
authStateData = AuthState{}
} else if err != nil {
return nil, err
}
sort.Strings(discharges)
authStateData.LastID++
authenticatedUser := UserState{
ID: authStateData.LastID,
Username: username,
Macaroon: macaroon,
Discharges: discharges,
StoreMacaroon: macaroon,
StoreDischarges: discharges,
}
authStateData.Users = append(authStateData.Users, authenticatedUser)
st.Set("auth", authStateData)
return &authenticatedUser, nil
}
示例2: newRunnerManager
func newRunnerManager(s *state.State) *runnerManager {
rm := &runnerManager{
runner: state.NewTaskRunner(s),
}
rm.runner.AddHandler("runMgr1", func(t *state.Task, _ *tomb.Tomb) error {
s := t.State()
s.Lock()
defer s.Unlock()
s.Set("runMgr1Mark", 1)
return nil
}, nil)
rm.runner.AddHandler("runMgr2", func(t *state.Task, _ *tomb.Tomb) error {
s := t.State()
s.Lock()
defer s.Unlock()
s.Set("runMgr2Mark", 1)
return nil
}, nil)
rm.runner.AddHandler("runMgrEnsureBefore", func(t *state.Task, _ *tomb.Tomb) error {
s := t.State()
s.Lock()
defer s.Unlock()
s.EnsureBefore(20 * time.Millisecond)
return nil
}, nil)
return rm
}
示例3: Set
// Set sets the SnapState of the given snap, overwriting any earlier state.
func Set(s *state.State, name string, snapst *SnapState) {
var snaps map[string]*json.RawMessage
err := s.Get("snaps", &snaps)
if err != nil && err != state.ErrNoState {
panic("internal error: cannot unmarshal snaps state: " + err.Error())
}
if snaps == nil {
snaps = make(map[string]*json.RawMessage)
}
if snapst == nil || (len(snapst.Sequence) == 0 && snapst.Candidate == nil) {
delete(snaps, name)
} else {
data, err := json.Marshal(snapst)
if err != nil {
panic("internal error: cannot marshal snap state: " + err.Error())
}
raw := json.RawMessage(data)
snaps[name] = &raw
}
s.Set("snaps", snaps)
}
示例4: RemoveUser
// RemoveUser removes a user from the state given its ID
func RemoveUser(st *state.State, userID int) error {
var authStateData AuthState
err := st.Get("auth", &authStateData)
if err != nil {
return err
}
for i := range authStateData.Users {
if authStateData.Users[i].ID == userID {
// delete without preserving order
n := len(authStateData.Users) - 1
authStateData.Users[i] = authStateData.Users[n]
authStateData.Users[n] = UserState{}
authStateData.Users = authStateData.Users[:n]
st.Set("auth", authStateData)
return nil
}
}
return fmt.Errorf("invalid user")
}
示例5: setConns
func setConns(st *state.State, conns map[string]connState) {
st.Set("conns", conns)
}