-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathversion.go
49 lines (37 loc) · 992 Bytes
/
version.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
/*
Copyright © 2025 Seednode <seednode@seedno.de>
*/
package main
import (
"fmt"
"net/http"
"strconv"
"sync"
"time"
"github.com/julienschmidt/httprouter"
)
func serveVersion(errorChannel chan<- Error) httprouter.Handle {
return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
data := []byte(fmt.Sprintf("query v%s\n", ReleaseVersion))
w.Header().Set("Content-Type", "text/plain;charset=UTF-8")
w.Header().Set("Content-Length", strconv.Itoa(len(data)))
securityHeaders(w)
if verbose {
fmt.Printf("%s | %s => %s\n",
time.Now().Format(timeFormats["RFC3339"]),
realIP(r, true),
r.RequestURI)
}
_, err := w.Write(data)
if err != nil {
errorChannel <- Error{Message: err, Path: "serveVersion()"}
}
}
}
func registerVersion(mux *httprouter.Router, usage *sync.Map, errorChannel chan<- Error) {
const module = "version"
mux.GET("/version/", serveVersion(errorChannel))
usage.Store(module, []string{
"/version/",
})
}