Browse Source

Organising project

main
Дмитрий 2 years ago
parent
commit
f97b9b6691
  1. 32
      Makefile
  2. 36
      internal/moc_server.go

32
Makefile

@ -1,19 +1,39 @@
# port for main server
port := 5053
moc_server_address := 127.0.0.1:5059
run:
go run cmd/main.go -p 5053 -d "127.0.0.1:5059"
go run cmd/main.go -p $(port) -d "$(moc_server_address)"
test-ip:
go run cmd/main.go -p 5053 -d "127.0.0.1:5059,localhost:5059"
go run cmd/main.go -p $(port) -d "$(moc_server_address),localhost:5059"
test-port:
go run cmd/main.go -p 5053 -d "127.0.0.1:5059,127.0.0.1:as"
go run cmd/main.go -p $(port) -d "$(moc_server_address),127.0.0.1:as"
test-port-max:
go run cmd/main.go -p 5053 -d "127.0.0.1:5059,127.0.0.1:65537"
go run cmd/main.go -p $(port) -d "$(moc_server_address),127.0.0.1:65537"
test-port-endpoint:
go run cmd/main.go -p 5053 -d "127.0.0.1:9001/bid_request"
go run cmd/main.go -p $(port) -d "127.0.0.1:9001/bid_request"
build:
go build -o bin/simple-choose-ad cmd/main.go
tests:
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
stop-moc-server:
@echo "[!] Killing moc server"
@cat run.pid | xargs kill -9
@rm run.pid
test-server:
@echo "Testing server..."
@cd "cmd/client_server/"; \
go test
tests: start-moc-server
@$(MAKE) test-server
@$(MAKE) stop-moc-server

36
internal/moc_server.go

@ -0,0 +1,36 @@
package main
import (
"io/ioutil"
"log"
"net/http"
)
func main() {
vres := `{
"id": "123",
"imp": [{
"id": 123,
"width": 144,
"height": 122,
"title": "Title1",
"url": "example.com",
"price": 123.5
},{
"id": 123,
"width": 155,
"height": 133,
"title": "Title2",
"url": "upachka.com",
"price": 143.5
}]}`
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))
}
Loading…
Cancel
Save