I want to create a struct with the values in a map.
Here's a snippet:
log := &Log{
Facility: parts["facility"].(int),
Severity: parts["severity"].(int),
Timestamp: parts["timestamp"].(time.Time),
Hostname: parts["hostname"].(string),
AppName: parts["appName"].(string),
Client: parts["client"].(string),
Priority: parts["priority"].(int),
Message: parts["message"].(string),
}
The problem is, if one of the values is nil, panic occurs. So I wanted to do something like this:
Facility: parts["facility"] != nil ? parts["facility"].(int) : 0
But this is not a valid syntax.
Do I have to check every key separately to handle nil cases?