1:iris的学习文档:
https://studyiris.com/doc/irisDoc/Routing.html(翻译的比较好,版本问题,容易遇到坑我第一个问题就是在这个文档遇到的)
https://learnku.com/docs/iris-go/10/routing_parameters/3768(这个就很推荐)
https://docs.iris-go.com/iris/routing/routing-path-parameter-types#parameters(英文版,但是准确性要高)
2:项目搭建:
go mod init 项目名字
get -u github.com/kataras/iris 安装iris
3-9里面是具体的框架,之后学习过程中不断补充。。。。。
10:第一个坑:(动态路由参数设置问题)
报错信息:./main.go:22:14: app.APIBuilder.Macros().Int undefined (type *macro.Macros has no field or method Int)
代码:按照第一个文档里面敲的
版本:我使用的iris是v11.1.1
第一种修改:
app.Macros().Get("int").RegisterFunc("min", func(minValue int) func(string) bool {
// 在此之前做任何事情[...]
//在这种情况下,我们不需要做任何事情
return func(paramValue string) bool {
n, err := strconv.Atoi(paramValue)
if err != nil {
return false
}
return n >= minValue
}
})
第二种修改:
# 这种修改方法,导入包的时候需要加上
# "github.com/kataras/iris/macro"
macro.Int.RegisterFunc("min", func(minValue int) func(string) bool {
return func(paramValue string) bool {
n, err := strconv.Atoi(paramValue)
if err != nil {
return false
}
return n >= minValue
}
})