+1
-1
.air/knotserver.toml
+1
-1
.air/knotserver.toml
+30
knotserver/handler.go
+30
knotserver/handler.go
···
5
5
"fmt"
6
6
"log/slog"
7
7
"net/http"
8
+
"runtime/debug"
8
9
9
10
"github.com/go-chi/chi/v5"
10
11
"tangled.sh/tangled.sh/core/jetstream"
···
66
67
}
67
68
68
69
r.Get("/", h.Index)
70
+
r.Get("/version", h.Version)
69
71
r.Route("/{did}", func(r chi.Router) {
70
72
// Repo routes
71
73
r.Route("/{name}", func(r chi.Router) {
···
124
126
125
127
return r, nil
126
128
}
129
+
130
+
// version is set during build time.
131
+
var version string
132
+
133
+
func (h *Handle) Version(w http.ResponseWriter, r *http.Request) {
134
+
if version == "" {
135
+
info, ok := debug.ReadBuildInfo()
136
+
if !ok {
137
+
http.Error(w, "failed to read build info", http.StatusInternalServerError)
138
+
return
139
+
}
140
+
141
+
var modVer string
142
+
for _, mod := range info.Deps {
143
+
if mod.Path == "tangled.sh/tangled.sh/knotserver" {
144
+
version = mod.Version
145
+
break
146
+
}
147
+
}
148
+
149
+
if modVer == "" {
150
+
version = "unknown"
151
+
}
152
+
}
153
+
154
+
w.Header().Set("Content-Type", "text/plain")
155
+
fmt.Fprintf(w, "knotserver/%s", version)
156
+
}