路由

路由分组

app := erguotou.New()

    api := app.Group("/api")
    {
        api.Get("/hello", func(ctx *erguotou.Context) {
            ctx.String(200, "hello")
        })

        api.Get("/ppc", func(ctx *erguotou.Context) {
            ctx.String(200, "ppc")
        })
    }

    err := app.Run(erguotou.SetHost(":8082"))
    if err != nil {
        panic(err)
    }

Restful 风格路由

app := erguotou.New()

    app.Get("/", func(ctx *erguotou.Context) {
        ctx.String(200, "hello erguotou")
    })

    app.Post("/", func(ctx *erguotou.Context) {
        ctx.String(200, "hello erguotou")
    })

    app.Delete("/", func(ctx *erguotou.Context) {
        ctx.String(200, "hello erguotou")
    })

    app.Put("/", func(ctx *erguotou.Context) {
        ctx.String(200, "hello erguotou")
    })

    app.Head("/", func(ctx *erguotou.Context) {
        ctx.String(200, "hello erguotou")
    })

    app.Options("/", func(ctx *erguotou.Context) {
        ctx.String(200, "hello erguotou")
    })

    app.Patch("/", func(ctx *erguotou.Context) {
        ctx.String(200, "hello erguotou")
    })

    err := app.Run(erguotou.SetHost(":8081"), erguotou.SetDebug(false))
    if err != nil {
        panic(err)
    }

路径中参数

app.Get("/hello/:hello", func(ctx *erguotou.Context) {
    value, b := ctx.PathValueString("hello")
    if b {
        ctx.String(200,value)
    }
})

results matching ""

    No results matching ""