本文整理汇总了Golang中github.com/CiscoCloud/distributive/errutil.GenericError函数的典型用法代码示例。如果您正苦于以下问题:Golang GenericError函数的具体用法?Golang GenericError怎么用?Golang GenericError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GenericError函数的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Status
func (chk PHPConfig) Status() (int, string, error) {
// getPHPVariable returns the value of a PHP configuration value as a string
// or just "" if it doesn't exist
getPHPVariable := func(name string) (val string) {
quote := func(str string) string {
return "\"" + str + "\""
}
// php -r 'echo get_cfg_var("default_mimetype");
echo := fmt.Sprintf("echo get_cfg_var(%s);", quote(name))
cmd := exec.Command("php", "-r", echo)
out, err := cmd.CombinedOutput()
if err != nil {
errutil.ExecError(cmd, string(out), err)
}
return string(out)
}
actualValue := getPHPVariable(chk.variable)
if actualValue == chk.value {
return errutil.Success()
} else if actualValue == "" {
msg := "PHP configuration variable not set"
return errutil.GenericError(msg, chk.value, []string{actualValue})
}
msg := "PHP variable did not match expected value"
return errutil.GenericError(msg, chk.value, []string{actualValue})
}
开发者ID:nyanshak,项目名称:distributive,代码行数:26,代码来源:misc.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: 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
示例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: 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
示例6: 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
示例7: 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
示例8: 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
示例9: 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
示例10: 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
示例11: 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
示例12: groupNotFound
// groupNotFound creates generic error messages and exit codes for groupExits,
// UserInGroup, and GroupID
func groupNotFound(name string) (int, string, error) {
// get a nicely formatted list of groups that do exist
var existing []string
groups, err := usrstatus.Groups()
if err != nil {
return 1, "", err
}
for _, group := range groups {
existing = append(existing, group.Name)
}
return errutil.GenericError("Group not found", name, existing)
}
开发者ID:allenbhuiyan,项目名称:distributive,代码行数:14,代码来源:users-and-groups.go
示例13: Status
func (chk GroupID) Status() (int, string, error) {
groups, err := usrstatus.Groups()
if err != nil {
return 0, "", err
}
for _, g := range groups {
if g.Name == chk.name {
if g.ID == chk.id {
return errutil.Success()
}
msg := "Group does not have expected ID"
return errutil.GenericError(msg, chk.id, []int{g.ID})
}
}
return groupNotFound(chk.name)
}
开发者ID:allenbhuiyan,项目名称:distributive,代码行数:16,代码来源:users-and-groups.go
示例14: 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
示例15: Status
func (chk Checksum) Status() (int, string, error) {
// getFileChecksum is self-explanatory
fileChecksum := func(algorithm string, path string) string {
if path == "" {
log.Fatal("getFileChecksum got a blank path")
} else if _, err := os.Stat(chk.path); err != nil {
log.WithFields(log.Fields{
"path": chk.path,
}).Fatal("fileChecksum got an invalid path")
}
// we already validated the aglorithm
chksum, _ := fsstatus.Checksum(algorithm, chkutil.FileToBytes(path))
return chksum
}
actualChksum := fileChecksum(chk.algorithm, chk.path)
if actualChksum == chk.expectedChksum {
return errutil.Success()
}
msg := "Checksums do not match for file: " + chk.path
return errutil.GenericError(msg, chk.expectedChksum, []string{actualChksum})
}
开发者ID:allenbhuiyan,项目名称:distributive,代码行数:21,代码来源:filesystem.go
示例16: existsRepoWithProperty
// existsRepoWithProperty is an abstraction of YumRepoExists and YumRepoURL.
// It takes a struct field name to check, and an expected value. If the expected
// value is found in the field of a repo, it returns 0, "" else an error message.
// Valid choices for prop: "URL" | "Name" | "Name"
func existsRepoWithProperty(prop string, val *regexp.Regexp, manager string) (int, string, error) {
var properties []string
for _, repo := range getRepos(manager) {
switch prop {
case "URL":
properties = append(properties, repo.URL)
case "Name":
properties = append(properties, repo.Name)
case "Status":
properties = append(properties, repo.Status)
case "ID":
properties = append(properties, repo.ID)
default:
log.Fatal("Repos don't have the requested property: " + prop)
}
}
if tabular.ReIn(val, properties) {
return errutil.Success()
}
msg := "Repo with given " + prop + " not found"
return errutil.GenericError(msg, val.String(), properties)
}
开发者ID:TanyaCouture,项目名称:distributive,代码行数:26,代码来源:packages.go
注:本文中的github.com/CiscoCloud/distributive/errutil.GenericError函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论