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

Golang errutil.Success函数代码示例

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

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



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

示例1: Status

func (chk Installed) Status() (int, string, error) {
	name := getManager()
	options := managers[name]
	cmd := exec.Command(name, options, chk.pkg)
	out, err := cmd.CombinedOutput()
	outstr := string(out)
	var msg string
	switch {
	case err == nil && (name == "rpm" || name == "pacman"):
		return errutil.Success()
	// failures due to mising package
	case name == "dpkg" && strings.Contains(outstr, "not installed"):
	case name == "pacman" && strings.Contains(outstr, "not found"):
	case name == "rpm" && strings.Contains(outstr, "not installed"):
		msg := "Package was not found:"
		msg += "\n\tPackage name: " + chk.pkg
		msg += "\n\tPackage manager: " + name
		msg += "\n\tCommand output: " + outstr
		return 1, msg, nil
	// failures that were not due to packages not being installed
	case err != nil:
		errutil.ExecError(cmd, outstr, err)
	default:
		return errutil.Success()
	}
	return 1, msg, nil
}
开发者ID:allenbhuiyan,项目名称:distributive,代码行数:27,代码来源:packages.go


示例2: Status

func (chk SystemctlUnitFileStatus) Status() (int, string, error) {
	units, statuses, err := systemdstatus.UnitFileStatuses()
	if err != nil {
		return 1, "", err
	}
	var actualStatus string
	found := false
	for _, unit := range units {
		if unit == chk.unit {
			found = true
		}
	}
	if !found {
		return 1, "Unit file could not be found: " + chk.unit, nil
	}
	for i, un := range units {
		if un == chk.unit {
			actualStatus = statuses[i]
			if actualStatus == chk.status {
				return errutil.Success()
			}
		}
	}
	msg := "Unit didn't have status"
	return errutil.GenericError(msg, chk.status, []string{actualStatus})
}
开发者ID:allenbhuiyan,项目名称:distributive,代码行数:26,代码来源:systemctl.go


示例3: Status

func (chk Command) Status() (int, string, error) {
	cmd := exec.Command("bash", "-c", chk.Command)
	err := cmd.Start()
	if err != nil && strings.Contains(err.Error(), "not found in $PATH") {
		return 1, "Executable not found: " + chk.Command, nil
	} else if err != nil {
		return 1, "", err
	}
	if err = cmd.Wait(); err != nil {
		var exitCode int
		// this is convoluted, but should work on Windows & Unix
		if exiterr, ok := err.(*exec.ExitError); ok {
			if status, ok := exiterr.Sys().(syscall.WaitStatus); ok {
				exitCode = status.ExitStatus()
			}
		}
		// dummy, in case the above failed. We know it's not zero!
		if exitCode == 0 {
			exitCode = 1
		}
		out, _ := cmd.CombinedOutput() // don't care if this fails
		exitMessage := "Command exited with non-zero exit code:"
		exitMessage += "\n\tCommand: " + chk.Command
		exitMessage += "\n\tExit code: " + fmt.Sprint(exitCode)
		exitMessage += "\n\tOutput: " + string(out)
		return 1, exitMessage, nil
	}
	return errutil.Success()
}
开发者ID:nyanshak,项目名称:distributive,代码行数:29,代码来源:misc.go


示例4: freeMemOrSwap

// freeMemOrSwap is an abstraction of FreeMemory and FreeSwap, which measures
// if the desired resource has a quantity free above the amount specified
func freeMemOrSwap(input string, swapOrMem string) (int, string, error) {
	amount, units, err := chkutil.SeparateByteUnits(input)
	if err != nil {
		log.WithFields(log.Fields{
			"err": err.Error(),
		}).Fatal("Couldn't separate string into a scalar and units")
	}
	var actualAmount int
	switch strings.ToLower(swapOrMem) {
	case "memory":
		actualAmount, err = memstatus.FreeMemory(units)
	case "swap":
		actualAmount, err = memstatus.FreeSwap(units)
	default:
		log.Fatalf("Invalid option passed to freeMemoOrSwap: %s", swapOrMem)
	}
	if err != nil {
		return 1, "", err
	} else if actualAmount > amount {
		return errutil.Success()
	}
	msg := "Free " + swapOrMem + " lower than defined threshold"
	actualString := fmt.Sprint(actualAmount) + units
	return errutil.GenericError(msg, input, []string{actualString})
}
开发者ID:nyanshak,项目名称:distributive,代码行数:27,代码来源:usage.go


