mirror of
https://github.com/GRFreire/nthmail.git
synced 2026-01-09 12:59:38 +00:00
render inbox as html instead of json
This commit is contained in:
parent
95252f12f5
commit
f4407d71f8
30
cmd/web_server/inbox.templ
Normal file
30
cmd/web_server/inbox.templ
Normal file
@ -0,0 +1,30 @@
|
||||
package main
|
||||
|
||||
import "time"
|
||||
|
||||
templ inbox_body(rcpt_addr string, ms []mail) {
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8"/>
|
||||
<title>nthmail.xyz</title>
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1"/>
|
||||
<meta name="description" content="A temporary mail service"/>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Emails for { rcpt_addr }:</h1>
|
||||
<ul>
|
||||
for _, m := range ms {
|
||||
<li>
|
||||
@mail_comp(m)
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
</body>
|
||||
</html>
|
||||
}
|
||||
|
||||
templ mail_comp(m mail) {
|
||||
<h3>From: <{ m.From_addr }> at { time.Unix(m.Arrived_at, 0).Format(time.DateTime) }</h3>
|
||||
<p>{ string(m.Data) }</p>
|
||||
}
|
||||
@ -2,7 +2,6 @@ package main
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
@ -16,7 +15,7 @@ import (
|
||||
|
||||
type mail struct {
|
||||
Id int
|
||||
Arrived_at int
|
||||
Arrived_at int64
|
||||
Rcpt_addr, From_addr string
|
||||
Data []byte
|
||||
}
|
||||
@ -98,16 +97,9 @@ func main() {
|
||||
|
||||
mails = append(mails, m)
|
||||
}
|
||||
b, err := json.Marshal(mails)
|
||||
if err != nil {
|
||||
res.WriteHeader(500)
|
||||
res.Write([]byte("internal server error"))
|
||||
|
||||
log.Println("could not marshal json")
|
||||
return
|
||||
}
|
||||
|
||||
res.Write([]byte(b))
|
||||
body := inbox_body(rcpt_addr, mails)
|
||||
body.Render(req.Context(), res)
|
||||
})
|
||||
|
||||
var port int
|
||||
|
||||
Loading…
Reference in New Issue
Block a user