logoalt Hacker News

shaknayesterday at 3:51 PM1 replyview on HN

listFiles is not sorted. It provides the files in the order that the OS provides them. That it's ordered on your machine, probably has to do with when the underlying nodes were created. But that's not going to much work in production.

    dirInfo, err := dir.Readdir(0)
    if err != nil {
        return nil, err
     }

    names := make([]string, len(dirInfo))
     for i, fileInfo := range dirInfo {
          names[i] = fileInfo.Name()
     }

Replies

jprokay13yesterday at 4:46 PM

Yeah that was what I was afraid of. I thought I saw in the caddy code that they did a sort on file name, but I must have misread it. Thanks for responding!

Edit: after looking more closely at sprig, the solve was sortAlpha