forked from moneymanagerex/general-reports
-
Notifications
You must be signed in to change notification settings - Fork 0
/
grm.go
38 lines (32 loc) · 788 Bytes
/
grm.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"os"
"fmt"
"github.com/julienschmidt/httprouter"
"net/http"
"log"
)
func Index(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
dir, err := os.Open(".")
if err != nil {
return
}
fileInfos, err := dir.Readdir(-1)
if err != nil {
return
}
for _, fi := range fileInfos {
if fi.IsDir() {
fmt.Fprint(w, "<a href=\"", fi.Name(), "\">", fi.Name(), "</a>")
}
}
}
func Report(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
fmt.Fprintf(w, "hello, %s!\n", ps.ByName("report"))
}
func main() {
router := httprouter.New()
router.GET("/", Index)
router.GET("/:report", Report)
log.Fatal(http.ListenAndServe(":8080", router))
}