-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.go
56 lines (44 loc) · 1.25 KB
/
log.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright 2021 Jérôme Sautret. All rights reserved. Use of this
// source code is governed by an Apache License 2.0 that can be found
// in the LICENSE file.
package logpredicate
import (
"fmt"
"github.com/jsautret/genapid/ctx"
"github.com/jsautret/genapid/genapid"
"github.com/rs/zerolog"
)
// Name of the predicate
var Name = "log"
// Predicate is the conf.Plugin interface that describes the predicate
type Predicate struct {
name string
params struct { // Params accepted by the predicate
Msg interface{} `validate:"required"`
}
}
// Call evaluates a predicate
func (predicate *Predicate) Call(log zerolog.Logger, c *ctx.Ctx) bool {
log.Info().Str("log", fmt.Sprintf("%v", predicate.params.Msg)).Msg("")
return true
}
// Generic interface //
// Result returns data set by the predicate
func (predicate *Predicate) Result() ctx.Result {
// no data is set by log
return ctx.Result{}
}
// Name returns the name of the predicate
func (predicate *Predicate) Name() string {
return predicate.name
}
// Params returns a reference to the params struct of the predicate
func (predicate *Predicate) Params() interface{} {
return &predicate.params
}
// New returns a new Predicate
func New() genapid.Predicate {
return &Predicate{
name: Name,
}
}