当前位置: 首页>>代码示例>>Golang>>正文


Golang errutil.Success函数代码示例

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


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


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