Giter Site home page Giter Site logo

Comments (5)

WhisperingChaos avatar WhisperingChaos commented on May 2, 2024 1

Thank you for:

  • A package that simplified my code!
  • Your quick reply to this issue!
  • The link you provided to the desired feature!

I've encoded the solution proposed by the link but am unable to obtain the data for the unmarshalled object. Here's a code snippet:

type EntropyPost struct {
	Session_id string   `json:"session-id"`
	Length     uint     `json:"length"`
	Entropy    []uint32 `json:"entropy"`
}

	req := resty.R().
		SetHeader("Content-Type", "application/json").
		SetBody(body). // automatic conversion to json
		SetResult(&EntropyPost{})

	var resp *resty.Response
	if resp, err = req.Post("http://172.17.0.2:8080/v1/316395C9-7226-41B2-94D7-013B778288FB/B615E471-CC76-4772-A879-3C865A131325/entropy/"); err != nil {
		t.Fatal("Client get failed: " + err.Error())
	}
	fmt.Fprintln(os.Stderr, resp.Status())
	var reply EntropyPost
	if err := json.Unmarshal(resp.Body(), &reply); err != nil {
		t.Fatal("Client unmarshal failed: " + err.Error())
	}
	fmt.Fprintf(os.Stderr, "reply: %v\n", reply)
	fmt.Fprintf(os.Stderr, "Result(): %v\n", resp.Result().(*EntropyPost))

Here's the generated output:

200 OK
reply: {sessionId 128 [16909060 84281096 151653132 219025168]}
Result(): &{ 0 []}

The output demonstrates that a manual decoding of the json produces the expected result. However,
I must be missing something simple in the encoding of the SetResult & companion Result() that prevents the automatic unmarshalling to EntropyPost. I would appreciate your insight to identify the problem. Thanks!

from resty.

jeevatkm avatar jeevatkm commented on May 2, 2024

I believe you're referring this https://godoc.org/github.com/go-resty/resty#Request.SetResult

from resty.

jeevatkm avatar jeevatkm commented on May 2, 2024

Response automatic marshaling happens based on response Content-Type header and Status Code.

Can you please enable debug resty.SetDebug(true) in resty? and give me that details. It will help me to identify an issue.

from resty.

WhisperingChaos avatar WhisperingChaos commented on May 2, 2024

Again, thank you for you kind assistance! Using your suggestion of enabling SetDebug() method provided the information I needed to identify the problem. In this situation, the server's content type was set to plain text, not json.

Sorry to have had you remotely debug "my" problem.

from resty.

jeevatkm avatar jeevatkm commented on May 2, 2024

I'm happy for you, you're welcome.

from resty.

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.