GroupBy function's problems and fix ideas

Today, I started writing tests commented at and found some problems with GroupBy function of master repository. Here is the list

  1. Can’t access fields and methods specified in GroupBy call
  2. PagesGroup doesn’t contain Pages. It’s always empty.
  3. When GroupBy is called with Section key, it doesn’t work as expected

No. 1 is caused by Go’s field and method names are case sensitive and only those which start with upper case character were exported and accessible. Now the key is forcibly converted into lower case string so GroupBy tries to call an unexported field or method. One of the way to fix it to convert the first character to upper case but it would cause another problem when it called with a camel cased field or method like PublishDate so I think simply removing the line is better.

No. 2 is easily fixed by adding tmp.SetMapIndex(fv, reflect.Append(tmp.MapIndex(fv), ppv)) after if block.

No. 3 is more complex. It seems to be caused by “Section” name conflict between field and method. The Page structure has both of them. The “Section” method is newly introduced one and “Section” field seems to be defined in UrlPath strcuture, included in Page. I think “Section” method is what we need but how should it be fixed? Should I rename UrlPath.Section or change name resolving order (now first search field then method)?

I’d like to hear an opinion or those have already been fixed in someones local repo?

About 3) – I had the same issue with the Where function.

What I did and what makes sense to me was to order the checks so function first, field second, see:

Thanks for your comment. I saw the commit and thought changing check order was enough to solve the problem. So, I fixed it in that way and sent PR