-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
36 lines (29 loc) · 840 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package main
import (
"log"
"net/http"
"os"
"github.com/ministryofjustice/opg-go-common/env"
)
func main() {
port := env.Get("PORT", "8080")
http.HandleFunc("/search/places/v1/postcode", func(w http.ResponseWriter, r *http.Request) {
postcode := r.URL.Query().Get("postcode")
log.Println("postcode searched:", postcode)
var postcodeJson []byte
switch postcode {
case "INVALID":
postcodeJson, _ = os.ReadFile("data/invalid-postcode-error.json")
case "NE234EE":
postcodeJson, _ = os.ReadFile("data/no-addresses-found.json")
default:
postcodeJson, _ = os.ReadFile("data/multiple-addresses.json")
}
w.Write(postcodeJson)
// to aid debugging e2e test failures
log.Println("OS mock response:", string(postcodeJson))
})
if err := http.ListenAndServe(":"+port, nil); err != nil {
log.Fatal(err)
}
}