diff --git a/main.go b/main.go index 2695134..8fe100d 100644 --- a/main.go +++ b/main.go @@ -6,8 +6,8 @@ import ( "html" "log" "net/http" - "strings" "strconv" + "strings" "gopkg.in/gomail.v2" ) @@ -114,14 +114,14 @@ type FormData struct { // rootHandler serves a minimal HTML page with a contact form and JS to submit to /send func rootHandler(w http.ResponseWriter, r *http.Request) { - if r.Method != http.MethodGet { - http.Error(w, "GET only", http.StatusMethodNotAllowed) - return - } - w.Header().Set("Content-Type", "text/html; charset=utf-8") - htmlEsc := html.EscapeString(docsHTMLSnippet) - jsEsc := html.EscapeString(docsJSSnippet) - page := fmt.Sprintf(` + if r.Method != http.MethodGet { + http.Error(w, "GET only", http.StatusMethodNotAllowed) + return + } + w.Header().Set("Content-Type", "text/html; charset=utf-8") + htmlEsc := html.EscapeString(docsHTMLSnippet) + jsEsc := html.EscapeString(docsJSSnippet) + page := fmt.Sprintf(` @@ -188,7 +188,7 @@ func rootHandler(w http.ResponseWriter, r *http.Request) { `, htmlEsc, jsEsc) - w.Write([]byte(page)) + w.Write([]byte(page)) } type EmailConfig struct { @@ -290,7 +290,8 @@ func enableCors(handler http.HandlerFunc) http.HandlerFunc { // sendParamsHandler handles sending email with explicit SMTP parameters via query string. // Example: -// GET /send-params?email=user@example.com&pass=secret&server=smtp.example.com&port=465&to=dest@example.com&from=user@example.com&subject=Hello&message=Hi +// +// GET /send-params?email=user@example.com&pass=secret&server=smtp.example.com&port=465&to=dest@example.com&from=user@example.com&subject=Hello&message=Hi func sendParamsHandler(w http.ResponseWriter, r *http.Request) { if r.Method != http.MethodGet { http.Error(w, "GET only", http.StatusMethodNotAllowed) @@ -343,17 +344,14 @@ func sendParamsHandler(w http.ResponseWriter, r *http.Request) { return } - w.Header().Set("Content-Type", "application/json") - _ = json.NewEncoder(w).Encode(map[string]string{"status": "ok", "message": "Email sent successfully"}) + w.Header().Set("Content-Type", "application/json") + _ = json.NewEncoder(w).Encode(map[string]string{"status": "ok", "message": "Email sent successfully"}) } // docsHandler serves a minimal JSON API description. func main() { - http.HandleFunc("/send", enableCors(sendHandler)) - http.HandleFunc("/send-params", enableCors(sendParamsHandler)) - http.HandleFunc("/", enableCors(rootHandler)) - log.Println("Server running on :8080") - log.Fatal(http.ListenAndServe(":8080", nil)) + http.HandleFunc("/send", enableCors(sendHandler)) + log.Println("Server running on :660") + log.Fatal(http.ListenAndServe(":660", nil)) } -