func main() {
app := iris.Default()
// This handler will match /user/john but will not match /user/ or /user
app.Get("/user/{name}", func(ctx iris.Context) {
name := ctx.Params().Get("name")
ctx.Writef("Hello %s", name)
})
// However, this one will match /user/john/ and also /user/john/send
// If no other routers match /user/john, it will redirect to /user/john/
app.Get("/user/{name}/{action:path}", func(ctx iris.Context) {
name := ctx.Params().Get("name")
action := ctx.Params().Get("action")
message := name + " is " + action
ctx.WriteString(message)
})
// For each matched request Context will hold the route definition
app.Post("/user/{name:string}/{action:path}", func(ctx iris.Context) {
ctx.GetCurrentRoute().Tmpl().Src == "/user/{name:string}/{action:path}" // true
})
app.Listen(":8080")
}
参数类型 | Go语言类型 | 验证 | iris对应检索 |
string | string | 字符串 | Params().Get |
uuid | string | uuid | Params().Get |
int | int | -9223372036854775808 至 9223372036854775807 | Params().GetInt |
int8 | int8 | -128 至 127 | Params().GetInt8 |
int16 | int16 | -32768 至 32767 | Params().GetInt16 |
int32 | int32 | -2147483648 至 2147483647 | Params().GetInt32 |
int64 | int64 | -9223372036854775808 至 9223372036854775807 | Params().GetInt64 |
unit | uint | 0 至 18446744073709551615 | Params().GetUint |
unit8 | uint8 | 0 至 255 | Params().GetUint8 |
unit16 | uint16 | 0 至 65535 | Params().GetUint16 |
uint32 | uint32 | 0 至 4294967295 | Params().GetUint32 |
uint64 | uint64 | 0 至 18446744073709551615 | Params().GetUint64 |
bool | bool | true 或 false | Params().GetBool |
alphabetical | string | 小写(大写)字母 | Params().Get |
file | string | 小写或大写字母、数字、下划线 (_)、破折号 (-)、点 (.) | Params().Get |
path | string | 可以用斜杠(路径段)分隔,但应该是路径路径的最后一部分 | Params().Get |
更多示例可以点这里找到
FastAPI不要求您使用 SQL(关系)数据库。但是您可以使用任何您想要的关系数据库。在这里,我们将看到一个使用SQLAlchemy的示例...
在 Flask 中,通过使用特殊的g对象可以使用before_request()和teardown_request()在请求开始前打开数据库连接,在请求结束后关闭...
编写测试Django 的单元测试采用 Python 的标准模块: unittest。该模块以类的形式定义测试。下面是一个例子,它是 django....
Vary标头定义了缓存机制在构建其缓存键时应考虑哪些请求标头。例如,如果网页的内容取决于用户的语言偏好,则称该页面因语言而异...
SWING - 控件每个用户界面考虑有以下三个主要方面:UI 元素: 有用户最终看到并且与之交互的核心视觉元素。GWT 提供了一个大量的...
以下是 JUnit 扩展CactusJWebUnitXMLUnitMockObjectCactusCactus 是一个简单框架用来测试服务器端的 Java 代码(Servlets, EJBs,...
动态SQL是MyBatis的强大特性之一。如果你使用过JDBC或其它类似的框架,你应该能理解根据不同条件拼接SQL语句有多痛苦,例如...