gmock

package module
v0.5.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 10, 2021 License: MIT Imports: 22 Imported by: 0

README

gmock

Build Status Coverage Status Go Report Card Latest Version License Repo Size

以文件为基准,最简单的 APIs 模拟工具

接口未至,开发先行

这里有一些 example 已经部署到 heroku

特性:

  • 支持所有 HTTP 方法
  • 以最低的成本兼容 JSON 接口
  • 实时更改接口,无需重启服务
  • 自定义模版,满足复杂需求
  • 支持文件流,例如返回图片,下载等
  • 支持渲染 HTML/Markdown 文件

安装

Unix

如果你使用 LinuxmacOS, 你可以输入以下命令安装:

# 安装最新版本
curl -fsSL https://raw.githubusercontent.com/axetroy/gmock/master/install.sh | bash
# 安装指定的版本
curl -fsSL https://raw.githubusercontent.com/axetroy/gmock/master/install.sh | bash -s v0.5.0

Windows

Github Release 页面下载文件

快速开始

首先先创建一个存放 APIs 文件的目录

$ mkdir -p ./apis/v1

然后在创建对应的 APIs 文件

$ touch ./apis/v1/ping.get.json
$ echo "{\"body\": \"tong\"}" > ./apis/v1/ping.get.json

运行命令

# gmock <接口文件目录>
$ gmock ./apis
$ curl http://localhost:8080/v1/ping
tong

文档

从源码中构建

确保你已安装 Golang@v1.14.2 或者更高版本.

$ git clone https://github.com/axetroy/gmock.git $GOPATH/src/github.com/axetroy/gmock
$ cd $GOPATH/src/github.com/axetroy/gmock
$ make build

测试

$ make test

开源许可

The MIT License

Documentation

Index

Constants

View Source
const ROUTER_PARAMS_PLACEHOLDER = "__ROUTER_PARAMS_PLACEHOLDER__"

Variables

View Source
var RootDir string

server's root dir

Functions

func ExtractParamsFromFileName

func ExtractParamsFromFileName(fileName string, urlPath string) map[string]string

func GetRealFileName

func GetRealFileName(fileName string) string

func Lookup

func Lookup(rootDir string, method string, u *url.URL) (*string, map[string]string)

Lookup router file and params context

func MatchFileName

func MatchFileName(rule, name string) bool

func NameToRegExp

func NameToRegExp(name string) *regexp.Regexp

func ParseQuery added in v0.5.0

func ParseQuery(queryStr string) map[string]interface{}

func Server

func Server(addr string, targetDir string) error

Types

type Handler

type Handler struct {
}

func (Handler) ServeHTTP

func (h Handler) ServeHTTP(res http.ResponseWriter, req *http.Request)

type Schema

type Schema struct {
	Status  *int        `json:"status"`  // 返回的状态码
	Body    interface{} `json:"body"`    // 请求体
	Headers interface{} `json:"headers"` // 返回头, 可以是 map[string]string 类型,也可以是 map[string][]string
}

func Render

func Render(req *http.Request) (*Schema, string, error)

return file path & content & status code & error

Directories

Path Synopsis
cmd
lib

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL