Comments (4)
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.
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.
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.
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)
- [feature] add prometheus metric filter HOT 3
- Please deploy update of v2 to https://pkg.go.dev/ HOT 9
- How to reset the default container HOT 1
- Request.QueryParameter function consumes large memory for big request HOT 3
- Support for multiple return types HOT 5
- (discussion) PrettyPrintResponses default value to false HOT 2
- Tokenizer change in 3.10 breaks many URLs HOT 33
- Security - PRISMA-2022-0227 - High Sev - emicklei/go-restful/v3 module prior to v3.10.0 is vulnerable HOT 3
- using path.Join breaks the current api HOT 6
- The go-restful-swagger12 not support go-restful version 3 HOT 4
- Whether to support a unified request results interceptors HOT 1
- which PR broke the compatible against v3.10.0 HOT 1
- Flush don't work HOT 7
- Questions about WebService Path HOT 2
- Security is not exposed in RouteBuilder HOT 6
- Improper handling of empty POST requests. HOT 5
- Why were the patch versions for vulnerability (snyk id:SNYK-GOLANG-GITHUBCOMEMICKLEIGORESTFULV3-2435654) released so late? HOT 2
- default values of a slice field in a Go struct HOT 3
- Evaluation HOT 1
- List all request headers HOT 1
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 go-restful.