fixing variable contretemps
This commit is contained in:
parent
54b412a3fe
commit
4b95b299f1
|
@ -40,7 +40,7 @@ func init() {
|
|||
// LoginHandler handles the /login endpoint.
|
||||
func LoginHandler(w http.ResponseWriter, r *http.Request) {
|
||||
var req LoginRequest
|
||||
fmt.Println("db is ", db)
|
||||
//fmt.Println("db is ", db)
|
||||
//fmt.Println("config is ", config)
|
||||
if db == nil {
|
||||
fmt.Println("DB is nil")
|
||||
|
|
21
main.go
21
main.go
|
@ -29,6 +29,11 @@ func main() {
|
|||
}
|
||||
fmt.Printf("Config loaded successfully in main(), DB path %s", config.DatabasePath)
|
||||
|
||||
// Set up logging
|
||||
if err := setupLogging(config.LogFile); err != nil {
|
||||
log.Fatalf("Failed to set up logging: %v", err)
|
||||
}
|
||||
|
||||
// Connect to the database
|
||||
db, err = connectToDatabase(config)
|
||||
if err != nil {
|
||||
|
@ -76,6 +81,20 @@ func loadAndValidateConfig() (*Config, error) {
|
|||
return config, nil
|
||||
}
|
||||
|
||||
func setupLogging(logFile string) error {
|
||||
fmt.Printf("Attempting to set up logging to file: %s\n", logFile)
|
||||
file, err := os.OpenFile(logFile, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to open log file: %v\n", err)
|
||||
return fmt.Errorf("failed to open log file: %v", err)
|
||||
}
|
||||
log.SetOutput(file)
|
||||
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
|
||||
fmt.Println("Logging initialized")
|
||||
log.Println("Logging initialized")
|
||||
return nil
|
||||
}
|
||||
|
||||
func connectToDatabase(config *Config) (*gorm.DB, error) {
|
||||
if config == nil {
|
||||
return nil, fmt.Errorf("config is nil in connectToDatabase")
|
||||
|
@ -84,7 +103,7 @@ func connectToDatabase(config *Config) (*gorm.DB, error) {
|
|||
if err != nil || db == nil {
|
||||
return nil, fmt.Errorf("failed to connect to database: %v", err)
|
||||
}
|
||||
fmt.Println("Connected to database in connectToDatabase")
|
||||
log.Println("Connected to database in connectToDatabase")
|
||||
return db, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue