package handlers import ( "authentication/helper" "authentication/services" "fmt" "net/http" ) func accessLog(r *http.Request, user *string, actType int, fieldUpdated interface{}) error { email, err := helper.ExtractEmailFromToken(r.Header.Get(Authorization)) if err != nil { return fmt.Errorf("%s", UnauthorizedAccess) } userID, err := services.GetUserIDFromEmail(email) if err != nil { helper.LogError(err, ErrorExtractingMailFromToken) return fmt.Errorf("%s", ErrorExtractingMailFromToken) } ipAddress := getIPAddress(r) err = helper.LogEvent(userID, user, ipAddress, actType, fieldUpdated) if err != nil { errMsg, err := services.GetActivityMessages(actType) if err == nil { errMsg = "Perform Action" } return fmt.Errorf("Failed to %s", errMsg) } return nil }