feat: 🎉 Rating Orama!
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"golang.org/x/exp/slog"
|
||||
"os"
|
||||
)
|
||||
|
||||
type Application struct {
|
||||
*slog.Logger
|
||||
Environment
|
||||
}
|
||||
|
||||
type Environment struct {
|
||||
Datasource string
|
||||
HarvesterApi string
|
||||
}
|
||||
|
||||
func NewApp(isProduction bool) *Application {
|
||||
if isProduction {
|
||||
return &Application{
|
||||
newStructuredLogger(),
|
||||
Environment{
|
||||
Datasource: os.Getenv("DATASOURCE"),
|
||||
HarvesterApi: os.Getenv("HARVESTER_API"),
|
||||
},
|
||||
}
|
||||
} else {
|
||||
return &Application{
|
||||
newStructuredLogger(),
|
||||
Environment{
|
||||
Datasource: "postgres://postgres:postgres@localhost:5432/postgres",
|
||||
HarvesterApi: "http://localhost:5000/tv-show/%s",
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"golang.org/x/exp/slog"
|
||||
"io"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
func newStructuredLogger() *slog.Logger {
|
||||
logFile, _ := os.OpenFile(generateLogFileName(), os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644)
|
||||
multiWriter := io.MultiWriter(os.Stdout, logFile)
|
||||
|
||||
return slog.New(slog.NewJSONHandler(multiWriter))
|
||||
}
|
||||
|
||||
func generateLogFileName() string {
|
||||
currentTime := time.Now()
|
||||
return "logs/" + currentTime.Format("2006-01-02") + ".log"
|
||||
}
|
||||
Reference in New Issue
Block a user