infrastructure/testhelper.go

41 lines
891 B
Go
Raw Normal View History

package main;
import (
"net/http"
2018-12-05 21:49:32 +00:00
"io/ioutil"
"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("/helper/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)
})
2018-12-05 21:19:28 +00:00
http.HandleFunc("/v1/directory/reconcile", func(w http.ResponseWriter, r *http.Request) {
2018-12-05 21:49:32 +00:00
b, err := ioutil.ReadAll(r.Body)
defer r.Body.Close()
crash(err)
log.Printf("%s", b)
w.Header().Set("Content-Type", "application/json")
w.Write([]byte("{\"status\": \"OK\"}\n"))
})
log.Fatal(http.ListenAndServe(":8082", nil))
}