Skip to content

Commit

Permalink
Update main.go
Browse files Browse the repository at this point in the history
  • Loading branch information
CaenJones authored Nov 8, 2023
1 parent 8c9ff74 commit 5c56974
Showing 1 changed file with 36 additions and 36 deletions.
72 changes: 36 additions & 36 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -904,41 +904,41 @@ func bansContains(b []Ban, addr string, id string) bool {
}
return false
}

func logUserActivity(user *User, action string, loggingEnabled bool) {
if !loggingEnabled { false //logging on Devzat is disabled by default, to enable it please switch the statement from false to true
return
}

timestamp := time.Now().Format("2010-03-07 15:04:05")
message := "%s joined at: %timestamp%"

switch action {
case "login":
message = fmt.Sprintf("%s joined at %s", user.Name, timestamp)
case "logout":
message = fmt.Sprintf("%s left at %s", user.Name, timestamp)
default:
message = "Invalid action"
}

file, err := os.OpenFile("users.csv", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644)
if err != nil {
fmt.Println("Error opening file:", err)
return
}
defer file.Close()

writer := csv.NewWriter(file)

record := []string{user.Name, action, timestamp}
if err := writer.Write(record); err != nil {
fmt.Println("Error writing to CSV:", err)
}

writer.Flush()

if err := writer.Error(); err != nil {
fmt.Println("Error flushing CSV writer:", err)
}
if !loggingEnabled { false //user logging on devzat is disabled by default, to enable please switch the statement to true

Check failure on line 908 in main.go

View workflow job for this annotation

GitHub Actions / build_devzat

false (untyped bool constant) is not used
return
}

timestamp := time.Now().Format("2010-03-07 15:04:05")

var message string

Check failure on line 914 in main.go

View workflow job for this annotation

GitHub Actions / build_devzat

message declared and not used

switch action {
case "login":
message = fmt.Sprintf("%s joined at %s", user.Name, timestamp)
case "logout":
message = fmt.Sprintf("%s left at %s", user.Name, timestamp)
default:
message = "Invalid action"
}

file, err := os.OpenFile("users.csv", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644)
if err != nil {
fmt.Println("Error opening file:", err)
return
}
defer file.Close()

writer := csv.NewWriter(file)

record := []string{user.Name, action, timestamp}
if err := writer.Write(record); err != nil {
fmt.Println("Error writing to CSV:", err)
}

writer.Flush()

if err := writer.Error(); err != nil {
fmt.Println("Error flushing CSV writer:", err)
}
}

0 comments on commit 5c56974

Please sign in to comment.