Comments (12)
commit b54685b should fix this.
from gomacro.
commit b54685b should fix this.
First of all, thank you very much for the fix, in fact, I still have a way to avoid this problem, you can take a look
link
from gomacro.
I tried again and found that the problem still exists
from gomacro.
Third fix applied in commit c545040. Let's see if it's enough this time :)
Oh yeah! This fix commit c545040 perfectly fixes the bug. Thanks for taking the time to solve it, I think this project has been further improved as well.
from gomacro.
So, is it because of on in gomacro cli
run the code import _b "github.com/imroc/req/v3"
, cause the problem?
from gomacro.
Hello @JoiLa,
I have tested the code fragment you pass to gomacro on go-1.17.3 running on Linux/amd64, and I confirm it produces an error:
$ gomacro
// Welcome to gomacro. Type :help for help, :copy for copyright and license.
// This is free software with ABSOLUTELY NO WARRANTY.
gomacro> import (
. . . . "fmt"
. . . . "github.com/imroc/req/v3"
. . . . )
// debug: running "go get github.com/imroc/req/v3" ...
go: downloading github.com/imroc/req/v3 v3.10.0
go: downloading github.com/imroc/req v0.3.2
go: downloading github.com/hashicorp/go-multierror v1.1.1
go: downloading golang.org/x/net v0.0.0-20220111093109-d55c255bac03
go: downloading golang.org/x/text v0.3.7
go: downloading github.com/hashicorp/errwrap v1.0.0
go get: added github.com/hashicorp/errwrap v1.0.0
go get: added github.com/hashicorp/go-multierror v1.1.1
go get: added github.com/imroc/req/v3 v3.10.0
go get: added golang.org/x/net v0.0.0-20220111093109-d55c255bac03
go get: added golang.org/x/text v0.3.7
// debug: running "go mod tidy" ...
// debug: compiling "/home/max/go/src/gomacro.imports/github.com/imroc/req/v3/v3.go" ...
gomacro> client := req.C()
gomacro> // send http url request
gomacro> response, err := client.R().Get("https://api.github.com/users/cosmos72")
gomacro> // get response data
gomacro> fmt.Println(len(response.Bytes()), err)
reflect: Call using *req.Response as type req.Response
The issue is in the call response.Bytes()
:
gomacro> response.Bytes()
reflect: Call using *req.Response as type req.Response
I will investigate the reason.
from gomacro.
Hello @JoiLa, I have tested the code fragment you pass to gomacro on go-1.17.3 running on Linux/amd64, and I confirm it produces an error:
$ gomacro // Welcome to gomacro. Type :help for help, :copy for copyright and license. // This is free software with ABSOLUTELY NO WARRANTY. gomacro> import ( . . . . "fmt" . . . . "github.com/imroc/req/v3" . . . . ) // debug: running "go get github.com/imroc/req/v3" ... go: downloading github.com/imroc/req/v3 v3.10.0 go: downloading github.com/imroc/req v0.3.2 go: downloading github.com/hashicorp/go-multierror v1.1.1 go: downloading golang.org/x/net v0.0.0-20220111093109-d55c255bac03 go: downloading golang.org/x/text v0.3.7 go: downloading github.com/hashicorp/errwrap v1.0.0 go get: added github.com/hashicorp/errwrap v1.0.0 go get: added github.com/hashicorp/go-multierror v1.1.1 go get: added github.com/imroc/req/v3 v3.10.0 go get: added golang.org/x/net v0.0.0-20220111093109-d55c255bac03 go get: added golang.org/x/text v0.3.7 // debug: running "go mod tidy" ... // debug: compiling "/home/max/go/src/gomacro.imports/github.com/imroc/req/v3/v3.go" ... gomacro> client := req.C() gomacro> // send http url request gomacro> response, err := client.R().Get("https://api.github.com/users/cosmos72") gomacro> // get response data gomacro> fmt.Println(len(response.Bytes()), err) reflect: Call using *req.Response as type req.ResponseThe issue is in the call
response.Bytes()
:gomacro> response.Bytes() reflect: Call using *req.Response as type req.ResponseI will investigate the reason.
ok. Wait for your news :)
from gomacro.
strange, response.Bytes()
typed directly at REPL works for me now:
$ gomacro
// Welcome to gomacro. Type :help for help, :copy for copyright and license.
// This is free software with ABSOLUTELY NO WARRANTY.
gomacro> import "github.com/imroc/req/v3"
// debug: running "go get github.com/imroc/req/v3" ...
go: added github.com/hashicorp/errwrap v1.0.0
go: added github.com/hashicorp/go-multierror v1.1.1
go: added github.com/imroc/req/v3 v3.13.1
go: added golang.org/x/net v0.0.0-20220111093109-d55c255bac03
go: added golang.org/x/text v0.3.7
// debug: running "go mod tidy" ...
// debug: compiling plugin "/home/max/go/src/gomacro.imports/gomacro_pid_22178/import_1" ...
gomacro> client := req.C()
gomacro> response, err := client.R().Get("https://api.github.com/users/cosmos72")
gomacro> response.Bytes()
[] // []uint8
Instead, putting it inside a function does not work yet:
gomacro> import (
. . . . "fmt"
. . . . "github.com/imroc/req/v3"
. . . . )
// debug: running "go get github.com/imroc/req/v3" ...
go: added github.com/hashicorp/errwrap v1.0.0
go: added github.com/hashicorp/go-multierror v1.1.1
go: added github.com/imroc/req/v3 v3.13.1
go: added golang.org/x/net v0.0.0-20220111093109-d55c255bac03
go: added golang.org/x/text v0.3.7
// debug: running "go mod tidy" ...
// debug: compiling plugin "/home/max/go/src/gomacro.imports/gomacro_pid_27627/import_1" ...
gomacro>
gomacro> func getData() string {
. . . . client := req.C()
. . . . // send http url request
. . . . response, err := client.R().Get("https://api.github.com/users/cosmos72")
. . . . // get response data
. . . . fmt.Println(len(response.Bytes()), err)
. . . . return "finish"
. . . . }
gomacro> getData()
reflect.Set: value of type *req.Response is not assignable to type req.Response
I will continue debugging this issue
from gomacro.
Getting nearer: it's a bug related to loading from compiled plugin a type that has both pointer and value methods.
With some debug prints, I managed to get the following error:
panic: overwriting mismatched reflect.Type found in cache for type func (*github.com/imroc/req/v3.Response).() []uint8 (hash 0x1703c4a):
old reflect.Type: func(*req.Response) []uint8
new reflect.Type: func(req.Response) []*http.Cookie [recovered]
The problem is gomacro confuses for some reason (still to be investigated) these two methods:
- first method of
req.Response
i.e.func (resp req.Response) Cookies() []*net/http.Cookie
- first method of
*req.Response
i.e.func (resp *req.Response) Bytes() []byte
from gomacro.
I added another patch (commit 1dc8be1) trying to fix this bug.
Would you check if it works now or it's still broken?
from gomacro.
I added another patch (commit 1dc8be1) trying to fix this bug.
Would you check if it works now or it's still broken?
Cool, this fix (commit1dc8be1
) was partially successful, I tried to check the code:
gomacro> import (
. . . . "fmt"
. . . . "github.com/imroc/req/v3"
. . . . )
// debug: running "go get github.com/imroc/req/v3" ...
go: added github.com/hashicorp/errwrap v1.0.0
go: added github.com/hashicorp/go-multierror v1.1.1
go: added github.com/imroc/req/v3 v3.13.1
go: added golang.org/x/net v0.0.0-20220111093109-d55c255bac03
go: added golang.org/x/text v0.3.7
// debug: running "go mod tidy" ...
// debug: compiling plugin "/home/max/go/src/gomacro.imports/gomacro_pid_27627/import_1" ...
gomacro>
gomacro> func getData() string {
. . . . client := req.C()
. . . . // send http url request
. . . . res, _ := client.R().Get("https://api.github.com/users/cosmos72")
. . . . // get response data
. . . . data := res.Bytes()
. . . . fmt.Println("len->",len(data))
. . . . return "finish"
. . . . }
gomacro> getData()
len-> 1181
finish // string
But ,still exists some other problm.
First, the 'Response' structure in the third-party 'imroc/req/v3' package inherits *http Response
structure. The 'res' variable obtained after the client requests the interface, and then I call some custom functions (String
, GetHeader
, GetStatus
) under the 'Response' structure through the 'res' variable. There will still be panic. :(
from gomacro.
Third fix applied in commit c545040.
Let's see if it's enough this time :)
from gomacro.
Related Issues (20)
- I would like a full working example how to inject my application context(types and functions) in the REPL HOT 9
- Extract struct with methods from script to compiled code HOT 2
- Proxy can mix the called method of the imported structure HOT 3
- integrate with https://github.com/go-rod/rod HOT 2
- I'm unable to compile code importing gomacro on Mac OS m1 pro HOT 7
- Is there a way to Eval a folder HOT 5
- recursive type error cases: call of reflect.Value.Interface on zero Value HOT 6
- can't import fsm package HOT 4
- Different compilation behaviour from native go HOT 2
- undefined: pkgpath HOT 3
- Cannot convert struct to interface if it has an embedded struct with a method HOT 4
- Cannot import third party packages on Linux (not even the ones in the README) HOT 2
- Third-party imported type method is not callable from fast.Interp.Eval [gomacro repl works] HOT 4
- Idea for making adding third party packages to Gomacro easier when plugins aren't available HOT 3
- recursive type error cases: call of reflect.Value.Interface on zero Value
- can not import 3rd party packages HOT 13
- package <package> exports zero constants, functions, types, and variables HOT 3
- Caching of interp.Eval1 results HOT 13
- Way to disable go get import and enforce to use only defined import list HOT 3
- An error will be reported when using third-party packages on Windows HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gomacro.