I have same Issue, I have a site already running Yaats. It’s hosted on a linux server and it’s just html alone. Now I want to add a registration golang code into the site for just the templates/registration.html file.
How do I do that?
This is my main.go file:
`
package main
import (
"fmt"
"github.com/gopkg.in/gomail.v2"
"html/template"
"log"
"net/http"
)
//yaatsservices@gmail.com
type registration struct {
Names string
Email string
KnowWhat string
Category string
Occupation string
Residence string
KnowUs string
}
var (
templ *template.Template
err error
)
func main() {
templ, err = templ.ParseGlob("templates/*.html")
if err != nil {
log.Fatalln("error loading files", err.Error())
}
http.HandleFunc("/registration", regs)
http.Handle("/assets/", http.FileServer(http.Dir(".")))
http.ListenAndServe(":8080", nil)
}
func regs(res http.ResponseWriter, req *http.Request) {
if req.Method == "POST" {
subject := "Summer-Camp Registration"
email := req.FormValue("mail")
names := req.FormValue("names")
knowWhat := req.FormValue("des")
category := req.FormValue("studies")
occupation := req.FormValue("occupation")
reside := req.FormValue("state")
knowUs := req.FormValue("publicity")
message := "Name: " + names + "\nWhat to learn: " + knowWhat +
"\nCategory: " + category + "\nOccupational Status" + occupation +
"\nResidential Area: " + reside + "\nHow I heard about You: " + knowUs + "\n"
cb := gomail.NewMessage()
cb.SetHeader("From", email)
cb.SetHeader("To", "davidekefre@gmail.com")
//cb.SetHeader("To", "raillblaze@gmail.com")
cb.SetHeader("Subject", subject)
cb.SetBody("text/plain", message)
d := gomail.NewDialer("smtp.gmail.com", 587, "mymail@gmail.com", "password")
if err := d.DialAndSend(cb); err != nil {
panic(err)
}
fmt.Println("message delivered successfully!")
}
err = templ.ExecuteTemplate(res, "registration.html", nil)
if err != nil {
log.Println(err)
}
}
`