• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang log.ErrorErrorf函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/YongMan/codis/pkg/utils/log.ErrorErrorf函数的典型用法代码示例。如果您正苦于以下问题:Golang ErrorErrorf函数的具体用法?Golang ErrorErrorf怎么用?Golang ErrorErrorf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了ErrorErrorf函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: apiSlotRangeSet

func apiSlotRangeSet(task RangeSetTask) (int, string) {
	lock := utils.GetZkLock(safeZkConn, globalEnv.ProductName())
	if err := lock.LockWithTimeout(0, fmt.Sprintf("set slot range, %+v", task)); err != nil {
		return 500, err.Error()
	}
	defer func() {
		err := lock.Unlock()
		if err != nil && err != zk.ErrNoNode {
			log.ErrorErrorf(err, "unlock node failed")
		}
	}()

	// default set online
	if len(task.Status) == 0 {
		task.Status = string(models.SLOT_STATUS_ONLINE)
	}

	err := models.SetSlotRange(safeZkConn, globalEnv.ProductName(), task.FromSlot, task.ToSlot, task.NewGroupId, models.SlotStatus(task.Status))
	if err != nil {
		log.ErrorErrorf(err, "set slot range [%d,%d] failed", task.FromSlot, task.ToSlot)
		return 500, err.Error()
	}

	return jsonRetSucc()
}
开发者ID:YongMan,项目名称:codis,代码行数:25,代码来源:dashboard_apis.go


示例2: apiPromoteServer

func apiPromoteServer(server models.Server, param martini.Params) (int, string) {
	lock := utils.GetZkLock(safeZkConn, globalEnv.ProductName())
	if err := lock.LockWithTimeout(0, fmt.Sprintf("promote server %+v", server)); err != nil {
		return 500, err.Error()
	}
	defer func() {
		err := lock.Unlock()
		if err != nil && err != zk.ErrNoNode {
			log.ErrorErrorf(err, "unlock node failed")
		}
	}()

	group, err := models.GetGroup(safeZkConn, globalEnv.ProductName(), server.GroupId)
	if err != nil {
		log.ErrorErrorf(err, "get group %d failed", server.GroupId)
		return 500, err.Error()
	}
	err = group.Promote(safeZkConn, server.Addr, globalEnv.Password())
	if err != nil {
		log.ErrorErrorf(err, "promote group %d failed", server.GroupId)
		return 500, err.Error()
	}

	return jsonRetSucc()
}
开发者ID:YongMan,项目名称:codis,代码行数:25,代码来源:dashboard_apis.go


示例3: apiAddServerGroup

// create new server group
func apiAddServerGroup(newGroup models.ServerGroup) (int, string) {
	lock := utils.GetZkLock(safeZkConn, globalEnv.ProductName())
	if err := lock.LockWithTimeout(0, fmt.Sprintf("add group %+v", newGroup)); err != nil {
		return 500, err.Error()
	}

	defer func() {
		err := lock.Unlock()
		if err != nil && err != zk.ErrNoNode {
			log.ErrorErrorf(err, "unlock node failed")
		}
	}()

	newGroup.ProductName = globalEnv.ProductName()

	exists, err := newGroup.Exists(safeZkConn)
	if err != nil {
		log.ErrorErrorf(err, "check group exits failed")
		return 500, err.Error()
	}
	if exists {
		return 500, "group already exists"
	}
	err = newGroup.Create(safeZkConn)
	if err != nil {
		log.ErrorErrorf(err, "create node for new group failed")
		return 500, err.Error()
	}
	return jsonRetSucc()
}
开发者ID:YongMan,项目名称:codis,代码行数:31,代码来源:dashboard_apis.go


示例4: apiAddServerToGroup

