I'm creating a standalone mockserver with JSON file as my input (request and response) for integration testing. I was able to serve first request only.
// MockServices ...
type MockServices struct {
Request string `json:"request"`
Response string `json:"response"`
}
func main() {
r := getMockServices()
for i, s := range r {
for i >= 0 {
// fmt.Println(i)
// fmt.Println(s.Request)
http.HandleFunc(s.Request, func(w http.ResponseWriter, r *http.Request) {
// not serving remaing endpoints
w.Write([]byte(s.Response))
})
if err := http.ListenAndServe(":8080", nil); err != nil {
panic(err)
}
}
}}
https://play.golang.org/p/_kFaxMnRTJJ
Any help greatly appreciated.
Thanks in advance