mirror of
https://github.com/mitchell/selfpass.git
synced 2025-12-13 21:07:22 +00:00
Implemented remaining transport layer methods; added logging middleware;
added Dockerfile; added gen cert Makefile cmds; added Redis repo
This commit is contained in:
parent
719a462048
commit
c289eecd54
20 changed files with 1977 additions and 143 deletions
114
credentials/middleware/logger.go
Normal file
114
credentials/middleware/logger.go
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
package middleware
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/go-kit/kit/log"
|
||||
"github.com/mitchell/selfpass/credentials/types"
|
||||
)
|
||||
|
||||
func NewServiceLogger(l log.Logger, next types.Service) ServiceLogger {
|
||||
return ServiceLogger{
|
||||
l: l,
|
||||
next: next,
|
||||
}
|
||||
}
|
||||
|
||||
type ServiceLogger struct {
|
||||
l log.Logger
|
||||
next types.Service
|
||||
}
|
||||
|
||||
func (svc ServiceLogger) GetAllMetadata(ctx context.Context, sourceHost string) (output <-chan types.Metadata, errch chan error) {
|
||||
defer func(begin time.Time) {
|
||||
_ = svc.l.Log(
|
||||
"service", "Credentials",
|
||||
"method", "GetAllMetadata",
|
||||
"input", sourceHost,
|
||||
"output", "channel",
|
||||
"err", "channel",
|
||||
"took", time.Since(begin),
|
||||
)
|
||||
}(time.Now())
|
||||
|
||||
return svc.next.GetAllMetadata(ctx, sourceHost)
|
||||
}
|
||||
|
||||
func (svc ServiceLogger) Get(ctx context.Context, id string) (output types.Credential, err error) {
|
||||
defer func(begin time.Time) {
|
||||
_ = svc.l.Log(
|
||||
"service", "Credentials",
|
||||
"method", "Get",
|
||||
"input", id,
|
||||
"output", output,
|
||||
"err", err,
|
||||
"took", time.Since(begin),
|
||||
)
|
||||
}(time.Now())
|
||||
|
||||
output, err = svc.next.Get(ctx, id)
|
||||
return output, err
|
||||
}
|
||||
|
||||
func (svc ServiceLogger) Create(ctx context.Context, ci types.CredentialInput) (output types.Credential, err error) {
|
||||
defer func(begin time.Time) {
|
||||
_ = svc.l.Log(
|
||||
"service", "Credentials",
|
||||
"method", "Create",
|
||||
"input", ci,
|
||||
"output", output,
|
||||
"err", err,
|
||||
"took", time.Since(begin),
|
||||
)
|
||||
}(time.Now())
|
||||
|
||||
output, err = svc.next.Create(ctx, ci)
|
||||
return output, err
|
||||
}
|
||||
|
||||
func (svc ServiceLogger) Update(ctx context.Context, id string, ci types.CredentialInput) (output types.Credential, err error) {
|
||||
defer func(begin time.Time) {
|
||||
_ = svc.l.Log(
|
||||
"service", "Credentials",
|
||||
"method", "Update",
|
||||
"input", []interface{}{id, ci},
|
||||
"output", output,
|
||||
"err", err,
|
||||
"took", time.Since(begin),
|
||||
)
|
||||
}(time.Now())
|
||||
|
||||
output, err = svc.next.Update(ctx, id, ci)
|
||||
return output, err
|
||||
}
|
||||
|
||||
func (svc ServiceLogger) Delete(ctx context.Context, id string) (err error) {
|
||||
defer func(begin time.Time) {
|
||||
_ = svc.l.Log(
|
||||
"service", "Credentials",
|
||||
"method", "Delete",
|
||||
"input", id,
|
||||
"err", err,
|
||||
"took", time.Since(begin),
|
||||
)
|
||||
}(time.Now())
|
||||
|
||||
err = svc.next.Delete(ctx, id)
|
||||
return err
|
||||
}
|
||||
|
||||
func (svc ServiceLogger) DumpDB(ctx context.Context) (output []byte, err error) {
|
||||
defer func(begin time.Time) {
|
||||
_ = svc.l.Log(
|
||||
"service", "Credentials",
|
||||
"method", "Dump",
|
||||
"output", output,
|
||||
"err", err,
|
||||
"took", time.Since(begin),
|
||||
)
|
||||
}(time.Now())
|
||||
|
||||
output, err = svc.next.DumpDB(ctx)
|
||||
return output, err
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue