Latest Threat ResearchGlassWorm Loader Hits Open VSX via Developer Account Compromise.Details
Socket
Book a DemoInstallSign in
Socket

vimagination.zapto.org/httplog

Package Overview
Dependencies
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vimagination.zapto.org/httplog

Go Modules
Version
v0.0.0-20251210183905-7e1244844f4d
Version published
Created
Source

httplog

-- import "vimagination.zapto.org/httplog"

Package httplog is used to create wrappers around http.Handler's to gather information about a request and its response.

Usage

const DefaultFormat = "{{.RemoteAddr}} - {{.URL.User.Username}} - [{{.StartTime.Format \"02/01/2006:15:04:05 +0700\"}}] \"{{.Method}} {{.URL.RequestURI}} {{.Proto}}\" {{.Status}} {{.RequestLength}} {{.StartTime.Sub .EndTime}}"

DefaultFormat is a simple template to output log data in something reminiscent on the Apache default format.

func Wrap

func Wrap(m http.Handler, l Logger) http.Handler

Wrap wraps an existing http.Handler and collects data about the request and response and passes it to a logger.

type Details

type Details struct {
	*http.Request
	Status, ResponseLength int
	StartTime, EndTime     time.Time
}

Details is a collection of data about the request and response.

type Logger

type Logger interface {
	Log(d Details)
}

Logger allows clients to specify how collected data is handled.

func NewWriteLogger

func NewWriteLogger(w io.Writer, format string) (Logger, error)

NewWriteLogger uses the given format as a template to write log data to the given io.Writer.

type WriteLogger

type WriteLogger struct {
}

WriteLogger is a Logger which formats log data to a given template and writes it to a given io.Writer.

func (*WriteLogger) Log

func (w *WriteLogger) Log(d Details)

Log satisfies the Logger interface.

FAQs

Package last updated on 10 Dec 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts