you have to pass it by reference (pointer).
Yes, and referred by value on the other end.I am not saying anything to the contrary.
On Sunday, 26 May 2013 21:50:23 UTC+5:30, minux wrote:
The general problem depends on whether you want the caller to modify the
Item?
and in some cases, you have to return a pointer, for example, you can't
pass sync.Mutex
by value, so if the struct embeds a Mutex, you have to pass it by
reference (pointer).
On Mon, May 27, 2013 at 12:05 AM, Nguyên Nguyễn Văn Cao <nvc...@gmail.com<javascript:>
itms, err := GetAllItem()
if err != nil {}
return &itms[len(itms)-1]
--The general problem depends on whether you want the caller to modify the
Item?
and in some cases, you have to return a pointer, for example, you can't
pass sync.Mutex
by value, so if the struct embeds a Mutex, you have to pass it by
reference (pointer).
On Mon, May 27, 2013 at 12:05 AM, Nguyên Nguyễn Văn Cao <nvc...@gmail.com<javascript:>
wrote:
For example I have a struct *Item* in my db, and two function *GetAllItem
* which return more than one Item and *GetLastItem* return one lasted
Item.
GetAllItem will return a slice of Item and and error if any
So I can return a nil slice if any error occur.
Now is my wonder about GetLastItem:
So I will able to return a nil Item, but it not analog with GetAllItem,
so should I change the GetAllItem to return a slice of *Item?
could do something like this:For example I have a struct *Item* in my db, and two function *GetAllItem
* which return more than one Item and *GetLastItem* return one lasted
Item.
GetAllItem will return a slice of Item and and error if any
func GetAllItem() ([]Item, error)
So I can return a nil slice if any error occur.
Now is my wonder about GetLastItem:
func GetLastItem() (*Item, error)
So I will able to return a nil Item, but it not analog with GetAllItem,
so should I change the GetAllItem to return a slice of *Item?
func GetAllItem() ([]*Item, error)
you don't need to modify GetAllItem() to return []*Item for this as youitms, err := GetAllItem()
if err != nil {}
return &itms[len(itms)-1]
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.