aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@vidhukant.com>2025-05-07 20:03:02 +0530
committerVidhu Kant Sharma <vidhukant@vidhukant.com>2025-05-07 20:03:02 +0530
commitab81e04e0090149aca6cba3f5154e91dc0cd6659 (patch)
tree3470ec4b478676d6e114c3d6fcaa4304a53afb1a
parent03e5020f880c7237141fd850f54579fe3e97324b (diff)
Saving timestampsHEADv1.5.0master
-rw-r--r--README.md17
-rw-r--r--cmd/dump.go4
-rw-r--r--cmd/root.go2
-rw-r--r--cmd/serve.go8
-rw-r--r--db/db.go1
5 files changed, 25 insertions, 7 deletions
diff --git a/README.md b/README.md
index d7259d7..840aed0 100644
--- a/README.md
+++ b/README.md
@@ -34,7 +34,8 @@ template = """
guestbook_entry(
name=\"{{.Name}}\",
website=\"{{.Website}}\",
- message=\"{{.Message}}\"
+ message=\"{{.Message}}\",
+ time=\"{{.Time}}\"
)
{{print "}}"}}
{{end}}"""
@@ -72,6 +73,20 @@ systemctl daemon-reload
systemctl enable --now my_guestbook-guestbook
```
+## Nginx configuration
+
+Pass exactly the desired url to the guestbook server.
+Replace port and the path to match your configuration.
+
+```
+location = /guestbook/sign {
+ proxy_pass http://localhost:2222/sign;
+ proxy_set_header Host $host;
+ proxy_set_header X-Real-IP $remote_addr;
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+}
+```
+
## Reading entries
```fish
diff --git a/cmd/dump.go b/cmd/dump.go
index ec8976b..ddc26e8 100644
--- a/cmd/dump.go
+++ b/cmd/dump.go
@@ -44,7 +44,7 @@ var dumpCmd = &cobra.Command{
conn := db.Connect()
defer conn.Close()
- rows, err := conn.Query(fmt.Sprintf("SELECT name, website, message FROM %s", guestbookName))
+ rows, err := conn.Query(fmt.Sprintf("SELECT name, website, message, time FROM %s", guestbookName))
if err != nil {
log.Fatal(err)
}
@@ -54,7 +54,7 @@ var dumpCmd = &cobra.Command{
for rows.Next() {
var entry db.GuestbookEntry
- if err := rows.Scan(&entry.Name, &entry.Website, &entry.Message); err != nil {
+ if err := rows.Scan(&entry.Name, &entry.Website, &entry.Message, &entry.Time); err != nil {
log.Fatal(err)
}
entries = append(entries, entry)
diff --git a/cmd/root.go b/cmd/root.go
index a150426..5ba7ae6 100644
--- a/cmd/root.go
+++ b/cmd/root.go
@@ -27,7 +27,7 @@ import (
var rootCmd = &cobra.Command{
Use: "guestbook",
- Version: "v1.4.0",
+ Version: "v1.5.0",
Short: "Standalone guestbook server for static websites",
Long: "Standalone guestbook server for static websites",
}
diff --git a/cmd/serve.go b/cmd/serve.go
index a5727df..7d0b8c1 100644
--- a/cmd/serve.go
+++ b/cmd/serve.go
@@ -20,6 +20,7 @@ package cmd
import (
"fmt"
"log"
+ "time"
"strings"
"net/http"
@@ -67,7 +68,8 @@ var serveCmd = &cobra.Command{
"id INT AUTO_INCREMENT PRIMARY KEY," +
"name TEXT," +
"website TEXT," +
- "message TEXT" +
+ "message TEXT," +
+ "time VARCHAR(30)" +
");",
guestbookName,
),
@@ -102,7 +104,7 @@ var serveCmd = &cobra.Command{
return
}
- stmt, err := conn.Prepare(fmt.Sprintf("INSERT INTO %s (name, website, message) VALUES (?, ?, ?)", guestbookName))
+ stmt, err := conn.Prepare(fmt.Sprintf("INSERT INTO %s (name, website, message, time) VALUES (?, ?, ?, ?)", guestbookName))
if err != nil {
log.Printf("Error occurred while preparing statement data: %v\n")
http.Redirect(w, r, errorRedirect, http.StatusSeeOther)
@@ -110,7 +112,7 @@ var serveCmd = &cobra.Command{
}
defer stmt.Close()
- _, err = stmt.Exec(data.Name, data.Website, data.Message)
+ _, err = stmt.Exec(data.Name, data.Website, data.Message, time.Now().Format(time.RFC3339))
if err != nil {
log.Printf("Error occurred while saving data: %v\n")
http.Redirect(w, r, errorRedirect, http.StatusSeeOther)
diff --git a/db/db.go b/db/db.go
index 11b6fd4..5afb96b 100644
--- a/db/db.go
+++ b/db/db.go
@@ -31,6 +31,7 @@ type GuestbookEntry struct {
Website string `json:"website"`
Message string `json:"message"`
Validation string `json:"validation"`
+ Time string
}
func Connect() *sql.DB {