utils

package module
v6.0.0-...-6862f37 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2020 License: MIT Imports: 8 Imported by: 0

README

go-utils

Golang routines and utils

How to use

go get gopkg.in/toggly/go-utils.v1

Documentation

Index

Constants

View Source
const (
	// XRequestID gets name of header
	XRequestID = "X-Toggly-Request-Id"
	// XServiceName gets service name in header
	XServiceName = "X-Toggly-Service-Name"
	// XServiceVersion gets version
	XServiceVersion = "X-Toggly-Service-Version"
	// ContextReqIDKey gets key for request id
	ContextReqIDKey contextKey = iota
	// ContextVersionKey gets key for version
	ContextVersionKey contextKey = iota
)

Variables

This section is empty.

Functions

func GenerateUUID

func GenerateUUID() string

GenerateUUID gets UUID v4 string

func GetRealIPAddr

func GetRealIPAddr(r *http.Request) string

GetRealIPAddr gets real IP Addr from request's headers

func RequestIDCtx

func RequestIDCtx(next http.Handler) http.Handler

RequestIDCtx adds request id to context

func ServiceInfo

func ServiceInfo(name string, version string) func(http.Handler) http.Handler

ServiceInfo adds service information to the response header

func VersionCtx

func VersionCtx(version string) func(next http.Handler) http.Handler

VersionCtx adds api version to context

Types

type LogFields

type LogFields map[string]interface{}

LogFields type

type StructuredLogger

type StructuredLogger struct {
	Logger   *logging.Logger
	R        *http.Request
	Excludes []string
}

StructuredLogger struct

func (*StructuredLogger) Debugf

func (l *StructuredLogger) Debugf(format string, args ...interface{})

Debugf wraps logger.Debugf

func (*StructuredLogger) Error

func (l *StructuredLogger) Error(format string)

Error wraps logger.Error

func (*StructuredLogger) Errorf

func (l *StructuredLogger) Errorf(format string, args ...interface{})

Errorf wraps logger.Errorf

func (*StructuredLogger) Infof

func (l *StructuredLogger) Infof(format string, args ...interface{})

Infof wraps logger.Infof

func (*StructuredLogger) NewLogEntry

func (l *StructuredLogger) NewLogEntry(r *http.Request) middleware.LogEntry

NewLogEntry method

func (*StructuredLogger) Warningf

func (l *StructuredLogger) Warningf(format string, args ...interface{})

Warningf wraps logger.Warningf

type StructuredLoggerEntry

type StructuredLoggerEntry struct {
	Logger *logging.Logger
	Fields LogFields
}

StructuredLoggerEntry struct

func (*StructuredLoggerEntry) Panic

func (l *StructuredLoggerEntry) Panic(v interface{}, stack []byte)

Panic method

func (*StructuredLoggerEntry) Write

func (l *StructuredLoggerEntry) Write(status, bytes int, header http.Header, elapsed time.Duration, intr interface{})

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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