Object pool design pattern in golang I am studying design patterns in go. I need a review of this implementation. I started this exercise from wikipedia description of the pattern and implementing step by step all the sentences.

I decided to use two objects: the pool and the object managed by the pool.

type PoolObject struct {
    id int
}

type Pool struct {
    idle   *list.List
    active *list.List
}


When pool is initialized two empty lists were created.

func InitPool() Pool {
    pool := &amp;Pool{
        list.New(),
        list.New(),
    }
    return *pool
}


Any time an object is requested, it's returned from the idle list or created from scratch.

func (p *Pool) Loan() PoolObject {
    if p.idle.Len() &gt; 0 {
        for e, i := p.idle.Front(), 0; e != nil; e, i = e.Next(), i+1 {
            if i == 0 {
                object := e.Value.(PoolObject)
                return object
            }
        }
    }

    object := PoolObject{p.NumberOfObjectsInPool() + 1}
    p.active.PushBack(object)
    return object
}


Any time an object is returned, it's removed from the active list and pushed in the idle list.

func (p *Pool) Receive(object PoolObject) {
    p.idle.PushBack(object)
    for e, i := p.active.Front(), 0; e != nil; e, i = e.Next(), i+1 {
        if object == e.Value.(PoolObject) {
            p.active.Remove(e)
            return
        }
    }
}
You don't seem to have a policy for a maximum pool side. Is that by mistake or by design? What should happen if someone requests an object too many?
Your choice of method names is slightly off. When I talk to an object pool, I don't want to Loan it an object, nor do I want to Receive an object. I want to "borrow," "obtain," "take" or "get" an object from the pool, and I want to "return" or "release" or "put" an object back into the pool.

I'd suggest:

obj = pool.Borrow()
// ...
pool.Return(obj)

Finally, why does your object have an id? It seems unused. I'd suggest just using interface{} as your object type.