How to Check if a String Is Empty in Go


If you need to check if a string is empty in Go, then there are two possible ways to immediately verify this:

Option 1 – Compare the length:

if len(s) > 0 {
    // do something with string
}

Option 2 – Compare against blank:

if s != "" {
    // do something with string
}