Giter VIP home page Giter VIP logo

Comments (4)

greivinlopez avatar greivinlopez commented on May 10, 2024

OK I did it in this way and seems to be working:

func serveSequence(request *restful.Request, response *restful.Response) {
id := request.PathParameter("seat-id")

rootdir, _ := os.Getwd()
filename := strings.Join([]string{id, ".zip"}, "")
http.ServeFile(response.ResponseWriter, request.Request, path.Join(rootdir, filename))

}

But I will like to serve the file as a different flavor for the same resource.. just like the library do with JSON, XML. Maybe writing a special WriteX function on the response.go code.

What are your thoughts about this?

from go-restful.

emicklei avatar emicklei commented on May 10, 2024

Your solution is exactly what I had in mind.
What do you mean with a different flavor? Can you give an example of a resource? and a corresponding WriteX

from go-restful.

greivinlopez avatar greivinlopez commented on May 10, 2024

About different flavor I was thinking on something like:

Produces(restful.MIME_JSON, restful.MIME_XML, restful.MIME_ZIP)

and then somehow create a custom WriteZip function and plugin it to the web service so I'm able to map the same route to the 3 formats... (including the zip file). In my current code I just create another restful.WebService with a completely different path.

So instead of having:

/seats/seat-id and /sequences/seat-id (for the ZIP file)

I will like to have:

/seats/seat-id and respond with JSON or the ZIP file according to the given Accept header.

I don't know if that makes sense.. maybe a feature request for the future?

Anyway thanks for your answer at least I know that my current solution is the way to go at the moment. Thanks.

from go-restful.

emicklei avatar emicklei commented on May 10, 2024

Ok, I understand your need. Adding other MIME types and associate them to their functions is something I would like to add. In particular I need support for Google Protocol Buffers.

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.