Skip to content

Commit 1f76420

Browse files
committed
json api 'branches'
sorted by name
1 parent 4030b5d commit 1f76420

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

app/hdlr/branches.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
"github.com/gorilla/mux"
66
"github.com/typomedia/gitti/app/git"
77
"github.com/typomedia/gitti/app/helper"
8-
"github.com/typomedia/gitti/app/msg"
98
"net/http"
9+
"sort"
1010
)
1111

1212
func Branches(w http.ResponseWriter, r *http.Request) {
@@ -32,11 +32,20 @@ func Branches(w http.ResponseWriter, r *http.Request) {
3232
}
3333
}
3434

35-
//json.NewEncoder(w).Encode(branches)
36-
jsonData, err := json.Marshal(branches)
37-
msg.Check(err)
35+
// sort branches by name
36+
branches.SortByName()
37+
38+
//jsonData, err := json.Marshal(branches)
39+
//msg.Check(err)
3840

3941
// set application/json header
4042
w.Header().Set("Content-Type", "application/json")
41-
w.Write(jsonData)
43+
//w.Write(jsonData)
44+
json.NewEncoder(w).Encode(branches)
45+
}
46+
47+
func (refs *Refs) SortByName() {
48+
sort.Slice(refs.Branches, func(i, j int) bool {
49+
return refs.Branches[i].Name < refs.Branches[j].Name
50+
})
4251
}

0 commit comments

Comments
 (0)