mirror of
https://github.com/GRFreire/nthmail.git
synced 2026-01-08 12:29:38 +00:00
add templ and initial frontend code
This commit is contained in:
parent
e07aeea312
commit
40900f3112
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
bin/*
|
||||
!bin/.gitkeep
|
||||
*_templ.go
|
||||
*.db
|
||||
|
||||
0
bin/.gitkeep
Normal file
0
bin/.gitkeep
Normal file
5
cmd/web_server/index.templ
Normal file
5
cmd/web_server/index.templ
Normal file
@ -0,0 +1,5 @@
|
||||
package main
|
||||
|
||||
templ index(appname string) {
|
||||
<h1>Home for { appname }</h1>
|
||||
}
|
||||
@ -29,6 +29,11 @@ func main() {
|
||||
|
||||
router := chi.NewRouter()
|
||||
|
||||
router.Get("/", func(res http.ResponseWriter, req *http.Request) {
|
||||
component := index("nthmail.xyz")
|
||||
component.Render(req.Context(), res)
|
||||
})
|
||||
|
||||
router.Get("/{rcpt-addr}", func(res http.ResponseWriter, req *http.Request) {
|
||||
rcpt_addr := chi.URLParam(req, "rcpt-addr")
|
||||
if len(rcpt_addr) == 0 {
|
||||
@ -78,7 +83,7 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
mails = append(mails, m)
|
||||
mails = append(mails, m)
|
||||
}
|
||||
b, err := json.Marshal(mails)
|
||||
if err != nil {
|
||||
@ -104,5 +109,8 @@ func main() {
|
||||
}
|
||||
|
||||
log.Println("Listening on port", port)
|
||||
http.ListenAndServe(fmt.Sprintf(":%d", port), router)
|
||||
err = http.ListenAndServe(fmt.Sprintf(":%d", port), router)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
1
go.mod
1
go.mod
@ -3,6 +3,7 @@ module github.com/GRFreire/nthmail
|
||||
go 1.21.6
|
||||
|
||||
require (
|
||||
github.com/a-h/templ v0.2.543 // indirect
|
||||
github.com/emersion/go-sasl v0.0.0-20200509203442-7bfe0ed36a21 // indirect
|
||||
github.com/emersion/go-smtp v0.20.2 // indirect
|
||||
github.com/go-chi/chi v1.5.5 // indirect
|
||||
|
||||
2
go.sum
2
go.sum
@ -1,3 +1,5 @@
|
||||
github.com/a-h/templ v0.2.543 h1:8YyLvyUtf0/IE2nIwZ62Z/m2o2NqwhnMynzOL78Lzbk=
|
||||
github.com/a-h/templ v0.2.543/go.mod h1:jP908DQCwI08IrnTalhzSEH9WJqG/Q94+EODQcJGFUA=
|
||||
github.com/emersion/go-sasl v0.0.0-20200509203442-7bfe0ed36a21 h1:OJyUGMJTzHTd1XQp98QTaHernxMYzRaOasRir9hUlFQ=
|
||||
github.com/emersion/go-sasl v0.0.0-20200509203442-7bfe0ed36a21/go.mod h1:iL2twTeMvZnrg54ZoPDNfJaJaqy0xIQFuBdrLsmspwQ=
|
||||
github.com/emersion/go-smtp v0.20.2 h1:peX42Qnh5Q0q3vrAnRy43R/JwTnnv75AebxbkTL7Ia4=
|
||||
|
||||
31
run-web.sh
Executable file
31
run-web.sh
Executable file
@ -0,0 +1,31 @@
|
||||
#!/bin/sh
|
||||
|
||||
watch_dir="cmd/web_server"
|
||||
pid=0
|
||||
|
||||
get_ts() {
|
||||
stat "$watch_dir" | grep Modify | awk '{$1=""; print $0}' | sed 's/^ //g'
|
||||
}
|
||||
|
||||
run_server() {
|
||||
make -B web
|
||||
./bin/web_server &
|
||||
pid=$!
|
||||
}
|
||||
|
||||
ts="$(get_ts)"
|
||||
run_server
|
||||
|
||||
while true; do
|
||||
sleep 1;
|
||||
new_ts="$(get_ts)"
|
||||
if [ "$ts" != "$new_ts" ]; then
|
||||
ts="$new_ts"
|
||||
echo ""
|
||||
if [ "$pid" != "0" ]; then
|
||||
kill -s KILL $pid
|
||||
fi
|
||||
run_server
|
||||
fi
|
||||
done
|
||||
|
||||
Loading…
Reference in New Issue
Block a user