Documentation ¶
Index ¶
- Constants
- Variables
- func GetMiddlewareCreated(c slate.ServiceContainer) (slaterest.Middleware, error)
- func GetMiddlewareNoContent(c slate.ServiceContainer) (slaterest.Middleware, error)
- func GetMiddlewareOk(c slate.ServiceContainer) (slaterest.Middleware, error)
- func NewMiddleware(logger *slog.Logger, requestReader RequestReader, ...) (slaterest.Middleware, error)
- func RequestReaderDefault(ctx *gin.Context) (map[string]interface{}, error)
- type Provider
- type RequestReader
- type RequestReaderDecorator
- type ResponseReader
- type ResponseReaderDecorator
Constants ¶
const ( // ContainerID defines the id to be used as the container // registration id of a logging middleware instance factory function. ContainerID = slaterest.ContainerID + ".log" // ContainerOkID defines the id to be used as the // container registration id of a standard log middleware generator // for a 200(OK) status code. ContainerOkID = ContainerID + ".ok" // ContainerCreatedID defines the id to be used as // the container registration id of a standard log middleware generator // for a 201(Created) status code. ContainerCreatedID = ContainerID + ".created" // ContainerNoContentID defines the id to be used as // the container registration id of a standard log middleware generator // for a 204(NoContent) status code. ContainerNoContentID = ContainerID + ".no_content" )
const ( // EnvID defines the slate.slaterest.log package base environment variable name. EnvID = slaterest.EnvID + "_LOG" )
Variables ¶
var ( // RequestChannel defines the channel id to be used when // the log middleware sends the request logging signal to the logger // instance. RequestChannel = senv.String(EnvID+"_REQUEST_CHANNEL", "transport") // RequestLevel defines the logging level to be used when // the log middleware sends the request logging signal to the logger // instance. RequestLevel = envToLogLevel(EnvID+"_REQUEST_LEVEL", slog.DEBUG) // RequestMessage defines the request event logging message to // be used when the log middleware sends the logging signal to the logger // instance. RequestMessage = senv.String(EnvID+"_REQUEST_MESSAGE", "Request") // ResponseChannel defines the channel id to be used when the // log middleware sends the response logging signal to the logger instance. ResponseChannel = senv.String(EnvID+"_RESPONSE_CHANNEL", "transport") // ResponseLevel defines the logging level to be used when the // log middleware sends the response logging signal to the logger instance. ResponseLevel = envToLogLevel(EnvID+"_RESPONSE_LEVEL", slog.INFO) // ResponseMessage defines the response event logging message // to be used when the log middleware sends the logging signal to the // logger instance. ResponseMessage = senv.String(EnvID+"_RESPONSE_MESSAGE", "Response") // DecorateJSON flag that defines the decoration of the log entries // for JSON body content. DecorateJSON = senv.Bool(EnvID+"_DECORATE_JSON", true) // DecorateXML flag that defines the decoration of the log entries // for XML body content. DecorateXML = senv.Bool(EnvID+"_DECORATE_XML", false) )
Functions ¶
func GetMiddlewareCreated ¶
func GetMiddlewareCreated(c slate.ServiceContainer) (slaterest.Middleware, error)
GetMiddlewareCreated will try to retrieve the registered logging middleware for created responses instance from the application service container.
func GetMiddlewareNoContent ¶
func GetMiddlewareNoContent(c slate.ServiceContainer) (slaterest.Middleware, error)
GetMiddlewareNoContent will try to retrieve the registered logging middleware for no-content responses instance from the application service container.
func GetMiddlewareOk ¶
func GetMiddlewareOk(c slate.ServiceContainer) (slaterest.Middleware, error)
GetMiddlewareOk will try to retrieve the registered logging middleware for ok responses instance from the application service container.
func NewMiddleware ¶
func NewMiddleware( logger *slog.Logger, requestReader RequestReader, responseReader ResponseReader, ) (slaterest.Middleware, error)
NewMiddleware will instantiate a new middleware that will emit logging signals on a request event and on a response event.
Types ¶
type Provider ¶
type Provider struct{}
Provider defines the gapp-rest-log module service provider to be used on the application initialization to register the logging middleware service.
type RequestReader ¶
RequestReader defines the function used by the middleware that compose the logging request context object.
func NewRequestReaderDecoratorJSON ¶
func NewRequestReaderDecoratorJSON(reader RequestReader, model interface{}) (RequestReader, error)
NewRequestReaderDecoratorJSON will instantiate a new request event context reader JSON decorator used to parse the request body as a JSON and add the parsed content into the logging data.
func NewRequestReaderDecoratorXML ¶
func NewRequestReaderDecoratorXML(reader RequestReader, model interface{}) (RequestReader, error)
NewRequestReaderDecoratorXML will instantiate a new request event context reader XML decorator used to parse the request body as an XML and add the parsed content into the logging data.
type RequestReaderDecorator ¶
type RequestReaderDecorator func(reader RequestReader, model interface{}) (RequestReader, error)
RequestReaderDecorator defines a function used to decorate a request reader output.
type ResponseReader ¶
ResponseReader defines the interface methods of a response context reader used to compose the data to be sent to the logger on a response event.
func NewResponseReaderDecoratorJSON ¶
func NewResponseReaderDecoratorJSON(reader ResponseReader, model interface{}) (ResponseReader, error)
NewResponseReaderDecoratorJSON will instantiate a new response event context reader JSON decorator used to parse the response body as a JSON and add the parsed content into the logging data.
func NewResponseReaderDecoratorXML ¶
func NewResponseReaderDecoratorXML(reader ResponseReader, model interface{}) (ResponseReader, error)
NewResponseReaderDecoratorXML will instantiate a new response event context reader XML decorator used to parse the response body as an XML and add the parsed content into the logging data.
func NewResponseReaderDefault ¶
func NewResponseReaderDefault(statusCode int) ResponseReader
NewResponseReaderDefault generates a new default response reader with the defined expected status code.
type ResponseReaderDecorator ¶
type ResponseReaderDecorator func(reader ResponseReader, model interface{}) (ResponseReader, error)
ResponseReaderDecorator defines a function used to decorate a response reader output.
Source Files ¶
- container.go
- errors.go
- globals.go
- middleware.go
- provider.go
- request_reader.go
- request_reader_decorator.go
- request_reader_decorator_json.go
- request_reader_decorator_xml.go
- request_reader_default.go
- response_reader.go
- response_reader_decorator.go
- response_reader_decorator_json.go
- response_reader_decorator_xml.go
- response_reader_default.go
- response_writer.go