agiledragon / agiledragon/gomonkey
ApplyMethod Invalid with -gcflags=all=-l in beego framework controller.ServeJSON()
- Langage dominant
- Go
- Étoiles
- 2.3k
- Forks
- 192
- Merge moyen
- 1 j 6 h
- PR mergées (30 j)
- 1
Description
my environment:
- mac Os 10.14.6
- golang 1.14.2
- gomonkey 2.0.2
- beego framework
As my title description, it work well until i encountered the method :
```go
func (c *Controller) ServeJSON(encoding ...bool) {
var (
hasIndent = BConfig.RunMode != PROD
hasEncoding = len(encoding) > 0 && encoding[0]
)
c.Ctx.Output.JSON(c.Data["json"], hasIndent, hasEncoding)
}
```
even though i use the -gcflags=all=-l , it's doesn't work as well.
There is my test code:
```go
var c *myController
patches := ApplyMethod(reflect.TypeOf(c), "ServeJSON",func(*myController, ...bool) {
//do nothing
})
defer patches.Reset()
```
see the result as below :
```shell
panic(0x494ab60, 0x53e96d0)
/usr/local/go/src/runtime/panic.go:969 +0x191
github.com/astaxie/beego/context.(*BeegoOutput).Header(0xc00031e6a0, 0x4a7cca5, 0xc, 0x4a93a96, 0x1f)
/Users/xxx/go/src/github.com/astaxie/beego/context/output.go:58 +0x25
github.com/astaxie/beego/context.(*BeegoOutput).JSON(0xc00031e6a0, 0x49c2ba0, 0xc00037ca20, 0xc000380000, 0xc00038a128, 0xc00038a120)
/Users/xxx/go/src/github.com/astaxie/beego/context/output.go:189 +0x6a
github.com/astaxie/beego.(*Controller).ServeJSON(0xc0001c42a0, 0x0, 0x0, 0x0)
/Users/xxx/go/src/github.com/astaxie/beego/controller.go:357 +0xdc
```
How to fix this problem or recommand me a HTTP unit test framework ? Thanks!!!!
Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Évaluation
Cette issue n'a pas encore été évaluée.