Properly distinguish between not set (nil) and blank/empty value

go

Solution

The zero value for a `string` is an empty string, and you can't distinguish between the two.

If you are using the `database/sql` package, and need to distinguish between `NULL` and empty strings, consider using the `sql.NullString` type. It is a simple struct that keeps track of the `NULL` state:

type NullString struct {
        String string
        Valid  bool // Valid is true if String is not NULL
}

You can scan into this type and use it as a query parameter, and the package will handle the `NULL` state for you.

Problem

Whats the correct way in go to distinguish between when a value in a struct was never set, or is just empty, for example, given the following: ``` type Organisation struct { Category string Code string Name string } ``` I need to know (for example) if the category was never set, or was saved as blank by the user, should I be doing this: ``` type Organisation struct { Category *string Code *string Name *string } ``` I also need to ensure I correctly persist either `null` or an empty string to the database I'm still learning GO so it is entirely possible my question needs more info.

Original source