// add redis server to exist server group
func apiAddServerToGroup(server models.Server, param martini.Params) (int, string) {
	groupId, _ := strconv.Atoi(param["id"])
	lock := utils.GetZkLock(safeZkConn, globalEnv.ProductName())
	if err := lock.LockWithTimeout(0, fmt.Sprintf("add server to group,  %+v", server)); err != nil {
		return 500, err.Error()
	}
	defer func() {
		err := lock.Unlock()
		if err != nil && err != zk.ErrNoNode {
			log.ErrorErrorf(err, "unlock node failed")
		}
	}()
	// check group exists first
	serverGroup := models.NewServerGroup(globalEnv.ProductName(), groupId)

	exists, err := serverGroup.Exists(safeZkConn)
	if err != nil {
		log.ErrorErrorf(err, "check group exits failed")
		return 500, err.Error()
	}

	// create new group if not exists
	if !exists {
		if err := serverGroup.Create(safeZkConn); err != nil {
			return 500, err.Error()
		}
	}

	if err := serverGroup.AddServer(safeZkConn, &server, globalEnv.Password()); err != nil {
		log.ErrorErrorf(err, "add server to group failed")
		return 500, err.Error()
	}

	return jsonRetSucc()
}
开发者ID:YongMan,项目名称:codis,代码行数:36,代码来源:dashboard_apis.go


示例5: apiGetServerGroup

func apiGetServerGroup(param martini.Params) (int, string) {
	id := param["id"]
	groupId, err := strconv.Atoi(id)
	if err != nil {
		log.ErrorErrorf(err, "parse groupid failed")
		return 500, err.Error()
	}
	group, err := models.GetGroup(safeZkConn, globalEnv.ProductName(), groupId)
	if err != nil {
		log.ErrorErrorf(err, "get group %d failed", groupId)
		return 500, err.Error()
	}
	b, err := json.MarshalIndent(group, " ", "  ")
	return 200, string(b)
}
开发者ID:YongMan,项目名称:codis,代码行数:15,代码来源:dashboard_apis.go


示例6: cmdProxy

func cmdProxy(argv []string) (err error) {
	usage := `usage:
	codis-config proxy list
	codis-config proxy offline <proxy_name>
	codis-config proxy online <proxy_name>
`
	args, err := docopt.Parse(usage, argv, true, "", false)
	if err != nil {
		log.ErrorErrorf(err, "parse args failed")
		return err
	}
	log.Debugf("parse args = {%+v}", args)

	if args["list"].(bool) {
		return runProxyList()
	}

	proxyName := args["<proxy_name>"].(string)
	if args["online"].(bool) {
		return runSetProxyStatus(proxyName, models.PROXY_STATE_ONLINE)
	}
	if args["offline"].(bool) {
		return runSetProxyStatus(proxyName, models.PROXY_STATE_MARK_OFFLINE)
	}
	return nil
}
开发者ID:YongMan,项目名称:codis,代码行数:26,代码来源:proxy.go


示例7: cmdDashboard

func cmdDashboard(argv []string) (err error) {
	usage := `usage: codis-config dashboard [--addr=<address>] [--http-log=<log_file>]

options:
	--addr	listen ip:port, e.g. localhost:18087, :18087, [default: :18087]
	--http-log	http request log [default: request.log ]
`

	args, err := docopt.Parse(usage, argv, true, "", false)
	if err != nil {
		log.ErrorErrorf(err, "parse args failed")
		return err
	}
	log.Debugf("parse args = {%+v}", args)

	logFileName := "request.log"
	if args["--http-log"] != nil {
		logFileName = args["--http-log"].(string)
	}

	addr := ":18087"
	if args["--addr"] != nil {
		addr = args["--addr"].(string)
	}

	runDashboard(addr, logFileName)
	return nil
}
开发者ID:YongMan,项目名称:codis,代码行数:28,代码来源:dashboard.go


示例8: loopEvents

