func (this *httpServer) doSheepTail(r *http.Request) (util.WaitRetMap, error) { reqParams, err := web.NewReqParams(r) if err != nil { return nil, web.HTTPError{400, "INVALID_REQUEST"} } names, err := reqParams.GetAll("name") if err != nil { for name, _ := range this.ctx.sheeps { names = append(names, name) } } var num int numStr, err := reqParams.Get("num") if err != nil { num = 10 } else if num, err = strconv.Atoi(numStr); err != nil { return nil, web.HTTPError{400, "MISSING_ARG_NUM"} } forever, _ := reqParams.Get("forever") rets, err := util.MultiWait(names, func(name interface{}) util.WaitRet { data, err := this.ctx.SheepTail(name.(string), num, forever == "true") return util.WaitRet{err, data} }) return rets, err }
func (this *httpServer) doSheepAdd(r *http.Request) (util.WaitRetMap, error) { reqParams, err := web.NewReqParams(r) if err != nil { return nil, web.HTTPError{400, "INVALID_REQUEST"} } ctx, err := this.readBody(reqParams) if err != nil { return nil, web.HTTPError{400, "INVALID_BODY"} } rets, err := util.MultiWait(ctx.Process, func(conf interface{}) util.WaitRet { return util.WaitRet{nil, this.ctx.SheepAdd(conf.(*process.Config))} }) this.Persistence() return rets, err }
func (this *httpServer) doSheepStop(r *http.Request) (util.WaitRetMap, error) { reqParams, err := web.NewReqParams(r) if err != nil { return nil, web.HTTPError{400, "INVALID_REQUEST"} } names, err := reqParams.GetAll("name") if err != nil { for name, _ := range this.ctx.sheeps { names = append(names, name) } } rets, err := util.MultiWait(names, func(name interface{}) util.WaitRet { return util.WaitRet{nil, this.ctx.SheepStop(name.(string))} }) return rets, err }