limit updates on front page
alex wennerberg alex@alexwennerberg.com
Sat, 24 Oct 2020 11:45:45 -0700
1 files changed,
11 insertions(+),
3 deletions(-)
jump to
M
main.go
→
main.go
@@ -8,8 +8,10 @@ "log"
"os" "path" "path/filepath" + "sort" "strings" "sync" + "time" ) var c Config // global var to hold static configuration@@ -21,7 +23,7 @@
type File struct { Creator string Name string - UpdatedTime string + UpdatedTime time.Time } func getUsers() ([]string, error) {@@ -57,7 +59,7 @@ // make this do what it should
result = append(result, &File{ Name: info.Name(), Creator: "alex", - UpdatedTime: "123123", + UpdatedTime: info.ModTime(), }) return nil })@@ -66,6 +68,12 @@ return nil, err
} // sort // truncate + sort.Slice(result, func(i, j int) bool { + return result[i].UpdatedTime.Before(result[j].UpdatedTime) + }) + if len(result) > 50 { + result = result[:50] + } return result, nil } // todo clean up paths@@ -79,7 +87,7 @@ for _, file := range files {
result = append(result, &File{ Name: file.Name(), Creator: user, - UpdatedTime: "123123", + UpdatedTime: file.ModTime(), }) } return result, nil