-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_handler.go
34 lines (25 loc) · 904 Bytes
/
build_handler.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
// Copyright 2024 Bill Nixon. All rights reserved.
// Use of this source code is governed by the license found in the LICENSE file.
package webapp
import (
"fmt"
"log/slog"
"net/http"
"github.com/bnixon67/webapp/webhandler"
"github.com/bnixon67/webapp/webutil"
)
// BuildDateTimeFormat defines the display format for build dates.
const BuildDateTimeFormat = "2006-01-02 15:04:05"
// BuildHandlerGet responds with the application's build date and time.
func (app *WebApp) BuildHandlerGet(w http.ResponseWriter, r *http.Request) {
logger := webhandler.NewRequestLoggerWithFuncName(r)
if !webutil.IsMethodOrError(w, r, http.MethodGet) {
logger.Error("invalid method")
return
}
webutil.SetNoCacheHeaders(w)
webutil.SetContentTypeText(w)
buildTime := app.BuildDateTime.Format(BuildDateTimeFormat)
fmt.Fprintln(w, buildTime)
logger.Info("done", slog.String("buildTime", buildTime))
}