infrastructure/testhelper.go
Finn Herzfeld ac5b78b752 Add testhlper.go, a tool for helping with tests
In this case all it does is retrieves verification codes
2018-12-05 12:03:40 -08:00

31 lines
613 B
Go

package main;
import (
"net/http"
// "golang.org/x/net/html"
"database/sql"
_ "github.com/lib/pq"
"os"
"log"
"fmt"
)
func crash(err error) {
if err != nil {
panic(err)
}
}
func main() {
db, err := sql.Open("postgres", os.Getenv("DB"))
crash(err)
http.HandleFunc("/verification-code", func(w http.ResponseWriter, r *http.Request) {
account := r.PostFormValue("account")
var code string
err := db.QueryRow("SELECT verification_code FROM pending_accounts WHERE number = $1", account).Scan(&code)
crash(err)
fmt.Fprintf(w, "%s\n", code)
})
log.Fatal(http.ListenAndServe(":8082", nil))
}