Fatalf and FatalFileRead

This commit is contained in:
Gregory Wells
2026-03-24 17:51:59 -04:00
parent 8d0cd0fd1b
commit 5aa2ce47c7
3 changed files with 23 additions and 1 deletions

View File

@@ -16,6 +16,14 @@ func Infof(message string, vars ...any) {
log.Printf(message, vars...) log.Printf(message, vars...)
} }
func Fatal(message string) {
log.Fatal(message)
}
func Fatalf(message string, v ...any) {
log.Fatalf(message, v...)
}
func Event(eventType EventType, eventData ...any) { func Event(eventType EventType, eventData ...any) {
switch eventType { switch eventType {
case ReadFile: case ReadFile:

View File

@@ -6,12 +6,26 @@ import (
"astraltech.xyz/accountmanager/src/logging" "astraltech.xyz/accountmanager/src/logging"
) )
// Reads a file, if fails just returns an error
func ReadFile(path string) ([]byte, error) { func ReadFile(path string) ([]byte, error) {
logging.Event(logging.ReadFile, "static/blank_profile.jpg") logging.Event(logging.ReadFile, "static/blank_profile.jpg")
data, err := os.ReadFile(path) data, err := os.ReadFile(path)
if err != nil { if err != nil {
logging.Infof("Could not read file at %s", path) logging.Infof("Could not read file at %s", path)
logging.Infof("Error code: %e", err)
return nil, err
} }
logging.Infof("Successfully read file at %s", path) logging.Infof("Successfully read file at %s", path)
return data, err return data, err
} }
func ReadRequiredFile(path string) []byte {
logging.Event(logging.ReadFile, "static/blank_profile.jpg")
data, err := os.ReadFile(path)
if err != nil {
logging.Fatalf("Could not read file at %s", path)
return nil
}
logging.Infof("Successfully read file at %s", path)
return data
}

View File

@@ -313,7 +313,7 @@ func main() {
var err error = nil var err error = nil
blankPhotoData, err = ReadFile("static/blank_profile.jpg") blankPhotoData, err = ReadFile("static/blank_profile.jpg")
if err != nil { if err != nil {
log.Fatal("Could not load blank profile image") logging.Fatal("Could not load blank profile image")
} }
serverConfig, err = loadServerConfig("./data/config.json") serverConfig, err = loadServerConfig("./data/config.json")
if err != nil { if err != nil {