示例5: RoutingTableMatch

// RoutingTableMatch asks: Is this value in this column of the routing table?
func RoutingTableMatch(col string, str string) (int, string, error) {
	column := RoutingTableColumn(col)
	if tabular.StrIn(str, column) {
		return errutil.Success()
	}
	return errutil.GenericError("Not found in routing table", str, column)
}
开发者ID:allenbhuiyan,项目名称:distributive,代码行数:8,代码来源:network.go


示例6: Status

func (chk DockerRunningAPI) Status() (int, string, error) {
	running := getRunningContainersAPI(chk.path)
	if tabular.StrContainedIn(chk.name, running) {
		return errutil.Success()
	}
	msg := "Docker container not runnning"
	return errutil.GenericError(msg, chk.name, running)
}
开发者ID:allenbhuiyan,项目名称:distributive,代码行数:8,代码来源:docker.go


示例7: ResponseMatchesGeneral

// ResponseMatchesGeneral is an abstraction of ResponseMatches and
// ResponseMatchesInsecure that simply varies in the security of the connection
func ResponseMatchesGeneral(urlstr string, re *regexp.Regexp, secure bool) (int, string, error) {
	body := chkutil.URLToBytes(urlstr, secure)
	if re.Match(body) {
		return errutil.Success()
	}
	msg := "Response didn't match regexp"
	return errutil.GenericError(msg, re.String(), []string{string(body)})
}
开发者ID:allenbhuiyan,项目名称:distributive,代码行数:10,代码来源:network.go


示例8: Status

func (chk FileMatches) Status() (int, string, error) {
	if chk.re.Match(chkutil.FileToBytes(chk.path)) {
		return errutil.Success()
	}
	msg := "File does not match regexp:"
	msg += "\n\tFile: " + chk.path
	msg += "\n\tRegexp: " + chk.re.String()
	return 1, msg, nil
}
开发者ID:allenbhuiyan,项目名称:distributive,代码行数:9,代码来源:filesystem.go


示例9: Status

func (chk UserInGroup) Status() (int, string, error) {
	boo, err := usrstatus.UserInGroup(chk.user, chk.group)
	if err != nil {
		return 1, "", err
	} else if boo {
		return errutil.Success()
	}
	return 1, "User not found in group", nil
}
开发者ID:allenbhuiyan,项目名称:distributive,代码行数:9,代码来源:users-and-groups.go


示例10: timerCheck

// timerCheck is pure DRY for SystemctlTimer and SystemctlTimerLoaded
func timerCheck(unit string, all bool) (int, string, error) {
	timers, err := systemdstatus.Timers(all)
	if err != nil {
		return 1, "", err
	} else if tabular.StrIn(unit, timers) {
		return errutil.Success()
	}
	return errutil.GenericError("Timer not found", unit, timers)
}
开发者ID:allenbhuiyan,项目名称:distributive,代码行数:10,代码来源:systemctl.go


示例11: ipCheck

// ipCheck(int, string, error) is an abstraction of IP4 and
// IP6
func ipCheck(name string, address *net.IP, version int) (int, string, error) {
	ips := netstatus.InterfaceIPs(name)
	for _, ip := range ips {
		if ip.Equal(*address) {
			return errutil.Success()
		}
	}
	return errutil.GenericError("Interface does not have IP", address, ips)
}
开发者ID:allenbhuiyan,项目名称:distributive,代码行数:11,代码来源:network.go


示例12: Status

