add index page and button to generate random inbox

This commit is contained in:
Guilherme Rugai Freire 2024-02-20 17:59:47 -03:00
parent c0c1ba4c08
commit 95252f12f5
No known key found for this signature in database
GPG Key ID: AC1D9B6E48E16AC1
4 changed files with 1667 additions and 4 deletions

View File

@ -1,5 +1,22 @@
package main
templ index(appname string) {
<h1>Home for { appname }</h1>
templ index_page() {
<!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>nthmail.xyz</h1>
<p>
A disposable, temporary and private mail address!
</p>
<form action="random" >
<button type="submit">Get one now!</button>
</form>
</body>
</html>
}

View File

@ -9,6 +9,7 @@ import (
"os"
"strconv"
"github.com/GRFreire/nthmail/pkg/rig"
"github.com/go-chi/chi"
_ "github.com/mattn/go-sqlite3"
)
@ -27,11 +28,23 @@ func main() {
}
defer db.Close()
domain, exists := os.LookupEnv("MAIL_SERVER_DOMAIN")
if !exists {
domain = "localhost"
}
router := chi.NewRouter()
router.Get("/", func(res http.ResponseWriter, req *http.Request) {
component := index("nthmail.xyz")
component.Render(req.Context(), res)
page := index_page()
page.Render(req.Context(), res)
})
router.Get("/random", func(res http.ResponseWriter, req *http.Request) {
inbox_name := rig.GenerateRandomInboxName()
inbox_addr := fmt.Sprintf("/%s@%s", inbox_name, domain)
http.Redirect(res, req, inbox_addr, 307)
})
router.Get("/{rcpt-addr}", func(res http.ResponseWriter, req *http.Request) {

1619
pkg/rig/dict.go Normal file

File diff suppressed because it is too large Load Diff

14
pkg/rig/rig.go Normal file
View File

@ -0,0 +1,14 @@
package rig
import (
"fmt"
"math/rand"
)
func GenerateRandomInboxName() string {
animal := animals[rand.Intn(len(animals))]
color := colors[rand.Intn(len(colors))]
adjective := adjectives[rand.Intn(len(adjectives))]
return fmt.Sprintf("%s-%s-%s", adjective, color, animal)
}