More cleanup, more refractor, more energy, more passion, more footwork
This commit is contained in:
@@ -113,9 +113,9 @@ func (c *Config) loadConfig() error {
|
||||
// Load the auth file
|
||||
c.Auth = c.GetAuth()
|
||||
|
||||
// Validate the config
|
||||
//Validate the config
|
||||
//if err := validateConfig(c); err != nil {
|
||||
// return nil, err
|
||||
// return err
|
||||
//}
|
||||
|
||||
return nil
|
||||
@@ -211,7 +211,11 @@ func GetConfig() *Config {
|
||||
once.Do(func() {
|
||||
instance = &Config{} // Initialize instance first
|
||||
if err := instance.loadConfig(); err != nil {
|
||||
panic(err)
|
||||
_, err := fmt.Fprintf(os.Stderr, "Configuration Error: %v\n", err)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
os.Exit(1)
|
||||
}
|
||||
})
|
||||
return instance
|
||||
|
||||
@@ -3,6 +3,7 @@ package logger
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/sirrobot01/debrid-blackhole/internal/config"
|
||||
"gopkg.in/natefinch/lumberjack.v2"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -16,11 +17,8 @@ var (
|
||||
)
|
||||
|
||||
func GetLogPath() string {
|
||||
logsDir := os.Getenv("LOG_PATH")
|
||||
if logsDir == "" {
|
||||
// Create the logs directory if it doesn't exist
|
||||
logsDir = "logs"
|
||||
}
|
||||
cfg := config.GetConfig()
|
||||
logsDir := filepath.Join(cfg.Path, "logs")
|
||||
|
||||
if err := os.MkdirAll(logsDir, 0755); err != nil {
|
||||
panic(fmt.Sprintf("Failed to create logs directory: %v", err))
|
||||
@@ -33,7 +31,7 @@ func NewLogger(prefix string, level string, output *os.File) zerolog.Logger {
|
||||
|
||||
rotatingLogFile := &lumberjack.Logger{
|
||||
Filename: GetLogPath(),
|
||||
MaxSize: 10,
|
||||
MaxSize: 2,
|
||||
MaxBackups: 2,
|
||||
MaxAge: 28,
|
||||
Compress: true,
|
||||
@@ -87,7 +85,7 @@ func NewLogger(prefix string, level string, output *os.File) zerolog.Logger {
|
||||
|
||||
func GetLogger(level string) zerolog.Logger {
|
||||
once.Do(func() {
|
||||
logger = NewLogger("Decypharr", level, os.Stdout)
|
||||
logger = NewLogger("decypharr", level, os.Stdout)
|
||||
})
|
||||
return logger
|
||||
}
|
||||
|
||||
@@ -93,19 +93,25 @@ func (c *RLHTTPClient) MakeRequest(req *http.Request) ([]byte, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
b, _ := io.ReadAll(res.Body)
|
||||
statusOk := strconv.Itoa(res.StatusCode)[0] == '2'
|
||||
if !statusOk {
|
||||
// Add status code error to the body
|
||||
b = append(b, []byte(fmt.Sprintf("\nstatus code: %d", res.StatusCode))...)
|
||||
return nil, fmt.Errorf(string(b))
|
||||
}
|
||||
|
||||
defer func(Body io.ReadCloser) {
|
||||
err := Body.Close()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
}(res.Body)
|
||||
|
||||
b, err := io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
statusOk := res.StatusCode == http.StatusOK || res.StatusCode == http.StatusCreated
|
||||
if !statusOk {
|
||||
// Add status code error to the body
|
||||
b = append(b, []byte(fmt.Sprintf("\nstatus code: %d", res.StatusCode))...)
|
||||
return nil, fmt.Errorf(string(b))
|
||||
}
|
||||
|
||||
return b, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user