infrastructure/testhelper.go

44 lines
964 B
Go
Raw Normal View History

2018-12-18 08:23:12 +00:00
package main
import (
"database/sql"
2018-12-18 08:23:12 +00:00
"fmt"
_ "github.com/lib/pq"
2018-12-18 08:23:12 +00:00
"io/ioutil"
"log"
2018-12-18 08:23:12 +00:00
"net/http"
"os"
)
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("number")
var code string
err := db.QueryRow("SELECT verification_code FROM pending_accounts WHERE number = $1", account).Scan(&code)
log.Printf("Looking for verification code for %s", account)
2018-12-18 08:23:12 +00:00
if err != nil {
panic(err)
2018-12-18 08:23:12 +00:00
} else {
fmt.Fprintf(w, "%s\n", code)
2018-12-18 08:20:55 +00:00
}
})
2020-06-25 05:50:22 +00:00
http.HandleFunc("/v2/directory/reconcile", func(w http.ResponseWriter, r *http.Request) {
2018-12-18 08:23:12 +00:00
_, err := ioutil.ReadAll(r.Body)
2018-12-05 21:49:32 +00:00
defer r.Body.Close()
crash(err)
w.Header().Set("Content-Type", "application/json")
w.Write([]byte("{\"status\": \"OK\"}\n"))
})
log.Fatal(http.ListenAndServe(":8082", nil))
}