本文整理汇总了Golang中github.com/CiscoCloud/distributive/tabular.StrIn函数的典型用法代码示例。如果您正苦于以下问题:Golang StrIn函数的具体用法?Golang StrIn怎么用?Golang StrIn使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了StrIn函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: getIPWorker
// getIPWorker(exitCode int, exitMessage string) is an abstraction of Ip4 and Ip6
func getIPWorker(name string, address string, version int) (exitCode int, exitMessage string) {
ips := getInterfaceIPs(name, version)
if tabular.StrIn(address, ips) {
return 0, ""
}
return wrkutils.GenericError("Interface does not have IP", address, ips)
}
开发者ID:orimarti,项目名称:distributive,代码行数:8,代码来源:network.go
示例2: 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
示例3: routingTableMatch
// routingTableMatch(exitCode int, exitMessage string) constructs a Worker that returns whether or not the
// given string was found in the given column of the routing table. It is an
// astraction of routingTableDestination, routingTableInterface, and
// routingTableGateway
func routingTableMatch(col string, str string) (exitCode int, exitMessage string) {
column := routingTableColumn(col)
if tabular.StrIn(str, column) {
return 0, ""
}
return wrkutils.GenericError("Not found in routing table", str, column)
}
开发者ID:orimarti,项目名称:distributive,代码行数:11,代码来源:network.go
示例4: timersWorker
// timers(exitCode int, exitMessage string) is pure DRY for systemctlTimer and systemctlTimerLoaded
func timersWorker(unit string, all bool) (exitCode int, exitMessage string) {
timers := getTimers(all)
if tabular.StrIn(unit, timers) {
return 0, ""
}
return wrkutils.GenericError("Timer not found", unit, timers)
}
开发者ID:pinterb,项目名称:distributive,代码行数:8,代码来源:systemctl.go
示例5: 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
示例6: Status
func (chk SystemctlSockListening) Status() (int, string, error) {
listening, err := systemdstatus.ListeningSockets()
if err != nil {
return 1, "", err
}
if tabular.StrIn(chk.path, listening) {
return errutil.Success()
}
return errutil.GenericError("Socket wasn't listening", chk.path, listening)
}
开发者ID:allenbhuiyan,项目名称:distributive,代码行数:10,代码来源:systemctl.go
示例7: Status
func (chk DockerImage) Status() (int, string, error) {
images, err := dockerstatus.DockerImageRepositories()
if err != nil {
return 1, "", err
}
if tabular.StrIn(chk.name, images) {
return errutil.Success()
}
return errutil.GenericError("Docker image was not found", chk.name, images)
}
开发者ID:allenbhuiyan,项目名称:distributive,代码行数:10,代码来源:docker.go
示例8: TestGetManager
func TestGetManager(t *testing.T) {
t.Parallel()
man := getManager()
supported := []string{"pacman", "dpkg", "rpm"}
if !tabular.StrIn(man, supported) {
msg := "getManager returned an unsupported package manager"
msg += "\n\tReturned: " + man
msg += "\n\tSupported: " + fmt.Sprint(supported)
t.Error(msg)
}
}
开发者ID:TanyaCouture,项目名称:distributive,代码行数:11,代码来源:packages_test.go
示例9: UserInGroup
// UserInGroup asks whether or not the given user is a part of the given group.
func UserInGroup(username, groupname string) (bool, error) {
groups, err := Groups()
if err != nil {
return false, err
}
for _, group := range groups {
if group.Name == groupname && tabular.StrIn(username, group.Users) {
return true, nil
}
}
return false, nil
}
开发者ID:allenbhuiyan,项目名称:distributive,代码行数:13,代码来源:usrstatus.go
示例10: systemctlSock
// systemctlSock is an abstraction of systemctlSockPath and systemctlSockUnit,
// it reads from `systemctl list-sockets` and sees if the value is in the
// appropriate column.
func systemctlSock(value string, column string) (exitCode int, exitMessage string) {
outstr := wrkutils.CommandOutput(exec.Command("systemctl", "list-sockets"))
lines := tabular.Lines(outstr)
msg := "systemctl list-sockers didn't output enough rows"
wrkutils.IndexError(msg, len(lines)-4, lines)
unlines := tabular.Unlines(lines[:len(lines)-4])
table := tabular.SeparateOnAlignment(unlines)
values := tabular.GetColumnByHeader(column, table)
if tabular.StrIn(value, values) {
return 0, ""
}
return wrkutils.GenericError("Socket not found", value, values)
}
开发者ID:pinterb,项目名称:distributive,代码行数:16,代码来源:systemctl.go
示例11: Status
func (chk Module) Status() (int, string, error) {
// kernelModules returns a list of all Modules that are currently loaded
// TODO just read from /proc/Modules
kernelModules := func() (Modules []string) {
cmd := exec.Command("/sbin/lsmod")
return chkutil.CommandColumnNoHeader(0, cmd)
}
Modules := kernelModules()
if tabular.StrIn(chk.name, Modules) {
return errutil.Success()
}
return errutil.GenericError("Module is not loaded", chk.name, Modules)
}
开发者ID:nyanshak,项目名称:distributive,代码行数:13,代码来源:misc.go
示例12: New
func (chk SystemctlUnitFileStatus) New(params []string) (chkutil.Check, error) {
if len(params) != 2 {
return chk, errutil.ParameterLengthError{2, params}
}
validStatuses := []string{"static", "enabled", "disabled"}
if !tabular.StrIn(strings.ToLower(params[1]), validStatuses) {
validStatusesStr := "static | enabled | disabled"
return chk, errutil.ParameterTypeError{params[1], validStatusesStr}
}
chk.unit = params[0]
chk.status = params[1]
return chk, nil
}
开发者ID:allenbhuiyan,项目名称:distributive,代码行数:13,代码来源:systemctl.go
示例13: userInGroup
// userInGroup checks whether or not a given user is in a given group
func userInGroup(parameters []string) (exitCode int, exitMessage string) {
user := parameters[0]
group := parameters[0]
groups := getGroups()
for _, g := range groups {
if g.Name == group {
if tabular.StrIn(user, g.Users) {
return 0, ""
}
return wrkutils.GenericError("User not found in group", user, g.Users)
}
}
return groupNotFound(group)
}
开发者ID:pinterb,项目名称:distributive,代码行数:15,代码来源:users-and-groups.go
示例14: module
// module checks to see if a kernel module is installed
func module(parameters []string) (exitCode int, exitMessage string) {
// kernelModules returns a list of all modules that are currently loaded
// TODO just read from /proc/modules
kernelModules := func() (modules []string) {
cmd := exec.Command("/sbin/lsmod")
return wrkutils.CommandColumnNoHeader(0, cmd)
}
name := parameters[0]
modules := kernelModules()
if tabular.StrIn(name, modules) {
return 0, ""
}
return wrkutils.GenericError("Module is not loaded", name, modules)
}
开发者ID:pinterb,项目名称:distributive,代码行数:15,代码来源:misc.go
示例15: New
func (chk RepoExistsURI) New(params []string) (chkutil.Check, error) {
if len(params) != 2 {
return chk, errutil.ParameterLengthError{2, params}
}
re, err := regexp.Compile(params[1])
if err != nil {
return chk, errutil.ParameterTypeError{params[1], "regexp"}
}
chk.re = re
if !tabular.StrIn(params[0], keys) {
return chk, errutil.ParameterTypeError{params[0], "package manager"}
}
chk.manager = params[0]
return chk, nil
}
开发者ID:TanyaCouture,项目名称:distributive,代码行数:15,代码来源:packages.go
示例16: 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
示例17: Status
func (chk Up) Status() (int, string, error) {
// getUpInterfaces returns all the names of the interfaces that are up
getUpInterfaces := func() (interfaceNames []string) {
for _, iface := range netstatus.GetInterfaces() {
if iface.Flags&net.FlagUp != 0 {
interfaceNames = append(interfaceNames, iface.Name)
}
}
return interfaceNames
}
upInterfaces := getUpInterfaces()
if tabular.StrIn(chk.name, upInterfaces) {
return errutil.Success()
}
return errutil.GenericError("Interface is not up", chk.name, upInterfaces)
}
开发者ID:allenbhuiyan,项目名称:distributive,代码行数:17,代码来源:network.go
示例18: pacmanIgnore
// pacmanIgnore checks to see whether a given package is in /etc/pacman.conf's
// IgnorePkg setting
func pacmanIgnore(parameters []string) (exitCode int, exitMessage string) {
pkg := parameters[0]
path := "/etc/pacman.conf"
data := wrkutils.FileToString(path)
re := regexp.MustCompile(`[^#]IgnorePkg\s+=\s+.+`)
find := re.FindString(data)
var packages []string
if find != "" {
spl := strings.Split(find, " ")
wrkutils.IndexError("Not enough lines in "+path, 2, spl)
packages = spl[2:] // first two are "IgnorePkg" and "="
if tabular.StrIn(pkg, packages) {
return 0, ""
}
}
msg := "Couldn't find package in IgnorePkg"
return wrkutils.GenericError(msg, pkg, packages)
}
开发者ID:pinterb,项目名称:distributive,代码行数:20,代码来源:packages.go
示例19: New
func (chk Checksum) New(params []string) (chkutil.Check, error) {
if len(params) != 3 {
return chk, errutil.ParameterLengthError{3, params}
}
valid := []string{"MD5", "SHA1", "SHA224", "SHA256", "SHA384", "SHA512"}
if !tabular.StrIn(strings.ToUpper(params[0]), valid) {
return chk, errutil.ParameterTypeError{params[0], "algorithm"}
}
chk.algorithm = params[0]
path := params[2]
if _, err := os.Stat(path); err != nil {
return chk, errutil.ParameterTypeError{path, "filepath"}
}
chk.path = path
// TODO validate length of checksum string
chk.expectedChksum = params[1]
return chk, nil
}
开发者ID:allenbhuiyan,项目名称:distributive,代码行数:18,代码来源:filesystem.go
示例20: up
// up determines if a network interface is up and running or not
func up(parameters []string) (exitCode int, exitMessage string) {
// getUpInterfaces returns all the names of the interfaces that are up
getUpInterfaces := func() (interfaceNames []string) {
for _, iface := range getInterfaces() {
if iface.Flags&net.FlagUp != 0 {
interfaceNames = append(interfaceNames, iface.Name)
}
}
return interfaceNames
}
name := parameters[0]
upInterfaces := getUpInterfaces()
if tabular.StrIn(name, upInterfaces) {
return 0, ""
}
return wrkutils.GenericError("Interface is not up", name, upInterfaces)
}
开发者ID:orimarti,项目名称:distributive,代码行数:19,代码来源:network.go
注:本文中的github.com/CiscoCloud/distributive/tabular.StrIn函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论