func (s *Server) loopEvents() {
	ticker := time.NewTicker(time.Second)
	defer ticker.Stop()

	var tick int = 0
	for s.info.State == models.PROXY_STATE_ONLINE {
		select {
		case <-s.kill:
			log.Infof("mark offline, proxy is killed: %s", s.info.Id)
			s.markOffline()
		case e := <-s.evtbus:
			evtPath := getEventPath(e)
			log.Infof("got event %s, %v, lastActionSeq %d", s.info.Id, e, s.lastActionSeq)
			if strings.Index(evtPath, models.GetActionResponsePath(s.conf.productName)) == 0 {
				seq, err := strconv.Atoi(path.Base(evtPath))
				if err != nil {
					log.ErrorErrorf(err, "parse action seq failed")
				} else {
					if seq < s.lastActionSeq {
						log.Infof("ignore seq = %d", seq)
						continue
					}
				}
			}
			s.processAction(e)
		case <-ticker.C:
			if maxTick := s.conf.pingPeriod; maxTick != 0 {
				if tick++; tick >= maxTick {
					s.router.KeepAlive()
					tick = 0
				}
			}
		}
	}
}
开发者ID:YongMan,项目名称:codis,代码行数:35,代码来源:proxy.go


示例9: apiActionGC

// actions
func apiActionGC(r *http.Request) (int, string) {
	r.ParseForm()
	keep, _ := strconv.Atoi(r.FormValue("keep"))
	secs, _ := strconv.Atoi(r.FormValue("secs"))
	lock := utils.GetZkLock(safeZkConn, globalEnv.ProductName())
	if err := lock.LockWithTimeout(0, fmt.Sprintf("action gc")); err != nil {
		return 500, err.Error()
	}
	defer func() {
		err := lock.Unlock()
		if err != nil && err != zk.ErrNoNode {
			log.ErrorErrorf(err, "unlock node failed")
		}
	}()

	var err error
	if keep >= 0 {
		err = models.ActionGC(safeZkConn, globalEnv.ProductName(), models.GC_TYPE_N, keep)
	} else if secs > 0 {
		err = models.ActionGC(safeZkConn, globalEnv.ProductName(), models.GC_TYPE_SEC, secs)
	}
	if err != nil {
		return 500, err.Error()
	}
	return jsonRetSucc()
}
开发者ID:YongMan,项目名称:codis,代码行数:27,代码来源:dashboard_apis.go


示例10: cmdServer

func cmdServer(argv []string) (err error) {
	usage := `usage:
	codis-config server list
	codis-config server add <group_id> <redis_addr> <role>
	codis-config server remove <group_id> <redis_addr>
	codis-config server promote <group_id> <redis_addr>
	codis-config server add-group <group_id>
	codis-config server remove-group <group_id>
`
	args, err := docopt.Parse(usage, argv, true, "", false)
	if err != nil {
		log.ErrorErrorf(err, "parse args failed")
		return err
	}
	log.Debugf("parse args = {%+v}", args)

	if args["list"].(bool) {
		return runListServerGroup()
	}

	groupId, err := strconv.Atoi(args["<group_id>"].(string))
	if err != nil {
		log.ErrorErrorf(err, "parse <group_id> failed")
		return err
	}

	if args["remove-group"].(bool) {
		return runRemoveServerGroup(groupId)
	}
	if args["add-group"].(bool) {
		return runAddServerGroup(groupId)
	}

	serverAddr := args["<redis_addr>"].(string)
	if args["add"].(bool) {
		role := args["<role>"].(string)
		return runAddServerToGroup(groupId, serverAddr, role)
	}
	if args["remove"].(bool) {
		return runRemoveServerFromGroup(groupId, serverAddr)
	}
	if args["promote"].(bool) {
		return runPromoteServerToMaster(groupId, serverAddr)
	}

	return nil
}
开发者ID:YongMan,项目名称:codis,代码行数:47,代码来源:server_group.go


示例11: apiForceRemoveLocks

