Coder Social home page Coder Social logo

mockserver's Introduction

A simple mock server with Go

用Go语言实现的一个简单的mock server (只支持完整的path匹配,不支持参数化), 在配置文件 mapping.json 文件中配置每个请求的path、对应的请求方式、保存Response数据的文件路径.

示例如下:

[
  {
    "path": "/v4/users/",
    "method": "GET",
    "resp_file": "/Users/yourname/config/responses/users_resp.json"
  },
  {
    "path": "/v5/categories/rec/articles/next/",
    "method": "POST",
    "resp_file": "/Users/yourname/config/responses/news_list_data.json"
  }
]

启动mock server

进入到项目所在的目录,执行启动命令

go run mockserver.go ~/mapping.json

其中最后一个参数为 mapping.json 所在的路径, 修改为你的mapping路径即可.

验证mock server 是否正常启动

终端中输入如下Log 即表示成功解析mapping文件,并启动mock server.

Mapping file is  /Users/yourname/mapping.json
=================================================> init router START
route :  path : /v4/users/, method : GET, file : /Users/yourname/config/responses/users_resp.json .
route :  path : /v5/categories/rec/articles/next/, method : GET, file : /Users/yourname/config/responses/news_list_data.json .
route :  path : /v9/categories/sorted/, method : GET, file : /Users/yourname/config/responses/channels.json .
================================================> init router END !

mockserver's People

Contributors

hehonghui avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.