aboutsummaryrefslogtreecommitdiff
path: root/status.go
diff options
context:
space:
mode:
authorCaroline Larimore <caroline@larimo.re>2025-01-25 12:29:22 -0800
committerCaroline Larimore <caroline@larimo.re>2025-01-25 12:29:22 -0800
commitb6840e185615f3e938a78ebe0488fdf61694464d (patch)
tree840de03c3da032badcfd1fdd1af2369acf6240ee /status.go
parentbb4239f59da123a1b13146955de70055e301a07d (diff)
Add timestamp to response
Diffstat (limited to 'status.go')
-rw-r--r--status.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/status.go b/status.go
index 8ef5301..970e044 100644
--- a/status.go
+++ b/status.go
@@ -2,16 +2,23 @@ package main
import (
"bufio"
+ "encoding/json"
"io"
"log"
"net/http"
"os"
"os/user"
"strings"
+ "time"
"golang.org/x/crypto/bcrypt"
)
+type response struct {
+ Msg string `json:"msg"`
+ Timestamp int64 `json:"timestamp"`
+}
+
func main() {
var msg string = ""
var adminHash []byte
@@ -50,6 +57,33 @@ func main() {
return
}
+ res := response{
+ Msg: msg,
+ Timestamp: time.Now().Unix(),
+ }
+
+ json, err := json.Marshal(res)
+ if err != nil {
+ http.Error(w, "Failed create JSON body", http.StatusInternalServerError)
+ return
+ }
+
+ w.Write(json)
+ return
+ }
+
+ deny(w)
+ })
+
+ http.HandleFunc("/raw", func(w http.ResponseWriter, r *http.Request) {
+ username, password, ok := r.BasicAuth()
+ if ok {
+ err := bcrypt.CompareHashAndPassword(userHash, []byte(username+password))
+ if err != nil {
+ deny(w)
+ return
+ }
+
w.Write([]byte(msg))
return
}