goshell

package
v0.0.0-...-4a92715 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const RequestIdKey key = "X-Request-Id"

RequestIdKey is the key used to store the request ID in the context or header.

Variables

This section is empty.

Functions

func DefaultLoggerConfig

func DefaultLoggerConfig() zap.Config

func ErrorHandler

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

func HttpRequestIdMiddleware

func HttpRequestIdMiddleware(next http.Handler) http.Handler

HttpRequestIdMiddleware is a middleware that adds a unique request ID to the request context.

func Logger

func Logger(ctx context.Context) *zap.Logger

Logger extracts a zap logger from a context, providing a default logger if one is not present It's recommended that you do not change the logger config too much from the default because when you use this method we will not respect that configuration

func NewHttpServer

func NewHttpServer(baseContext context.Context, mux goa.Muxer) *http.Server

NewHttpServer creates a new HTTP server with some default middlewares like HttpRequestIdMiddleware. You can of course update some config on the http.Server like timeouts or even replace the handler all together. This method expects that a http.Muxer with already mounted endpoints and endpoint middlewares.

By default, the server will use zap.Logger through the log.Logger wrapper to log errors.

func NewInternalError

func NewInternalError() *goa.ServiceError

func NewLogger

func NewLogger() *zap.Logger

NewLogger returns a new zap logger. This logger is configured to log at InfoLevel and above We are using this logger instead of zap.NewProduction because by default it's configured to sample the logs Additionally, we this log will not fail to be created which simplifies what things could go wrong

func NewLoggerWithConfig

func NewLoggerWithConfig(config zap.Config) *zap.Logger

NewLoggerWithConfig returns a new zap logger. This logger would use the config provided by the caller. You're only able to configure to set the JSON EncoderWithLogs and the level. The output is defaulted to stdout.

func NewStdErrorLogger

func NewStdErrorLogger(l *zap.Logger) *stdlog.Logger

func RequestDecoderWithLogs

func RequestDecoderWithLogs(r *stdhttp.Request) http.Decoder

func RequestEncoderWithLogs

func RequestEncoderWithLogs(r *stdhttp.Request) http.Encoder

func ResponseDecoderFuncWithLogs

func ResponseDecoderFuncWithLogs(ctx context.Context) func(r *stdhttp.Response) http.Decoder

func ResponseEncoderWithLogs

func ResponseEncoderWithLogs(ctx context.Context, r stdhttp.ResponseWriter) http.Encoder

func WithLogger

func WithLogger(ctx context.Context, l *zap.Logger) context.Context

WithLogger attaches a zap logger to a given context, returning the new updated context

Types

type DecoderWithLogs

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

func (DecoderWithLogs) Decode

func (d DecoderWithLogs) Decode(v interface{}) error

type EncoderWithLogs

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

func (EncoderWithLogs) Encode

func (e EncoderWithLogs) Encode(v interface{}) error

type EndpointMiddleware

type EndpointMiddleware func(goa.Endpoint) goa.Endpoint // EndpointMiddleware are executed around the endpoint handler.

func EndpointLoggerInjectionMiddleware

func EndpointLoggerInjectionMiddleware() EndpointMiddleware

EndpointLoggerInjectionMiddleware Injects the logger into the context with shared info of the request i.e. the request ID

func EndpointRecoverMiddleware

func EndpointRecoverMiddleware() EndpointMiddleware

func EndpointRequestLogMiddleware

func EndpointRequestLogMiddleware() EndpointMiddleware

EndpointRequestLogMiddleware waits for the request to complete logging the outcome of it.

Jump to

Keyboard shortcuts

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