Categorygithub.com/haozibi/httpbee
repositorypackage
0.1.2
Repository: https://github.com/haozibi/httpbee.git
Documentation: pkg.go.dev

# Packages

No description provided by the author
No description provided by the author

# README

httpbee

CircleCI

Fake HTTP Server

根据 JSON 配置文件做出响应

快速开始

$ httpbee -f=config.json

config.json 示例

配置文件说明

字段类型是否必需默认值说明其他
routerstring匹配路由精准匹配,按照声明顺序匹配
typestringbody此路由响应方式共支持三种(body、static、proxy)
resp.statusint200响应状态码例如: 200、404、502
resp.headersjsonHTTP 响应头例如: "content-type": "application/text"
resp.bodyrawtype=body 时的响应输出会按照 raw 形式输出
resp.filestringtype=static 时的响应内容的文件路径例如: logo.png
resp.proxystringtype=proxy 时代理的路径例如: http://google.com
[
    {
        "router": "/hello",
        "resp": {
            "status": 200,
            "headers": {
                "version": "0.0.1",
                "content-type": "text/plain"
            },
            "body": "world"
        }
    },
    {
        "router": "/file",
        "type": "static",
        "resp": {
            "status": 200,
            "file": "logo.png"
        }
    },
    {
        "router": "/html",
        "type": "static",
        "resp": {
            "status": 200,
            "headers": {
                "content-type": "text/html"
            },
            "file": "1.html"
        }
    },
    {
        "router": "/json",
        "type": "body",
        "resp": {
            "status": 200,
            "headers": {
                "content-type": "application/json"
            },
            "body": {
                "err_code": 0,
                "err_msg": "success",
                "data": "ok"
            }
        }
    }
]

todo

  • 是否支持 Query 参数
  • 是否支持 HTTP Method 方法过滤

已知 Bug

使用 vim 编辑 config.json 时会导致 fsnotify 监听错误(正常编辑会监听到 REMOVE 操作),导致 config.json 失效

注意事项

  • 路由精准匹配,并按照声明顺序尽心匹配

resp.type:

  • static: 静态文件(文件具体形式根据 header 决定)
  • body: 文件