How check if a property was set in a struct

go

Solution

Like dyoo said, you can use `nil` if your struct properties are pointers. If you want to keep them as strings you can compare with `""`. Here is a sample:

package main

import "fmt"

type MyStruct struct {
    Property string
}

func main() {
    s1 := MyStruct{
        Property: "hey",
    }

    s2 := MyStruct{}

    if s1.Property != "" {
        fmt.Println("s1.Property has been set")
    }

    if s2.Property == "" {
        fmt.Println("s2.Property has not been set")
    }
}

http://play.golang.org/p/YStKFuekeZ

Problem

I am trying to find how check if a structure property was set, but i cannot find any way. I expect something like this but of corse this not works: ``` type MyStruct struct { property string } test := new(MyStruct) if test.property { //do something with this } ```

Original source