util

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2019 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckPort

func CheckPort(port string) error

CheckPort checks if a port is in the valid 0 <= port <= 65535 range

func CheckTCPAddress

func CheckTCPAddress(address string) error

CheckTCPAddress checks if a passed TCP address is a valid listening address

func HashIDToString

func HashIDToString(hash string) (string, error)

HashIDToString decodes a HashID-encoded string into a normal string

func Healthz

func Healthz() http.HandlerFunc

Healthz responds to a HTTP healthcheck

func InitTracer

func InitTracer(serviceName string, logger *Logger) (ot.Tracer, io.Closer, error)

InitTracer returns an instance of Jaeger Tracer that samples 100% of traces and logs all spans to stdout.

func LoggerMiddleware

func LoggerMiddleware(inner http.Handler, logger *Logger) http.HandlerFunc

LoggerMiddleware is a decorator for a HTTP Request, adding structured logging functionality

func NewRouter

func NewRouter() *mux.Router

NewRouter returns a gorilla/mux router

func PrometheusMiddleware

func PrometheusMiddleware(h http.Handler, handler string, rm *RequestMetricHistogram) http.Handler

PrometheusMiddleware wraps a request for monitoring via Prometheus.

func StringToHashID

func StringToHashID(str string) (string, error)

StringToHashID converts a UTF-8 string into a HashID.

func TracerMiddleware

func TracerMiddleware(inner http.Handler, route Route) http.HandlerFunc

TracerMiddleware adds a Span to the request Context ready for other handlers to use it.

Types

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger is an adapter type for zap's SugaredLogger

func NewLogger

func NewLogger(level, serviceName string) (*Logger, error)

NewLogger creates a new Logger.

func (*Logger) Debug

func (l *Logger) Debug(args ...interface{})

Debug uses fmt.Sprint to log a templated message.

func (*Logger) Debugf

func (l *Logger) Debugf(msg string, args ...interface{})

Debugf uses fmt.Sprintf to log a templated message.

func (*Logger) Debugw

func (l *Logger) Debugw(msg string, kv ...interface{})

Debugw logs a message with some additional context. The variadic key-value pairs are treated as they are in With.

func (*Logger) Error

func (l *Logger) Error(msg string)

Error uses fmt.Sprint to construct and log a message.

func (*Logger) Errorw

func (l *Logger) Errorw(msg string, kv ...interface{})

Errorw logs a message with some additional context. The variadic key-value pairs are treated as they are in With.

func (*Logger) Fatal

func (l *Logger) Fatal(args ...interface{})

Fatal uses fmt.Sprint to log a templated message, then calls os.Exit.

func (*Logger) Fatalf

func (l *Logger) Fatalf(msg string, args ...interface{})

Fatalf uses fmt.Sprintf to log a templated message, then calls os.Exit.

func (*Logger) Fatalw

func (l *Logger) Fatalw(msg string, kv ...interface{})

Fatalw logs a message with some additional context, then calls os.Exit. The variadic key-value pairs are treated as they are in With.

func (*Logger) Info

func (l *Logger) Info(args ...interface{})

Info uses fmt.Sprint to log a templated message.

func (*Logger) Infof

func (l *Logger) Infof(msg string, args ...interface{})

Infof uses fmt.Sprintf to log a templated message.

func (*Logger) Infow

func (l *Logger) Infow(msg string, kv ...interface{})

Infow logs a message with some additional context. The variadic key-value pairs are treated as they are in With.

func (*Logger) Panic

func (l *Logger) Panic(args ...interface{})

Panic uses fmt.Sprint to log a templated message, then panics.

func (*Logger) Panicf

func (l *Logger) Panicf(msg string, args ...interface{})

Panicf uses fmt.Sprintf to log a templated message, then panics.

func (*Logger) Panicw

func (l *Logger) Panicw(msg string, kv ...interface{})

Panicw logs a message with some additional context, then panics The variadic key-value pairs are treated as they are in With.

func (*Logger) Sync

func (l *Logger) Sync()

Sync flushes any buffered log entries.

func (*Logger) Warn

func (l *Logger) Warn(args ...interface{})

Warn uses fmt.Sprint to log a templated message.

func (*Logger) Warnf

func (l *Logger) Warnf(msg string, args ...interface{})

Warnf uses fmt.Sprintf to log a templated message.

func (*Logger) Warnw

func (l *Logger) Warnw(msg string, kv ...interface{})

Warnw logs a message with some additional context. The variadic key-value pairs are treated as they are in With.

type RequestMetricHistogram

type RequestMetricHistogram struct {
	InFlightGauge prometheus.Gauge
	Counter       *prometheus.CounterVec
	Duration      *prometheus.HistogramVec
	ResponseSize  *prometheus.HistogramVec
}

RequestMetricHistogram defines a type of used metrics for a specific request, using Histograms for observations

func NewRequestMetricHistogram

func NewRequestMetricHistogram(durationBuckets, responseSizeBuckets []float64) *RequestMetricHistogram

NewRequestMetricHistogram creates a RequestMetricHistogram struct with sane defaults

type Route

type Route struct {
	Name        string
	Method      string
	Pattern     string
	HandlerFunc http.HandlerFunc
}

Route defines a specific route

type Routes

type Routes []Route

Routes defines a slice of all available API Routes

type Server added in v0.2.0

type Server interface {
	ServeHTTP(w http.ResponseWriter, r *http.Request)
}

Server is an interface for types that implement ServeHTTP. For now this is only used for testing but will possibly extended for refactoring at a later point.

Jump to

Keyboard shortcuts

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