func (chk PortTCP) Status() (int, string, error) {
	if netstatus.PortOpen("tcp", chk.port) {
		return errutil.Success()
	}
	// convert ports to string to send to errutil.GenericError
	var strPorts []string
	for _, port := range netstatus.OpenPorts("tcp") {
		strPorts = append(strPorts, fmt.Sprint(port))
	}
	return errutil.GenericError("Port not open", fmt.Sprint(chk.port), strPorts)
}
开发者ID:allenbhuiyan,项目名称:distributive,代码行数:11,代码来源:network.go


示例13: isType

// isType checks if the resource at path is of the type specified by name by
// passing path to checker. Mostly used to abstract Directory, File, Symlink.
func isType(name string, checker fileCondition, path string) (int, string, error) {
	boo, err := checker(path)
	if os.IsNotExist(err) {
		return 1, "No such file or directory: " + path, nil
	} else if os.IsPermission(err) {
		return 1, "", errors.New("Insufficient Permissions to read: " + path)
	} else if boo {
		return errutil.Success()
	}
	return 1, "Is not a " + name + ": " + path, nil
}
开发者ID:allenbhuiyan,项目名称:distributive,代码行数:13,代码来源:filesystem.go


示例14: Status

func (chk SwapUsage) Status() (int, string, error) {
	actualPercentUsed, err := memstatus.UsedSwap("percent")
	if err != nil {
		return 1, "", err
	}
	if actualPercentUsed < int(chk.maxPercentUsed) {
		return errutil.Success()
	}
	msg := "Swap usage above defined maximum"
	slc := []string{fmt.Sprint(actualPercentUsed)}
	return errutil.GenericError(msg, fmt.Sprint(chk.maxPercentUsed), slc)
}
开发者ID:nyanshak,项目名称:distributive,代码行数:12,代码来源:usage.go


示例15: Status

func (chk InodeUsage) Status() (int, string, error) {
	actualPercentUsed, err := fsstatus.PercentInodesUsed(chk.filesystem)
	if err != nil {
		return 1, "Unexpected error", err
	}
	if actualPercentUsed < chk.maxPercentUsed {
		return errutil.Success()
	}
	msg := "More disk space used than expected"
	slc := []string{fmt.Sprint(actualPercentUsed) + "%"}
	return errutil.GenericError(msg, fmt.Sprint(chk.maxPercentUsed)+"%", slc)
}
开发者ID:allenbhuiyan,项目名称:distributive,代码行数:12,代码来源:usage.go


示例16: genericUserField

// genericUserField constructs (int, string, error)s that check if a given field of a User
// object found by lookupUser has a given value
func genericUserField(usernameOrUID string, fieldName string, fieldValue string) (int, string, error) {
	boolean, err := userHasField(usernameOrUID, fieldName, fieldValue)
	if err != nil {
		return 1, "User does not exist: " + usernameOrUID, nil
	} else if boolean {
		return errutil.Success()
	}
	msg := "User does not have expected " + fieldName + ": "
	msg += "\nUser: " + usernameOrUID
	msg += "\nGiven: " + fieldValue
	return 1, msg, nil
}
开发者ID:allenbhuiyan,项目名称:distributive,代码行数:14,代码来源:users-and-groups.go


示例17: Status

func (chk PacmanIgnore) Status() (int, string, error) {
	path := "/etc/pacman.conf"
	data := chkutil.FileToString(path)
	re := regexp.MustCompile(`[^#]IgnorePkg\s+=\s+.+`)
	find := re.FindString(data)
	var packages []string
	if find != "" {
		spl := strings.Split(find, " ")
		errutil.IndexError("Not enough lines in "+path, 2, spl)
		packages = spl[2:] // first two are "IgnorePkg" and "="
		if tabular.StrIn(chk.pkg, packages) {
			return errutil.Success()
		}
	}
	msg := "Couldn't find package in IgnorePkg"
	return errutil.GenericError(msg, chk.pkg, packages)
}
开发者ID:TanyaCouture,项目名称:distributive,代码行数:17,代码来源:packages.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang tabular.StrIn函数代码示例发布时间:2022-05-23
下一篇:
Golang errutil.GenericError函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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