utils

package
v0.0.0-...-dcb838f Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2017 License: BSD-3-Clause Imports: 10 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DelConsulKv = func(client *consul.Client, key string) error {
	log.Printf("consul delete `%s`", key)
	_, err := client.KV().Delete(strings.TrimPrefix(key, "/"), nil)
	return err
}
View Source
var DeletePluginData = func(plugin string, packageName string, consulAddress string) error {
	log.Println(color.YellowString("Delete %s for %s package in consul", plugin, packageName))
	consulApi, err := ConsulClient(consulAddress)
	if err != nil {
		return err
	}

	return DelConsulKv(consulApi, "services/data/"+packageName+"/"+plugin)
}
View Source
var PutConsulKv = func(client *consul.Client, key string, value string) error {
	log.Printf("consul put `%s`: %s", key, value)
	_, err := client.KV().Put(&consul.KVPair{Key: strings.TrimPrefix(key, "/"), Value: []byte(value)}, nil)
	return err
}
View Source
var RandomString = func(length uint) string {
	b := make([]rune, length)
	for i := range b {
		b[i] = allLetters[rand.Intn(len(allLetters))]
	}
	return string(b)
}
View Source
var RegisterPluginData = func(plugin string, packageName string, data string, consulAddress string) error {
	consulApi, err := ConsulClient(consulAddress)
	if err != nil {
		return err
	}

	return PutConsulKv(consulApi, "services/data/"+packageName+"/"+plugin, data)
}
View Source
var RunCmdWithEnv = func(cmdline string, env map[string]string) error {
	log.Println(color.YellowString("> %s", cmdline))

	cmd := exec.Command("/bin/bash", "-c", cmdline)

	cmd.Env = os.Environ()

	for k, v := range env {
		cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%v", k, v))
	}

	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr

	return cmd.Run()
}

Functions

func ConsulClient

func ConsulClient(consulAddress string) (*consul.Client, error)

func Contains

func Contains(elm string, list []string) bool

func Filter

func Filter(vs []string, f func(string) bool) []string

func ListConsulKv

func ListConsulKv(client *consul.Client, prefix string, q *consul.QueryOptions) (consul.KVPairs, error)

func MapsEqual

func MapsEqual(a, b map[string]string) bool

func MarkAsOutdated

func MarkAsOutdated(client *consul.Client, name string, delay time.Duration) error

func MergeMaps

func MergeMaps(maps ...map[string]string) map[string]string

func RunCmd

func RunCmd(cmdline string, a ...interface{}) error

func RunParallelSshCmd

func RunParallelSshCmd(cluster, sshUser, cmd string, maxProcs int) error

func RunSingleSshCmd

func RunSingleSshCmd(cluster, sshUser, cmd string) error

func RunSshCmd

func RunSshCmd(cluster, sshUser, cmd string) error

func Substr

func Substr(s string, pos, length int) string

Types

type BySortIndex

type BySortIndex []map[string]string

func (BySortIndex) Len

func (a BySortIndex) Len() int

func (BySortIndex) Less

func (a BySortIndex) Less(i, j int) bool

func (BySortIndex) Swap

func (a BySortIndex) Swap(i, j int)

Directories

Path Synopsis
Package gabs implements a simplified wrapper around creating and parsing JSON.
Package gabs implements a simplified wrapper around creating and parsing JSON.

Jump to

Keyboard shortcuts

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