本文整理汇总了Golang中github.com/snapcore/snapd/overlord/state.Change.ID方法的典型用法代码示例。如果您正苦于以下问题:Golang Change.ID方法的具体用法?Golang Change.ID怎么用?Golang Change.ID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/snapcore/snapd/overlord/state.Change
的用法示例。
在下文中一共展示了Change.ID方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: snapsOp
func snapsOp(c *Command, r *http.Request, user *auth.UserState) Response {
route := c.d.router.Get(stateChangeCmd.Path)
if route == nil {
return InternalError("cannot find route for change")
}
decoder := json.NewDecoder(r.Body)
var inst snapInstruction
if err := decoder.Decode(&inst); err != nil {
return BadRequest("cannot decode request body into snap instruction: %v", err)
}
if inst.Channel != "" || !inst.Revision.Unset() || inst.DevMode || inst.JailMode {
return BadRequest("unsupported option provided for multi-snap operation")
}
st := c.d.overlord.State()
st.Lock()
defer st.Unlock()
if user != nil {
inst.userID = user.ID
}
var msg string
var affected []string
var tsets []*state.TaskSet
var err error
switch inst.Action {
case "refresh":
msg, affected, tsets, err = snapUpdateMany(&inst, st)
case "install":
msg, affected, tsets, err = snapInstallMany(&inst, st)
case "remove":
msg, affected, tsets, err = snapRemoveMany(&inst, st)
default:
return BadRequest("unsupported multi-snap operation %q", inst.Action)
}
if err != nil {
return InternalError("cannot %s %q: %v", inst.Action, inst.Snaps, err)
}
var chg *state.Change
if len(tsets) == 0 {
chg = st.NewChange(inst.Action+"-snap", msg)
chg.SetStatus(state.DoneStatus)
} else {
chg = newChange(st, inst.Action+"-snap", msg, tsets, affected)
ensureStateSoon(st)
}
chg.Set("api-data", map[string]interface{}{"snap-names": affected})
return AsyncResponse(nil, &Meta{Change: chg.ID()})
}
示例2: change2changeInfo
func change2changeInfo(chg *state.Change) *changeInfo {
status := chg.Status()
chgInfo := &changeInfo{
ID: chg.ID(),
Kind: chg.Kind(),
Summary: chg.Summary(),
Status: status.String(),
Ready: status.Ready(),
SpawnTime: chg.SpawnTime(),
}
readyTime := chg.ReadyTime()
if !readyTime.IsZero() {
chgInfo.ReadyTime = &readyTime
}
if err := chg.Err(); err != nil {
chgInfo.Err = err.Error()
}
tasks := chg.Tasks()
taskInfos := make([]*taskInfo, len(tasks))
for j, t := range tasks {
label, done, total := t.Progress()
taskInfo := &taskInfo{
ID: t.ID(),
Kind: t.Kind(),
Summary: t.Summary(),
Status: t.Status().String(),
Log: t.Log(),
Progress: taskInfoProgress{
Label: label,
Done: done,
Total: total,
},
SpawnTime: t.SpawnTime(),
}
readyTime := t.ReadyTime()
if !readyTime.IsZero() {
taskInfo.ReadyTime = &readyTime
}
taskInfos[j] = taskInfo
}
chgInfo.Tasks = taskInfos
var data map[string]*json.RawMessage
if chg.Get("api-data", &data) == nil {
chgInfo.Data = data
}
return chgInfo
}