add
This commit is contained in:
3
trading_assistant_api/common/go.mod
Normal file
3
trading_assistant_api/common/go.mod
Normal file
@@ -0,0 +1,3 @@
|
||||
module common
|
||||
|
||||
go 1.25.7
|
||||
32
trading_assistant_api/common/logger/logger.go
Normal file
32
trading_assistant_api/common/logger/logger.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package logger
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
type Logger interface {
|
||||
Printf(format string, v ...any)
|
||||
Fatalf(format string, v ...any)
|
||||
}
|
||||
|
||||
type stdLogger struct {
|
||||
l *log.Logger
|
||||
}
|
||||
|
||||
func (s *stdLogger) Printf(format string, v ...any) { s.l.Printf(format, v...) }
|
||||
func (s *stdLogger) Fatalf(format string, v ...any) { s.l.Fatalf(format, v...) }
|
||||
|
||||
var defaultLogger Logger = &stdLogger{
|
||||
l: log.New(os.Stdout, "[app] ", log.LstdFlags|log.Lshortfile),
|
||||
}
|
||||
|
||||
func L() Logger {
|
||||
return defaultLogger
|
||||
}
|
||||
|
||||
func SetLogger(l Logger) {
|
||||
if l != nil {
|
||||
defaultLogger = l
|
||||
}
|
||||
}
|
||||
11
trading_assistant_api/common/utils/env.go
Normal file
11
trading_assistant_api/common/utils/env.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package utils
|
||||
|
||||
import "os"
|
||||
|
||||
func GetEnv(key, def string) string {
|
||||
val := os.Getenv(key)
|
||||
if val == "" {
|
||||
return def
|
||||
}
|
||||
return val
|
||||
}
|
||||
Reference in New Issue
Block a user