func apiForceRemoveLocks() (int, string) {
	err := models.ForceRemoveLock(safeZkConn, globalEnv.ProductName())
	if err != nil {
		log.ErrorErrorf(err, "force remove lock failed")
		return 500, err.Error()
	}
	return jsonRetSucc()
}
开发者ID:YongMan,项目名称:codis,代码行数:8,代码来源:dashboard_apis.go


示例12: cmdAction

func cmdAction(argv []string) (err error) {
	usage := `usage: codis-config action (gc [-n <num> | -s <seconds>] | remove-lock | remove-fence)

options:
	gc:
	gc -n N		keep last N actions;
	gc -s Sec	keep last Sec seconds actions;

	remove-lock	force remove zookeeper lock;
`
	args, err := docopt.Parse(usage, argv, true, "", false)
	if err != nil {
		log.ErrorErrorf(err, "parse args failed")
		return errors.Trace(err)
	}
	log.Debugf("parse args = {%+v}", args)

	if args["remove-lock"].(bool) {
		return errors.Trace(runRemoveLock())
	}

	if args["remove-fence"].(bool) {
		return errors.Trace(runRemoveFence())
	}

	if args["gc"].(bool) {
		if args["-n"].(bool) {
			n, err := strconv.Atoi(args["<num>"].(string))
			if err != nil {
				log.ErrorErrorf(err, "parse <num> failed")
				return err
			}
			return runGCKeepN(n)
		} else if args["-s"].(bool) {
			sec, err := strconv.Atoi(args["<seconds>"].(string))
			if err != nil {
				log.ErrorErrorf(err, "parse <seconds> failed")
				return errors.Trace(err)
			}
			return runGCKeepNSec(sec)
		}
	}

	return nil
}
开发者ID:YongMan,项目名称:codis,代码行数:45,代码来源:action.go


示例13: apiGetSlots

func apiGetSlots() (int, string) {
	slots, err := models.Slots(safeZkConn, globalEnv.ProductName())
	if err != nil {
		log.ErrorErrorf(err, "Error getting slot info, try init slots first?")
		return 500, err.Error()
	}
	b, err := json.MarshalIndent(slots, " ", "  ")
	return 200, string(b)
}
开发者ID:YongMan,项目名称:codis,代码行数:9,代码来源:dashboard_apis.go


示例14: apiGetProxyList

func apiGetProxyList(param martini.Params) (int, string) {
	proxies, err := models.ProxyList(safeZkConn, globalEnv.ProductName(), nil)
	if err != nil {
		log.ErrorErrorf(err, "get proxy list failed")
		return 500, err.Error()
	}
	b, err := json.MarshalIndent(proxies, " ", "  ")
	return 200, string(b)
}
开发者ID:YongMan,项目名称:codis,代码行数:9,代码来源:dashboard_apis.go


示例15: apiGetRedisSlotInfo

func apiGetRedisSlotInfo(param martini.Params) (int, string) {
	addr := param["addr"]
	slotId, err := strconv.Atoi(param["id"])
	if err != nil {
		log.ErrorErrorf(err, "parse slotid failed")
		return 500, err.Error()
	}
	slotInfo, err := utils.SlotsInfo(addr, globalEnv.Password(), slotId, slotId)
	if err != nil {
		log.ErrorErrorf(err, "get slot info %d failed", slotId)
		return 500, err.Error()
	}
	out, _ := json.MarshalIndent(map[string]interface{}{
		"keys":    slotInfo[slotId],
		"slot_id": slotId,
	}, " ", "  ")
	return 200, string(out)
}
开发者ID:YongMan,项目名称:codis,代码行数:18,代码来源:dashboard_apis.go


示例16: loop

func (m *MigrateManager) loop() error {
	for {
		time.Sleep(time.Second)
		info := m.NextTask()
		if info == nil {
			continue
		}
		t := GetMigrateTask(*info)
		err := t.preMigrateCheck()
		if err != nil {
			log.ErrorErrorf(err, "pre migrate check failed")
		}
		err = t.run()
		if err != nil {
			log.ErrorErrorf(err, "migrate failed")
		}
	}
}
开发者ID:YongMan,项目名称:codis,代码行数:18,代码来源:migrate_manager.go


