跳至主要內容

Introduce

The Yock authors小于 1 分钟

go-faker binding for yock, and built-in captcha and random avatars functions for mock service.

Install

ypm install github.tag/ansurfen/yock-faker@1.0.0

Get started

Faker data

print(fake.name(), fake.email())

Mock with captcha and random avatars

local port = init("yock-faker@1.0.0")
---@type faker
local fake = import("./index")
fake.set_port(port)

local m = mock.new()

-- writes a random avatar into response according to name
m:get("/avatar/:name", function(ctx)
    local name = ctx:Param("name")
    fake.avatar.govatar(ctx, name)
end)

-- writes captcha into response according to captcha's id
m:get("/captcha/get/:id", function(ctx)
    local id = ctx:Param("id")
    fake.captcha.get(ctx, id)
end)

-- returns a captcha's id
m:get("/captcha/new", function(ctx)
    local id = fake.captcha.new()
    ctx:String(200, id)
end)

-- lists all avaiable captcha's id
m:get("/captcha/ls", function(ctx)
    ctx:String(200, json.encode(fake.captcha.ls()))
end)

m:run(8080)