44 lines
614 B
Go
44 lines
614 B
Go
//
|
|
// context_test.go
|
|
// Copyright (C) 2023 tiglog <me@tiglog.com>
|
|
//
|
|
// Distributed under terms of the MIT license.
|
|
//
|
|
|
|
package gweb_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"git.hexq.cn/tiglog/golib/gweb"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type controller struct {
|
|
}
|
|
|
|
func (ctl *controller) foo(c *gweb.Context) {
|
|
|
|
c.JSON(200, gin.H{
|
|
"code": 0,
|
|
"msg": "hi, foo",
|
|
})
|
|
}
|
|
|
|
func (ctl *controller) bar(c *gweb.Context) {
|
|
c.String(200, "hello bar")
|
|
}
|
|
|
|
func TestContext(t *testing.T) {
|
|
app := gweb.New()
|
|
|
|
ctl := &controller{}
|
|
app.GET("/root", ctl.foo)
|
|
|
|
v1 := app.Group("/v1")
|
|
{
|
|
v1.GET("/foo", ctl.bar)
|
|
}
|
|
_ = app.Run()
|
|
}
|