7 "github.com/go-kit/kit/log"
10 // Middleware describes a service (as opposed to endpoint) middleware.
11 type Middleware func(Service) Service
13 func LoggingMiddleware(logger log.Logger) Middleware {
14 return func(next Service) Service {
15 return &loggingMiddleware{
22 type loggingMiddleware struct {
27 func (mw loggingMiddleware) PostProfile(ctx context.Context, p Profile) (err error) {
28 defer func(begin time.Time) {
29 mw.logger.Log("method", "PostProfile", "id", p.ID, "took", time.Since(begin), "err", err)
31 return mw.next.PostProfile(ctx, p)
34 func (mw loggingMiddleware) GetProfile(ctx context.Context, id string) (p Profile, err error) {
35 defer func(begin time.Time) {
36 mw.logger.Log("method", "GetProfile", "id", id, "took", time.Since(begin), "err", err)
38 return mw.next.GetProfile(ctx, id)
41 func (mw loggingMiddleware) PutProfile(ctx context.Context, id string, p Profile) (err error) {
42 defer func(begin time.Time) {
43 mw.logger.Log("method", "PutProfile", "id", id, "took", time.Since(begin), "err", err)
45 return mw.next.PutProfile(ctx, id, p)
48 func (mw loggingMiddleware) PatchProfile(ctx context.Context, id string, p Profile) (err error) {
49 defer func(begin time.Time) {
50 mw.logger.Log("method", "PatchProfile", "id", id, "took", time.Since(begin), "err", err)
52 return mw.next.PatchProfile(ctx, id, p)
55 func (mw loggingMiddleware) DeleteProfile(ctx context.Context, id string) (err error) {
56 defer func(begin time.Time) {
57 mw.logger.Log("method", "DeleteProfile", "id", id, "took", time.Since(begin), "err", err)
59 return mw.next.DeleteProfile(ctx, id)
62 func (mw loggingMiddleware) GetAddresses(ctx context.Context, profileID string) (addresses []Address, err error) {
63 defer func(begin time.Time) {
64 mw.logger.Log("method", "GetAddresses", "profileID", profileID, "took", time.Since(begin), "err", err)
66 return mw.next.GetAddresses(ctx, profileID)
69 func (mw loggingMiddleware) GetAddress(ctx context.Context, profileID string, addressID string) (a Address, err error) {
70 defer func(begin time.Time) {
71 mw.logger.Log("method", "GetAddress", "profileID", profileID, "addressID", addressID, "took", time.Since(begin), "err", err)
73 return mw.next.GetAddress(ctx, profileID, addressID)
76 func (mw loggingMiddleware) PostAddress(ctx context.Context, profileID string, a Address) (err error) {
77 defer func(begin time.Time) {
78 mw.logger.Log("method", "PostAddress", "profileID", profileID, "took", time.Since(begin), "err", err)
80 return mw.next.PostAddress(ctx, profileID, a)
83 func (mw loggingMiddleware) DeleteAddress(ctx context.Context, profileID string, addressID string) (err error) {
84 defer func(begin time.Time) {
85 mw.logger.Log("method", "DeleteAddress", "profileID", profileID, "addressID", addressID, "took", time.Since(begin), "err", err)
87 return mw.next.DeleteAddress(ctx, profileID, addressID)