将指针字段分配给强制转换值

I'm sure this is just a syntax thing I'm not aware of but this is the struct with pointer fields:

type someStruct struct {
    StringVal string     `json:"val_str"`
    IntVal    *int64     `json:"val_int"`
}

I'm trying to return an instance of this struct like so, where aValue is an int64 value and I'm trying to get the IntVal pointer to point to it:

return someStruct{IntVal: &(int64(aValue))}

I get this error:

cannot take the address of int64(d)

Any ideas how to achieve this?

You would need to first assign the int64 to a variable:

aValueTmp := int64(aValue)
return someStruct{IntVal: &aValueTmp}

The easiest way - instantuiate a variable and give a pointer to it. Or in one line:

return someStruct{
    IntVal: func(i int64) *int64 {return &i}(aValue)
}