Skip to content
mock api server , default response {"status":"ok"}
Go Dockerfile
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
www Allow specified files May 2, 2017
.gitignore Allow specified files May 2, 2017
Dockerfile Allow specified files May 2, 2017
main.go Enable websocket Jul 31, 2019
readme.md Update readme.md Jul 31, 2019

readme.md

Mock server

This app will mock http api server, listen default on :7890, it accept any post/get

Run

To quick run a mock server

docker run --restart=always -d --name ms -v $(pwd)/www:/www -p 7890:7890 netroby/mock-server 

make sure ./www exists, and mock-server will try to find exists file to handler api request.

such as ./www/api/version.json will handle as http://example.com/api/version.json

The default MIME type for response, will be application/json

build

to build static binary

CGO_ENABLED=0 go build -a -ldflags '-extldflags "-static"' .

preview

netroby@mi ~/go/src/github.com/netroby/mock-server (master) $ curl -v 127.0.0.1:7890
* Uses proxy env variable no_proxy == '.dz11.com,localhost,127.0.0.1,localaddress,.localdomain.com,isrv.us,10.119.25.116,10.118.26.135'
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 7890 (#0)
> GET / HTTP/1.1
> Host: 127.0.0.1:7890
> User-Agent: curl/7.64.1
> Accept: */*
> 
< HTTP/1.1 200 OK
< Content-Type: application/json
< Date: Wed, 31 Jul 2019 07:12:55 GMT
< Content-Length: 15
< 
* Connection #0 to host 127.0.0.1 left intact
{"status":"ok"}* Closing connection 0
netroby@mi ~/go/src/github.com/netroby/mock-server (master) $ systemctl status ms1.service
¡ñ ms1.service
  Loaded: loaded (/etc/systemd/system/ms1.service; enabled; vendor preset: enabled)
  Active: active (running) since Tue 2019-07-30 08:42:56 CST; 1 day 6h ago
Main PID: 1067 (mock-server)
   Tasks: 5 (limit: 4915)
  Memory: 6.3M
  CGroup: /system.slice/ms1.service
          ©¸©¤1067 /home/netroby/go/bin/mock-server -l 7890

Jul 30 08:42:56 min mock-server[1067]:  - using env:        export GIN_MODE=release
Jul 30 08:42:56 min mock-server[1067]:  - using code:        gin.SetMode(gin.ReleaseMode)
Jul 30 08:42:56 min mock-server[1067]: [GIN-debug] Listening and serving HTTP on :7890
Jul 31 15:12:55 min mock-server[1067]: GET / HTTP/1.1
Jul 31 15:12:55 min mock-server[1067]: Host: 127.0.0.1:7890
Jul 31 15:12:55 min mock-server[1067]: Accept: */*
Jul 31 15:12:55 min mock-server[1067]: User-Agent: curl/7.64.1
Jul 31 15:12:55 min mock-server[1067]: [1B blob data]
Jul 31 15:12:55 min mock-server[1067]: Request file./www/
Jul 31 15:12:55 min mock-server[1067]: [GIN] 2019/07/31 - 15:12:55 | 200 |    2.429254ms |       127.0.0.1 | GET      /
You can’t perform that action at this time.