-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog.go
More file actions
51 lines (45 loc) · 1006 Bytes
/
log.go
File metadata and controls
51 lines (45 loc) · 1006 Bytes
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
/*
* Author: Markus Stenberg <fingon@iki.fi>
*
* Copyright (c) 2024 Markus Stenberg
*
*/
package main
import (
"encoding/json"
"fmt"
"net/http"
"strconv"
"github.com/a-h/templ"
"github.com/fingon/lixie/data"
)
func logLink(log *data.Log, op string) templ.SafeURL {
return templ.URL(topLevelLog.Path + fmt.Sprintf("/%d/%s", log.Hash(), op))
}
func toJSON(v interface{}) string {
b, err := json.Marshal(v)
if err != nil {
return ""
}
return string(b)
}
func logClassifyHandler(st State, ham bool) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
hashString := r.PathValue("hash")
hash, err := strconv.ParseUint(hashString, 10, 64)
if err != nil {
http.Error(w, err.Error(), 400)
return
}
err = st.DB.ClassifyHash(hash, ham)
if err == data.ErrHashNotFound {
http.NotFound(w, r)
return
}
if err != nil {
http.Error(w, err.Error(), 400)
return
}
http.Redirect(w, r, topLevelLog.Path, http.StatusSeeOther)
})
}