38 lines
844 B
Go
38 lines
844 B
Go
package utils
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"log"
|
|
|
|
"gopkg.in/gomail.v2"
|
|
|
|
"golang.org/x/crypto/bcrypt"
|
|
)
|
|
|
|
func HashPassword(password string) ([]byte, error) {
|
|
return bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
|
|
}
|
|
|
|
func PrettyPrintJson(data interface{}) {
|
|
b, err := json.MarshalIndent(data, "", " ")
|
|
if err != nil {
|
|
fmt.Println("error:", err)
|
|
}
|
|
log.Println(string(b))
|
|
}
|
|
|
|
func SendEmail(email string) {
|
|
m := gomail.NewMessage()
|
|
m.SetHeader("From", "suporte@pcastlive.com")
|
|
m.SetHeader("To", email)
|
|
m.SetHeader("Subject", "Test Email from Go")
|
|
m.SetBody("text/plain", "This is a test email sent from a Go application.")
|
|
|
|
d := gomail.NewDialer("smtp.kinghost.net", 465, "suporte@pcastlive.com", "@407Smc837")
|
|
|
|
if err := d.DialAndSend(m); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|