util

package
v0.0.0-...-e25bc3e Latest Latest
Warning

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

Go to latest
Published: May 13, 2021 License: MIT Imports: 18 Imported by: 29

Documentation

Overview

Package util defines utilities for bosun.

Index

Constants

View Source
const (
	Separator = filepath.Separator
)

Variables

View Source
var (
	// ErrPath is returned by Command if the program is not in the PATH.
	ErrPath = errors.New("program not in PATH")
	// ErrTimeout is returned by Command if the program timed out.
	ErrTimeout = errors.New("program killed after timeout")

	// Debug enables debug logging.
	Debug = false
)
View Source
var ErrBadPattern = errors.New("syntax error in pattern")

ErrBadPattern indicates a globbing pattern was malformed.

Functions

func Btoi

func Btoi(b bool) int

func Command

func Command(timeout time.Duration, stdin io.Reader, name string, arg ...string) (io.Reader, error)

Command executes the named program with the given arguments. If it does not exit within timeout, it is sent SIGINT (if supported by Go). After another timeout, it is killed.

func GetHostManager

func GetHostManager() host.Manager

func InitHostManager

func InitHostManager(customHostname string, useFullHostName bool)

func MarshalGzipJson

func MarshalGzipJson(data interface{}) ([]byte, error)

func Match

func Match(pattern, name string) (matched bool, err error)

Match returns true if name matches any of the patterns. The pattern syntax is:

pattern:
	{ term } [ '|' { term } '|' ... ]
term:
	'*'         matches any sequence of non-Separator characters
	'?'         matches any single non-Separator character
	'[' [ '^' ] { character-range } ']'
	            character class (must be non-empty)
	c           matches character c (c != '*', '?', '\\', '[')
	'\\' c      matches character c

character-range:
	c           matches character c (c != '\\', '-', ']')
	'\\' c      matches character c
	lo '-' hi   matches character c for lo <= c <= hi

Match requires pattern to match all of name, not just a substring. The only possible returned error is ErrBadPattern, when pattern is malformed.

func NameMatches

func NameMatches(name string, regexes []*regexp.Regexp) bool

func NewSingleHostProxy

func NewSingleHostProxy(target *url.URL) *httputil.ReverseProxy

Creates a new http Proxy that forwards requests to the specified url. Differs from httputil.NewSingleHostReverseProxy only in that it properly sets the host header.

func ReadCommand

func ReadCommand(line func(string) error, name string, arg ...string) error

ReadCommand runs command name with args and calls line for each line from its stdout. Command is interrupted (if supported by Go) after 10 seconds and killed after 20 seconds.

func ReadCommandTimeout

func ReadCommandTimeout(timeout time.Duration, line func(string) error, stdin io.Reader, name string, arg ...string) error

ReadCommandTimeout is the same as ReadCommand with a specifiable timeout. It can also take a []byte as input (useful for chaining commands).

func SetHostManager

func SetHostManager(hm host.Manager)

func UnmarshalGzipJson

func UnmarshalGzipJson(b []byte, dst interface{}) error

Types

This section is empty.

Jump to

Keyboard shortcuts

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