mirror of
https://github.com/kataras/iris.git
synced 2025-03-14 08:26:26 +01:00
minor (see previous commit)
This commit is contained in:
parent
07806ba270
commit
b063fbf3c8
|
@ -41,6 +41,16 @@ func main() {
|
|||
ac.SetFormatter(&accesslog.Template{
|
||||
Text: "{{.Now.Format .TimeFormat}}|{{.Latency}}|{{.Method}}|{{.Path}}|{{.RequestValuesLine}}|{{.Code}}|{{.Request}}|{{.Response}}|\n",
|
||||
})
|
||||
|
||||
Set custom request fields:
|
||||
ac.AddField(func(ctx iris.Context) (string, interface{}) {
|
||||
v := ctx.RemoteAddr()
|
||||
if v == "" {
|
||||
return "", nil
|
||||
}
|
||||
// the log entry name and its value.
|
||||
return "IP", v
|
||||
})
|
||||
*/
|
||||
|
||||
defer ac.Close()
|
||||
|
|
|
@ -1129,6 +1129,8 @@ type (
|
|||
// The structure contains struct tags for JSON, form, XML, YAML and TOML.
|
||||
// Look the `GetReferrer() Referrer` and `goreferrer` external package.
|
||||
Referrer struct {
|
||||
// The raw refer(r)er URL.
|
||||
Raw string `json:"raw" form:"raw" xml:"Raw" yaml:"Raw" toml:"Raw"`
|
||||
Type ReferrerType `json:"type" form:"referrer_type" xml:"Type" yaml:"Type" toml:"Type"`
|
||||
Label string `json:"label" form:"referrer_form" xml:"Label" yaml:"Label" toml:"Label"`
|
||||
URL string `json:"url" form:"referrer_url" xml:"URL" yaml:"URL" toml:"URL"`
|
||||
|
@ -1147,6 +1149,11 @@ type (
|
|||
ReferrerGoogleSearchType = goreferrer.GoogleSearchType
|
||||
)
|
||||
|
||||
// String returns the raw ref url.
|
||||
func (ref Referrer) String() string {
|
||||
return ref.Raw
|
||||
}
|
||||
|
||||
// Contains the available values of the goreferrer enums.
|
||||
const (
|
||||
ReferrerInvalid ReferrerType = iota
|
||||
|
@ -1187,6 +1194,7 @@ func (ctx *Context) GetReferrer() Referrer {
|
|||
|
||||
if ref := goreferrer.DefaultRules.Parse(refURL); ref.Type > goreferrer.Invalid {
|
||||
return Referrer{
|
||||
Raw: refURL,
|
||||
Type: ReferrerType(ref.Type),
|
||||
Label: ref.Label,
|
||||
URL: ref.URL,
|
||||
|
|
|
@ -257,7 +257,7 @@ func (ac *AccessLog) after(ctx *context.Context, lat time.Duration, method, path
|
|||
var fields []memstore.Entry
|
||||
|
||||
if n := len(ac.Fields); n > 0 {
|
||||
fields = make([]memstore.Entry, n)
|
||||
fields = make([]memstore.Entry, 0, n)
|
||||
|
||||
for _, extract := range ac.Fields {
|
||||
key, value := extract(ctx)
|
||||
|
|
Loading…
Reference in New Issue
Block a user