2 Commits

Author SHA1 Message Date
Gregory Wells
8d0cd0fd1b use read file helper function everywhere 2026-03-24 17:10:56 -04:00
Gregory Wells
35ec6678f8 implement and use first logging event (ReadFile) 2026-03-24 17:09:30 -04:00
3 changed files with 39 additions and 3 deletions

View File

@@ -2,6 +2,26 @@ package logging
import "log"
type EventType int
const (
ReadFile EventType = iota
)
func Info(message string) {
log.Print(message)
}
func Infof(message string, vars ...any) {
log.Printf(message, vars...)
}
func Event(eventType EventType, eventData ...any) {
switch eventType {
case ReadFile:
{
log.Printf("Reading file %s", eventData[0])
break
}
}
}

17
src/main/helpers.go Normal file
View File

@@ -0,0 +1,17 @@
package main
import (
"os"
"astraltech.xyz/accountmanager/src/logging"
)
func ReadFile(path string) ([]byte, error) {
logging.Event(logging.ReadFile, "static/blank_profile.jpg")
data, err := os.ReadFile(path)
if err != nil {
logging.Infof("Could not read file at %s", path)
}
logging.Infof("Successfully read file at %s", path)
return data, err
}

View File

@@ -172,7 +172,7 @@ func avatarHandler(w http.ResponseWriter, r *http.Request) {
filePath := fmt.Sprintf("./avatars/%s.jpeg", username)
cleaned := filepath.Clean(filePath)
value, err := os.ReadFile(cleaned)
value, err := ReadFile(cleaned)
if err == nil {
photoCreatedMutex.Lock()
@@ -311,8 +311,7 @@ func main() {
logging.Info("Starting the server")
var err error = nil
blankPhotoData, err = os.ReadFile("static/blank_profile.jpg")
blankPhotoData, err = ReadFile("static/blank_profile.jpg")
if err != nil {
log.Fatal("Could not load blank profile image")
}