checks

package
v0.0.0-...-59a6a0f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 19, 2016 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package checks defines a Checker and several implementations of it for performing system checks regardless of how are they being used.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Checker

type Checker interface {
	FileExists(path string) (bool, error)
	FileContains(path, substr string) (bool, error)
	ProcessIsRunning(name string) (bool, error)
}

Checker defines all allowed checks.

type MockCheck

type MockCheck struct{}

MockCheck is an implementation of Checker that can be used for tests.

func (MockCheck) FileContains

func (u MockCheck) FileContains(path, substr string) (bool, error)

FileContains mocks the check if given sub-string is contained into a file.

func (MockCheck) FileExists

func (MockCheck) FileExists(path string) (bool, error)

FileExists mocks the checks if a file exists.

func (MockCheck) ProcessIsRunning

func (MockCheck) ProcessIsRunning(name string) (bool, error)

ProcessIsRunning mocks the checks if given process name is currently running.

type NativeCheck

type NativeCheck struct{}

NativeCheck implements the Checker interface using only NativeCheck Go implementation (i.e. without shelling out) which is intended to be platform-independed.

func (NativeCheck) FileContains

func (NativeCheck) FileContains(path, substr string) (bool, error)

FileContains checks if given sub-string is contained into a file. Current implementation uses bufio.Scanner for that purpose, reading files line by line.

func (NativeCheck) FileExists

func (NativeCheck) FileExists(path string) (bool, error)

FileExists checks if a file exists using Go's os package.

func (NativeCheck) ProcessIsRunning

func (NativeCheck) ProcessIsRunning(name string) (bool, error)

ProcessIsRunning checks if given process name is currently running.

- Darwin uses the sysctl syscall to retrieve the process table, via cgo.

- On Unix uses the procfs at /proc to inspect the process tree.

- On Windows uses the Windows API, and methods such as CreateToolhelp32Snapshot to get a point-in-time snapshot of the process table.

type UnixShellCheck

type UnixShellCheck struct{}

UnixShellCheck implements the Checker interface using explicitly shell commands intended to work on Unix machines only.

The nature of requied checks are easily doable with simple commands while check result being deducable simply by checking the exit status.

func (UnixShellCheck) FileContains

func (u UnixShellCheck) FileContains(path, substr string) (bool, error)

FileContains checks if given sub-string is contained into a file, using `grep` and returns true if the status code of it is 0 (zero).

func (UnixShellCheck) FileExists

func (u UnixShellCheck) FileExists(path string) (bool, error)

FileExists checks if a file exists using the `stat` command.

func (UnixShellCheck) ProcessIsRunning

func (u UnixShellCheck) ProcessIsRunning(name string) (bool, error)

ProcessIsRunning checks if given process name is currently running using `ps` .

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL