goautils

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2021 License: MIT Imports: 8 Imported by: 0

README

goa utils

This is just a collection of something I find useful while writing applications using https://goa.design/

Logging

I try not to use external dependencies when writing libraries, so for logging I stand by the approach of https://github.com/logur/logur.

You can just pass a logger that implements this simple interface (which is compatible with the logur one):

type logger interface {
	Debug(msg string, fields ...map[string]interface{})
	Info(msg string, fields ...map[string]interface{})
	Error(msg string, fields ...map[string]interface{})
}

For example if you want to use logrus:

import (
	"github.com/sirupsen/logrus"
	logrusadapter "logur.dev/adapter/logrus"
)

	logrusLog := logrus.New()
	log := logrusadapter.New(logrusLog)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorHandler added in v0.0.2

func ErrorHandler(log logger) func(context.Context, http.ResponseWriter, error)

ErrorHandler returns a function that writes and logs the given error.

func ListenGracefully

func ListenGracefully(addr string, handler http.Handler, log logger)

ListenGracefully will start a listener on a specified address and blocks until it receives an interrupt or a sigterm, at which point it will start a graceful shutdown and finally return. You MUST provide a logger, it's the only way to see if there are errors

func RequestID added in v0.0.3

func RequestID() func(http.Handler) http.Handler

RequestID is a wrapper around the goa middleware with the same name, except it also augments the ctxlog with the request id

Types

This section is empty.

Jump to

Keyboard shortcuts

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