Giter VIP home page Giter VIP logo

Comments (4)

emicklei avatar emicklei commented on May 11, 2024

The WriteEntity of restful.Response accepts interface{} which means you can
use (almost) any type for this argument.
In your case you can pass the slice of channels ; the result will be a JSON
array.

On Sat, Sep 7, 2013 at 5:41 PM, thedan [email protected] wrote:

Hi,
How can i return multiple JSON objects in one response?

type Organisation struct {
Channels []ChannelEntry bson:"channels"
}

type ChannelEntry struct {
ChannelId bson.ObjectId bson:"channel_id
}

I fetch the attributes of the channel with its ID and then put them in
another struct. However, I want to return all of the channels to the client
in one response. How do i do this?


Reply to this email directly or view it on GitHubhttps://github.com//issues/51
.

^ Ernest Micklei

from go-restful.

emicklei avatar emicklei commented on May 11, 2024

Is it ok to close this issue?

from go-restful.

hourback avatar hourback commented on May 11, 2024

I am trying to do this but am running into the error . . .

This page contains the following errors:

error on line 7 at column 1: Extra content at the end of the document
Below is a rendering of the page up to the first error.

The handler that is being called looks like this:

// GET http://localhost:8080/notifications/
//
func (u NotificationResource) findAllNotifications(request *restful.Request, response *restful.Response) {
    fmt.Println("Entering handler....")
    fmt.Println(u)
    all := []Notification{}
    for key, _ := range u.notifications {
        usr := u.notifications[key]
        //fmt.Println("Id:", Id, "Status:", Status, "DescriptionOfProblem:", DescriptionOfProblem)
        fmt.Println(usr)
        all = append(all, usr)
        //response.WriteEntity(usr)
    }
    fmt.Println(all)
    response.WriteEntity(all)
    fmt.Println("Exiting handler....")
}

What I'm trying to do is have a route that finds all of the records, populates a slice by iterating over the data, then returns all of the records as JSON objects. The full code is here:

https://gist.github.com/hourback/c2672cbc05d80c2e279a

from go-restful.

hourback avatar hourback commented on May 11, 2024

@danvonk , Did you get this working?

from go-restful.

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.