diff --git a/internal/delivery/api/api.go b/internal/delivery/api/api.go deleted file mode 100644 index 10f42603..00000000 --- a/internal/delivery/api/api.go +++ /dev/null @@ -1,51 +0,0 @@ -package api - -// -//import ( -// "github.com/gorilla/mux" -// "net/http" -//) -// -//type IApi interface { -// //SetPath() -// API() Api -// //SetMethod() -// //GetMethod() string -// //SetHandler() -// //GetHandler() http.Handler -// // -// //RegisterApi(router *mux.Router) -//} -//type Api struct { -// Path string -// Method string -// Handler http.Handler -//} -// -//func (a Api) GetPath() string { -// return a.Path -//} -// -//func (a Api) GetMethod() string { -// return a.Method -//} -// -//func (a Api) GetHandler() http.Handler { -// return a.Handler -//} -// -//func (a Api) SetBasePath(path string) { -// a.Path = path -//} -// -//func (a Api) SetMethod(method string) { -// a.Method = method -//} -// -//func (a Api) SetHandler(handler http.Handler) { -// a.Handler = handler -//} -// -//func (a Api) RegisterApi(router *mux.Router) { -// router.Handle(a.GetPath(), a.GetHandler()) -//} diff --git a/internal/delivery/api/group.go b/internal/delivery/api/group.go deleted file mode 100644 index 9b6362e0..00000000 --- a/internal/delivery/api/group.go +++ /dev/null @@ -1,9 +0,0 @@ -package api - -var ProjectEndpoints = []Endpoint{ - CreateProject, - UpdateProject, - DeleteProject, - GetProject, - GetProjects, -} diff --git a/internal/delivery/api/project.go b/internal/delivery/api/project.go deleted file mode 100644 index 13786557..00000000 --- a/internal/delivery/api/project.go +++ /dev/null @@ -1,28 +0,0 @@ -package api - -// -//var ProjectApis []IApi = []IApi{ -// &ProjectApi{ -// name: "CreateProject", -// Api: Api{ -// Path: "", -// Method: "", -// Handler: nil, -// }, -// }, -//} -// -//type ProjectApi struct { -// name string -// Api -//} -// -////func NewProjectApi(path string, method string) IApi { -//// return &ProjectApi{ -//// Api: Api{Path: path, Method: method}, -//// } -////} -// -//func (a ProjectApi) API() Api { -// return a.Api -//} diff --git a/pkg/log/log.go b/pkg/log/log.go index 1983ad67..2a5bf3bc 100644 --- a/pkg/log/log.go +++ b/pkg/log/log.go @@ -4,7 +4,6 @@ import ( "context" "io" "os" - "path" "runtime" "strconv" "strings" @@ -59,8 +58,7 @@ func (f *CustomFormatter) Format(entry *logrus.Entry) ([]byte, error) { func Info(v ...interface{}) { if _, file, line, ok := runtime.Caller(1); ok { logger.WithFields(logrus.Fields{ - "file": path.Base(file), - "line": line, + "file": file + ":" + strconv.Itoa(line), }).Info(v...) } else { logger.Info(v...) @@ -69,8 +67,7 @@ func Info(v ...interface{}) { func Infof(format string, v ...interface{}) { if _, file, line, ok := runtime.Caller(1); ok { logger.WithFields(logrus.Fields{ - "file": path.Base(file), - "line": line, + "file": file + ":" + strconv.Itoa(line), }).Infof(format, v...) } else { logger.Infof(format, v...) @@ -78,18 +75,31 @@ func Infof(format string, v ...interface{}) { } func InfoWithContext(ctx context.Context, v ...interface{}) { reqID := ctx.Value(internal.ContextKeyRequestID) - logger.WithField(string(internal.ContextKeyRequestID), reqID).Info(v...) + if _, file, line, ok := runtime.Caller(1); ok { + logger.WithFields(logrus.Fields{ + "file": file + ":" + strconv.Itoa(line), + string(internal.ContextKeyRequestID): reqID, + }).Info(v...) + } else { + logger.WithField(string(internal.ContextKeyRequestID), reqID).Info(v...) + } } func InfofWithContext(ctx context.Context, format string, v ...interface{}) { reqID := ctx.Value(internal.ContextKeyRequestID) - logger.WithField(string(internal.ContextKeyRequestID), reqID).Infof(format, v...) + if _, file, line, ok := runtime.Caller(1); ok { + logger.WithFields(logrus.Fields{ + "file": file + ":" + strconv.Itoa(line), + string(internal.ContextKeyRequestID): reqID, + }).Infof(format, v...) + } else { + logger.WithField(string(internal.ContextKeyRequestID), reqID).Infof(format, v...) + } } func Warn(v ...interface{}) { if _, file, line, ok := runtime.Caller(1); ok { logger.WithFields(logrus.Fields{ - "file": file, - "line": line, + "file": file + ":" + strconv.Itoa(line), }).Warn(v...) } else { logger.Warn(v...) @@ -98,8 +108,7 @@ func Warn(v ...interface{}) { func Warnf(format string, v ...interface{}) { if _, file, line, ok := runtime.Caller(1); ok { logger.WithFields(logrus.Fields{ - "file": file, - "line": line, + "file": file + ":" + strconv.Itoa(line), }).Warnf(format, v...) } else { logger.Warnf(format, v...) @@ -110,7 +119,6 @@ func WarnWithContext(ctx context.Context, v ...interface{}) { if _, file, line, ok := runtime.Caller(1); ok { logger.WithFields(logrus.Fields{ "file": file + ":" + strconv.Itoa(line), - "line": line, string(internal.ContextKeyRequestID): reqID, }).Warn(v...) } else { @@ -121,8 +129,7 @@ func WarnfWithContext(ctx context.Context, format string, v ...interface{}) { reqID := ctx.Value(internal.ContextKeyRequestID) if _, file, line, ok := runtime.Caller(1); ok { logger.WithFields(logrus.Fields{ - "file": file, - "line": line, + "file": file + ":" + strconv.Itoa(line), string(internal.ContextKeyRequestID): reqID, }).Warnf(format, v...) } else { @@ -133,8 +140,7 @@ func WarnfWithContext(ctx context.Context, format string, v ...interface{}) { func Debug(v ...interface{}) { if _, file, line, ok := runtime.Caller(1); ok { logger.WithFields(logrus.Fields{ - "file": file, - "line": line, + "file": file + ":" + strconv.Itoa(line), }).Debug(v...) } else { logger.Debug(v...) @@ -143,8 +149,7 @@ func Debug(v ...interface{}) { func Debugf(format string, v ...interface{}) { if _, file, line, ok := runtime.Caller(1); ok { logger.WithFields(logrus.Fields{ - "file": file, - "line": line, + "file": file + ":" + strconv.Itoa(line), }).Debugf(format, v...) } else { logger.Debugf(format, v...) @@ -152,18 +157,31 @@ func Debugf(format string, v ...interface{}) { } func DebugWithContext(ctx context.Context, v ...interface{}) { reqID := ctx.Value(internal.ContextKeyRequestID) - logger.WithField(string(internal.ContextKeyRequestID), reqID).Debug(v...) + if _, file, line, ok := runtime.Caller(1); ok { + logger.WithFields(logrus.Fields{ + "file": file + ":" + strconv.Itoa(line), + string(internal.ContextKeyRequestID): reqID, + }).Debug(v...) + } else { + logger.WithField(string(internal.ContextKeyRequestID), reqID).Debug(v...) + } } func DebugfWithContext(ctx context.Context, format string, v ...interface{}) { reqID := ctx.Value(internal.ContextKeyRequestID) - logger.WithField(string(internal.ContextKeyRequestID), reqID).Debugf(format, v...) + if _, file, line, ok := runtime.Caller(1); ok { + logger.WithFields(logrus.Fields{ + "file": file + ":" + strconv.Itoa(line), + string(internal.ContextKeyRequestID): reqID, + }).Debugf(format, v...) + } else { + logger.WithField(string(internal.ContextKeyRequestID), reqID).Debugf(format, v...) + } } func Error(v ...interface{}) { if _, file, line, ok := runtime.Caller(1); ok { logger.WithFields(logrus.Fields{ - "file": file, - "line": line, + "file": file + ":" + strconv.Itoa(line), }).Error(v...) } else { logger.Error(v...) @@ -172,8 +190,7 @@ func Error(v ...interface{}) { func Errorf(format string, v ...interface{}) { if _, file, line, ok := runtime.Caller(1); ok { logger.WithFields(logrus.Fields{ - "file": file, - "line": line, + "file": file + ":" + strconv.Itoa(line), }).Errorf(format, v...) } else { logger.Errorf(format, v...) @@ -183,8 +200,7 @@ func ErrorWithContext(ctx context.Context, v ...interface{}) { reqID := ctx.Value(internal.ContextKeyRequestID) if _, file, line, ok := runtime.Caller(1); ok { logger.WithFields(logrus.Fields{ - "file": file, - "line": line, + "file": file + ":" + strconv.Itoa(line), string(internal.ContextKeyRequestID): reqID, }).Error(v...) } else { @@ -195,8 +211,7 @@ func ErrorfWithContext(ctx context.Context, format string, v ...interface{}) { reqID := ctx.Value(internal.ContextKeyRequestID) if _, file, line, ok := runtime.Caller(1); ok { logger.WithFields(logrus.Fields{ - "file": file, - "line": line, + "file": file + ":" + strconv.Itoa(line), string(internal.ContextKeyRequestID): reqID, }).Errorf(format, v...) } else { @@ -207,8 +222,7 @@ func ErrorfWithContext(ctx context.Context, format string, v ...interface{}) { func Fatal(v ...interface{}) { if _, file, line, ok := runtime.Caller(1); ok { logger.WithFields(logrus.Fields{ - "file": file, - "line": line, + "file": file + ":" + strconv.Itoa(line), }).Fatal(v...) } else { logger.Fatal(v...) @@ -217,8 +231,7 @@ func Fatal(v ...interface{}) { func Fatalf(format string, v ...interface{}) { if _, file, line, ok := runtime.Caller(1); ok { logger.WithFields(logrus.Fields{ - "file": file, - "line": line, + "file": file + ":" + strconv.Itoa(line), }).Fatalf(format, v...) } else { logger.Fatalf(format, v...)