As a side note, I'm probably stating the obvious here, but this is only a 
problem because your type is `*Attribute`. Should it be `Attribute` 
instead, your struct would be properly initialized with its fields to their 
zero value.

I mention it because I'm not sure myself why, from a design point of view, 
it's such a common practice to make pointers out of everything by default 
(I like the idea that what I pass as parameter can only be altered if I 
explicitly allow it). 

Le samedi 14 janvier 2017 12:41:27 UTC+1, Teety Konko a écrit :
>
> It was easier than i expected 
>
> https://play.golang.org/p/olooozwapD
>
> On Friday, 13 January 2017 19:13:16 UTC+1, mhh...@gmail.com wrote:
>>
>> yeah, right, it s possible and works, but its way more complex, lets 
>> forget about this :)
>>
>> This works https://play.golang.org/p/hP8Zq-LfQA
>>
>> On Friday, January 13, 2017 at 6:42:25 PM UTC+1, mail...@gmail.com wrote:
>>>
>>>
>>> Can you give example how this validation can be done via such interface 
>>> ? 
>>>
>>> On Friday, 13 January 2017 18:27:51 UTC+1, mhh...@gmail.com wrote:
>>>>
>>>> you could also implment unmarshaler interface
>>>>
>>>> https://blog.gopheracademy.com/advent-2016/advanced-encoding-decoding/
>>>>
>>>>
>>>>
>>>> On Friday, January 13, 2017 at 6:18:01 PM UTC+1, mail...@gmail.com 
>>>> wrote:
>>>>>
>>>>>
>>>>> Hello,
>>>>>
>>>>> Ignoring the error does not help 
>>>>>
>>>>> https://play.golang.org/p/a8AIcHWII6
>>>>>
>>>>> Thank you.
>>>>>
>>>>>
>>>>> On Friday, 13 January 2017 15:38:45 UTC+1, Ian Davis wrote:
>>>>>>
>>>>>> On Fri, 13 Jan 2017, at 10:12 AM, mail...@gmail.com wrote:
>>>>>>
>>>>>>
>>>>>> Hello,
>>>>>>
>>>>>> Have been struggling with mitigating against nil pointer deference 
>>>>>> and i would appreciate if anyone can help
>>>>>>
>>>>>> Code 1:   Works file 
>>>>>> https://play.golang.org/p/lhOh9g5R9l
>>>>>>
>>>>>>
>>>>>> Code 2: Error
>>>>>> https://play.golang.org/p/pY4F9bK-D9
>>>>>>
>>>>>>
>>>>>> In this case you must not ignore the error returned from 
>>>>>> json.Unmarshal. If an error is returned then p will be nil.
>>>>>>
>>>>>>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to