Пример #1
0
func getAndSetHandler(responseWriter http.ResponseWriter, request *http.Request) {
	request.ParseForm()
	token := request.Form.Get("token")

	if validToken(token) {
		var err error

		if request.Method == "POST" {
			recordNote(request.Form)
			responseWriter.Write([]byte("Got it!"))
		} else {
			err = respondWithJSON(responseWriter, SummaryResponse{notable.Notes()})
		}

		if err != nil {
			http.Error(responseWriter, err.Error(), http.StatusInternalServerError)
		}
	} else {
		fmt.Printf("Invalid token received: %s\n", token)
		http.Error(responseWriter, "Invalid token", http.StatusForbidden)
	}
}
Пример #2
0
func main() {
	if port, err := strconv.Atoi(os.Getenv("SMTP_PORT")); err == nil {
		if len(notable.Notes()) > 0 {
			notable.SendEmail(
				os.Getenv("SMTP_HOST"),
				port,
				os.Getenv("SMTP_USERNAME"),
				os.Getenv("SMTP_PASSWORD"),
				os.Getenv("FROM_EMAIL"),
				os.Getenv("FROM_NAME"),
				os.Getenv("TO_EMAIL"),
				os.Getenv("TO_NAME"),
			)
			if os.Getenv("NO_RESET") == "" {
				notable.Reset()
			} else {
				log.Print("Not resetting notes")
			}
		}
	} else {
		log.Fatal(err)
	}
}
Пример #3
0
func main() {
	if len(notable.Notes()) > 0 {
		notable.SendEmail(os.Getenv("MANDRILL_API_KEY"))
		notable.Reset()
	}
}