diff --git a/Makefile b/Makefile index c7d033a..15a8614 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ build: start-moc-server: @echo "[!] Starting moc server on 127.0.0.1:5059..." - @nohup go run internal/moc_server.go> /dev/null 2>&1 & echo $! > run.pid + @nohup go run internal/moc_server.go -l $(moc_server_address)> /dev/null 2>&1 & echo $! > run.pid stop-moc-server: @echo "[!] Killing moc server" diff --git a/internal/moc_server.go b/internal/moc_server.go index 6835fd8..642a594 100644 --- a/internal/moc_server.go +++ b/internal/moc_server.go @@ -1,6 +1,7 @@ package main import ( + "flag" "io/ioutil" "log" "net/http" @@ -24,13 +25,19 @@ func main() { "url": "upachka.com", "price": 143.5 }]}` + + addr := flag.String("l", "", "-l 127.0.0.1:5059") + flag.Parse() + if *addr == "" { + log.Fatalln("Error: listening address is required!") + } + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { b, _ := ioutil.ReadAll(r.Body) log.Println(string(b)) - // as, err := json.Marshal(vres) w.Header().Add("Content-Type", "application/json") w.Write([]byte(vres)) }) - log.Fatal(http.ListenAndServe("127.0.0.1:5059", nil)) + log.Fatal(http.ListenAndServe(*addr, nil)) }