-
Notifications
You must be signed in to change notification settings - Fork 0
/
loggin.go
39 lines (35 loc) · 833 Bytes
/
loggin.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
package main
import (
"go-kit-microservice-demo/service"
"fmt"
"github.com/go-kit/kit/log"
"time"
)
type LoggingMiddleware struct {
Logger log.Logger
Next service.Service
}
func (l LoggingMiddleware) Login(username, password string) (ret string, err error) {
defer func(begin time.Time) {
_ = l.Logger.Log(
"method", "login",
"input", fmt.Sprintf("username:%s, password:%s", username, password),
"output" , ret,
"took", time.Since(begin),
)
}(time.Now())
ret, _= l.Next.Login(username, password)
return
}
func (l LoggingMiddleware) Add (num1, num2 int) (ret int) {
defer func(begin time.Time) {
_ = l.Logger.Log(
"method", "add",
"input", fmt.Sprintf("num1:%d, num2:%d", num1, num2),
"output" , ret,
"took", time.Since(begin),
)
}(time.Now())
ret = l.Next.Add(num1, num2)
return
}