Skip to content

Commit d35a4b1

Browse files
committed
add hello route
Sometimes it is pretty difficult to know if the connection to SPAAS even was successfully established. This should be a useful enpoint.
1 parent c48c24a commit d35a4b1

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
GIT_COMMIT=$(shell git rev-list -1 HEAD)
2+
all:
3+
go build -ldflags "-X main.GitCommit=$(GIT_COMMIT)"

main.go

+18
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import (
2222
"go.uber.org/zap"
2323
)
2424

25+
var GitCommit string
26+
2527
var (
2628
flagAddr = flag.String("addr", ":8080", "Server address")
2729
flagPatchCache = flag.String("patchcache", ".", "Path to the patch cache")
@@ -32,6 +34,7 @@ var (
3234
flagCertFile = flag.String("certfile", "", "Path to a TLS cert file")
3335
flagKeyFile = flag.String("keyfile", "", "Path to a TLS key file")
3436
flagDebug = flag.Bool("debug", false, "Enable debug logging (otherwise production level log)")
37+
flagVersion = flag.Bool("version", false, "Print version and exit")
3538
)
3639

3740
const tarballURLBase = "https://www.linbit.com/downloads/drbd/"
@@ -60,6 +63,11 @@ type server struct {
6063
func main() {
6164
flag.Parse()
6265

66+
if *flagVersion {
67+
fmt.Printf("Git-commit: '%s'\n", GitCommit)
68+
os.Exit(0)
69+
}
70+
6371
if *flagMaxBytesBody < 0 {
6472
log.Fatal("maxbytesbody has to be a positive value")
6573
}
@@ -370,6 +378,16 @@ func (s *server) genPatch(r *http.Request, drbdversion string) ([]byte, error) {
370378
return patch, nil
371379
}
372380

381+
func (s *server) hello() http.HandlerFunc {
382+
return func(w http.ResponseWriter, r *http.Request) {
383+
w.Header().Set("Content-Type", "application/text")
384+
385+
if _, err := fmt.Fprintf(w, "Successfully connected to SPAAS ('%s')\n", GitCommit); err != nil {
386+
w.WriteHeader(http.StatusInternalServerError)
387+
}
388+
}
389+
}
390+
373391
func (s *server) errorf(code int, remoteAddr string, w http.ResponseWriter, format string, a ...interface{}) {
374392
w.WriteHeader(code)
375393
_, _ = fmt.Fprintf(w, format, a...)

routes.go

+1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ package main
22

33
func (s *server) routes() {
44
s.router.HandleFunc("/api/v1/spatch/{drbdversion}", s.spatchCreate()).Methods("POST")
5+
s.router.HandleFunc("/api/v1/hello", s.hello()).Methods("GET")
56
}

0 commit comments

Comments
 (0)