-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
60 lines (45 loc) · 1.31 KB
/
main.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"github.com/julienschmidt/httprouter"
"strconv"
"net/http"
"log"
)
func Index(w http.ResponseWriter, _ *http.Request, _ httprouter.Params) {
parseAll(w)
}
func MakeUser(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
check(r.ParseForm())
var t TimeCard
t.User = r.PostFormValue("user")
t.Password = r.PostFormValue("password")
writeTC(&t)
http.Redirect(w, r, "/", 301)
}
func Timecard(w http.ResponseWriter, _ *http.Request, ps httprouter.Params) {
parseDB(w, ps.ByName("user"))
}
func Punch(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
check(r.ParseForm())
week, err := strconv.Atoi(r.PostFormValue("week"))
check(err)
day, err := strconv.Atoi(r.PostFormValue("day"))
check(err)
time, err := strconv.Atoi(r.PostFormValue("time"))
check(err)
tc := readDB(ps.ByName("user"))
if tc.Password == r.PostFormValue("password") {
tc.punch(week, day, time)
writeTC(tc)
}
http.Redirect(w, r, "/tc/" + ps.ByName("user"), 301)
}
func main() {
router := httprouter.New()
router.GET("/", Index)
router.POST("/", MakeUser)
router.GET("/tc/:user", Timecard)
router.POST("/tc/:user", Punch)
router.Handler("GET", "/raw/*file", http.StripPrefix("/raw/", http.FileServer(http.Dir(dbdir))))
log.Fatal(http.ListenAndServe(":80", router))
}