本书未发布

12.7. Bind Header

未匹配的标注
package main

/*
先设置bind调用validate app.Binder = eudore.NewValidateBinder(app.Binder),然后bind时会调用Validate验证数据。
*/

import (
    "github.com/eudore/eudore"
    "github.com/eudore/eudore/component/httptest"
)

type bindHeader struct {
    Accept      string
    ContextType string `alias:"Content-Type"`
}

func main() {
    app := eudore.NewApp()
    app.Binder = eudore.NewBinderHeader(app.Binder)

    // 上传文件信息
    app.AnyFunc("/*", func(ctx eudore.Context) {
        var h bindHeader
        ctx.Bind(&h)
    })

    client := httptest.NewClient(app)
    client.NewRequest("HEAD", "/2").WithHeaderValue("Content-Type", "application/json").Do().CheckStatus(200)

    app.Listen(":8088")
    // app.CancelFunc()
    app.Run()
}

反馈和交流请加群组:QQ群373278915

本文章首发在 LearnKu.com 网站上。

上一篇 下一篇
讨论数量: 0
发起讨论 查看所有版本


暂无话题~