Giter Site home page Giter Site logo

Cannot use Pointer Struct about gomacro HOT 12 CLOSED

JoiLa avatar JoiLa commented on May 27, 2024
Cannot use Pointer Struct

from gomacro.

Comments (12)

cosmos72 avatar cosmos72 commented on May 27, 2024 1

commit b54685b should fix this.

from gomacro.

JoiLa avatar JoiLa commented on May 27, 2024 1

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.

JoiLa avatar JoiLa commented on May 27, 2024 1

I tried again and found that the problem still exists

from gomacro.

JoiLa avatar JoiLa commented on May 27, 2024 1

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.

JoiLa avatar JoiLa commented on May 27, 2024

So, is it because of on in gomacro cli run the code import _b "github.com/imroc/req/v3" , cause the problem?

from gomacro.

cosmos72 avatar cosmos72 commented on May 27, 2024

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.

JoiLa avatar JoiLa commented on May 27, 2024

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.

ok. Wait for your news :)

from gomacro.

cosmos72 avatar cosmos72 commented on May 27, 2024

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.

cosmos72 avatar cosmos72 commented on May 27, 2024

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:

  1. first method of req.Response i.e. func (resp req.Response) Cookies() []*net/http.Cookie
  2. first method of *req.Response i.e. func (resp *req.Response) Bytes() []byte

from gomacro.

cosmos72 avatar cosmos72 commented on May 27, 2024

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.

JoiLa avatar JoiLa commented on May 27, 2024

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.

cosmos72 avatar cosmos72 commented on May 27, 2024

Third fix applied in commit c545040.
Let's see if it's enough this time :)

from gomacro.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.