util

package
v0.3.7 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2015 License: MPL-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// EtcdFlags is a convenience variable for simple etcd cli arguments
	EtcdFlags = []cli.Flag{
		cli.StringSliceFlag{
			Name:   "peers, C",
			EnvVar: "ETCD_PEERS",
			Value:  &cli.StringSlice{},
			Usage:  "a machine address in the etcd cluster (default: \"127.0.0.1:4001\"), may be specified multiple times",
		},
		cli.StringFlag{
			Name:   "ca-file",
			EnvVar: "ETCD_CA_FILE",
			Usage:  "etcd certificate authority file",
		},
		cli.StringFlag{
			Name:   "cert-file",
			EnvVar: "ETCD_CERT_FILE",
			Usage:  "etcd tls client certificate file",
		},
		cli.StringFlag{
			Name:   "key-file",
			EnvVar: "ETCD_KEY_FILE",
			Usage:  "etcd tls client key file",
		},
		cli.BoolFlag{
			Name:   "no-sync",
			EnvVar: "ETCD_NO_SYNC",
			Usage:  "don't synchronize etcd cluster information before watching",
		},
		cli.BoolFlag{
			Name:   "use-default-gateway, d",
			EnvVar: "ETCD_USE_DEFAULT_GATEWAY",
			Usage:  "expose the default gateway as $ETCD_DEFAULT_GATEWAY",
		},
	}
)
View Source
var (

	// LogLevelFlag is a convenience variable for a simple log-level cli argument
	LogLevelFlag = cli.StringFlag{
		Name:   "log-level, l",
		EnvVar: "LOG_LEVEL",
		Value:  "WARN",
		Usage:  "set log level (DEBUG, INFO, WARN, ERR)",
	}
)

Functions

func ChangeLogLevel added in v0.2.0

func ChangeLogLevel(minLevel string)

ChangeLogLevel updates the minimum log level

func DefaultRoute added in v0.2.1

func DefaultRoute() (ip net.IP, err error)

DefaultRoute will read /proc/net/route and look for an IPv4 default gateway. IPv6 gateways will not be found. It will then return the gateway as an IP.

func GetEtcdClient added in v0.2.0

func GetEtcdClient(c *EtcdConfig) (*etcd.Client, error)

GetEtcdClient returns an etcd Client. Uses endpoints.

func InitLogger

func InitLogger(minLevel string)

InitLogger should be called once at the start of each application to enable the output log filtering. It depends on a cli context GlobalString "log-level" to set the MinLevel.

func InitLoggerCli added in v0.1.0

func InitLoggerCli(c *cli.Context)

InitLoggerCli should be called once at the start of each application to enable the output log filtering. It depends on a cli context GlobalString "log-level" to set the MinLevel.

func NewLogger added in v0.1.0

func NewLogger(level string) *log.Logger

NewLogger returns a pointer to an object that implements the log.Logger interface but otherwise works the same as the standard logger.

func Render

func Render(w http.ResponseWriter, req *http.Request, status int, data interface{})

Render looks for a ".pb" extension and renders either the protobuf or JSON message properly to an http.ResponseWriter

func RenderPB

func RenderPB(w http.ResponseWriter, status int, msg proto.Message)

RenderPB renders a proto.Message properly to an http.ResponseWriter

func Round

func Round(val float64) float64

Round to integral value, regardless of rounding direction

Types

type EtcdConfig added in v0.2.0

type EtcdConfig struct {
	TLS               *transport.TLSInfo
	Peers             []string
	Sync              bool
	UseDefaultGateway bool
}

EtcdConfig includes a peers list and any TLS info.

func NewEtcdConfig added in v0.2.0

func NewEtcdConfig(c *cli.Context) *EtcdConfig

NewEtcdConfig creates an etcdConfig declaration from the command line context provided by cli. This includes potential TLS files.

type HealthData added in v0.1.0

type HealthData struct {
	Health    bool   `json:"health"`
	RequestID string `json:"request_id"`
}

HealthData is used for /health endpoints

type StatsData added in v0.1.0

type StatsData struct {
	Stats     map[string]int64 `json:"stats"`
	RequestID string           `json:"request_id"`
}

StatsData is used for /stats endpoints

Jump to

Keyboard shortcuts

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