示例17: apiGetServerGroupList

func apiGetServerGroupList() (int, string) {
	groups, err := models.ServerGroups(safeZkConn, globalEnv.ProductName())
	if err != nil {
		log.ErrorErrorf(err, "get server groups failed")
		return 500, err.Error()
	}
	b, err := json.MarshalIndent(groups, " ", "  ")
	return 200, string(b)
}
开发者ID:YongMan,项目名称:codis,代码行数:9,代码来源:dashboard_apis.go


示例18: apiRebalance

func apiRebalance(param martini.Params) (int, string) {
	if len(globalMigrateManager.Tasks()) > 0 {
		return 500, "there are migration tasks running, you should wait them done"
	}
	if err := Rebalance(); err != nil {
		log.ErrorErrorf(err, "rebalance failed")
		return 500, err.Error()
	}
	return jsonRetSucc()
}
开发者ID:YongMan,项目名称:codis,代码行数:10,代码来源:dashboard_apis.go


示例19: apiGetRedisSlotInfoFromGroupId

func apiGetRedisSlotInfoFromGroupId(param martini.Params) (int, string) {
	groupId, err := strconv.Atoi(param["group_id"])
	if err != nil {
		log.ErrorErrorf(err, "parse groupid failed")
		return 500, err.Error()
	}
	slotId, err := strconv.Atoi(param["slot_id"])
	if err != nil {
		log.ErrorErrorf(err, "parse slotid failed")
		return 500, err.Error()
	}
	g, err := models.GetGroup(safeZkConn, globalEnv.ProductName(), groupId)
	if err != nil {
		log.ErrorErrorf(err, "get group %d failed", groupId)
		return 500, err.Error()
	}

	s, err := g.Master(safeZkConn)
	if err != nil {
		log.ErrorErrorf(err, "get master of group %d failed", groupId)
		return 500, err.Error()
	}

	if s == nil {
		return 500, "master not found"
	}

	slotInfo, err := utils.SlotsInfo(s.Addr, globalEnv.Password(), slotId, slotId)
	if err != nil {
		log.ErrorErrorf(err, "get slot info %d failed", slotId)
		return 500, err.Error()
	}

	out, _ := json.MarshalIndent(map[string]interface{}{
		"keys":     slotInfo[slotId],
		"slot_id":  slotId,
		"group_id": groupId,
		"addr":     s.Addr,
	}, " ", "  ")
	return 200, string(out)

}
开发者ID:YongMan,项目名称:codis,代码行数:42,代码来源:dashboard_apis.go


示例20: apiRemoveServerFromGroup

func apiRemoveServerFromGroup(server models.Server, param martini.Params) (int, string) {
	groupId, _ := strconv.Atoi(param["id"])
	lock := utils.GetZkLock(safeZkConn, globalEnv.ProductName())
	if err := lock.LockWithTimeout(0, fmt.Sprintf("removing server from group, %+v", server)); err != nil {
		return 500, err.Error()
	}
	defer func() {
		err := lock.Unlock()
		if err != nil && err != zk.ErrNoNode {
			log.ErrorErrorf(err, "unlock node failed")
		}
	}()

	serverGroup := models.NewServerGroup(globalEnv.ProductName(), groupId)
	err := serverGroup.RemoveServer(safeZkConn, server.Addr)
	if err != nil {
		log.ErrorErrorf(err, "remove group %d failed", groupId)
		return 500, err.Error()
	}
	return jsonRetSucc()
}
开发者ID:YongMan,项目名称:codis,代码行数:21,代码来源:dashboard_apis.go



注:本文中的github.com/YongMan/codis/pkg/utils/log.ErrorErrorf函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang log.Infof函数代码示例发布时间:2022-05-28
下一篇:
Golang errors.Trace函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap