mirror of
https://github.com/GRFreire/nthmail.git
synced 2026-01-09 21:09:39 +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 (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -16,7 +15,7 @@ import (
|
|||||||
|
|
||||||
type mail struct {
|
type mail struct {
|
||||||
Id int
|
Id int
|
||||||
Arrived_at int
|
Arrived_at int64
|
||||||
Rcpt_addr, From_addr string
|
Rcpt_addr, From_addr string
|
||||||
Data []byte
|
Data []byte
|
||||||
}
|
}
|
||||||
@ -98,16 +97,9 @@ func main() {
|
|||||||
|
|
||||||
mails = append(mails, m)
|
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")
|
body := inbox_body(rcpt_addr, mails)
|
||||||
return
|
body.Render(req.Context(), res)
|
||||||
}
|
|
||||||
|
|
||||||
res.Write([]byte(b))
|
|
||||||
})
|
})
|
||||||
|
|
||||||
var port int
|
var port int
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user