mirror of
https://github.com/GRFreire/nthmail.git
synced 2026-01-09 12:59:38 +00:00
add simple web server
This commit is contained in:
parent
6e0e577916
commit
5767f9d594
34
cmd/web_server/main.go
Normal file
34
cmd/web_server/main.go
Normal file
@ -0,0 +1,34 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/go-chi/chi"
|
||||
)
|
||||
|
||||
func main() {
|
||||
router := chi.NewRouter()
|
||||
|
||||
router.Get("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte("Hello world"))
|
||||
})
|
||||
|
||||
var port int
|
||||
var err error
|
||||
port_str, exists := os.LookupEnv("WEB_SERVER_PORT")
|
||||
if exists {
|
||||
port, err = strconv.Atoi(port_str)
|
||||
if err != nil {
|
||||
log.Fatal("env:MAIL_SERVER_PORT is not a number")
|
||||
}
|
||||
} else {
|
||||
port = 3000
|
||||
}
|
||||
|
||||
log.Println("Listening on port", port)
|
||||
http.ListenAndServe(fmt.Sprintf(":%d", port), router)
|
||||
}
|
||||
1
go.mod
1
go.mod
@ -5,5 +5,6 @@ go 1.21.6
|
||||
require (
|
||||
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
|
||||
github.com/mattn/go-sqlite3 v1.14.22 // indirect
|
||||
)
|
||||
|
||||
2
go.sum
2
go.sum
@ -2,5 +2,7 @@ github.com/emersion/go-sasl v0.0.0-20200509203442-7bfe0ed36a21 h1:OJyUGMJTzHTd1X
|
||||
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=
|
||||
github.com/emersion/go-smtp v0.20.2/go.mod h1:qm27SGYgoIPRot6ubfQ/GpiPy/g3PaZAVRxiO/sDUgQ=
|
||||
github.com/go-chi/chi v1.5.5 h1:vOB/HbEMt9QqBqErz07QehcOKHaWFtuj87tTDVz2qXE=
|
||||
github.com/go-chi/chi v1.5.5/go.mod h1:C9JqLr3tIYjDOZpzn+BCuxY8z8vmca43EeMgyZt7irw=
|
||||
github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
|
||||
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
|
||||
|
||||
Loading…
Reference in New Issue
Block a user