diff --git a/src/logging/logging.go b/src/logging/logging.go index 4f6a66a..0625178 100644 --- a/src/logging/logging.go +++ b/src/logging/logging.go @@ -16,6 +16,14 @@ func Infof(message string, vars ...any) { 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) { switch eventType { case ReadFile: diff --git a/src/main/helpers.go b/src/main/helpers.go index bb9de35..1f2f9a1 100644 --- a/src/main/helpers.go +++ b/src/main/helpers.go @@ -6,12 +6,26 @@ import ( "astraltech.xyz/accountmanager/src/logging" ) +// Reads a file, if fails just returns an error 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("Error code: %e", err) + return nil, err } logging.Infof("Successfully read file at %s", path) 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 +} diff --git a/src/main/main.go b/src/main/main.go index 4b07214..e1f9b26 100644 --- a/src/main/main.go +++ b/src/main/main.go @@ -313,7 +313,7 @@ func main() { var err error = nil blankPhotoData, err = ReadFile("static/blank_profile.jpg") 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") if err != nil {