Comments (4)
Yeah, I agree that static files aren't being done correctly. I do like sinatra's approch to this:
http://www.sinatrarb.com/intro.html (the static files section)
By default, they serve static files from the ./public, but you can change that by setting a variable. It would be awesome there was a web.SetStaticDirectory(path) to change the default.
I could do this later this week, unless you want to hack on it :)
from web.
I think there's nothing wrong with allowing several static locations. You may even want different handlers for those, for example you may want short files to be served using write() while longer ones use sendfile() instead. The problem right now is that handlers in web.go get a string (or optionally a request object) and return a string. If you wanted to extract the code that handles static files right now into a handler, you'd have to add another special case for Connection as a parameter. I am not sure about this just yet, especially since it could also be done with less overhead by exposing a little bit of the underlying http package. For most users this wouldn't complicate anything though, we could still have a default location for static files with a default handler that's used if the user doesn't specify their own. Something to think about I guess, I can't really make that change without know what direction you'd like to go in.
from web.
I'd rather keep the static serving as simple as possible -- one static file directory should be fine for now. If there's a good reason to support multiple static directories than I'd consider it, but right now it would make things complicated.
To serve static files in a handler, you'd need to modify the content-type (which you can't do right now), and use ioutil to return contents of the file. That's why I'd like to have sinatra-like support for static directories, it makes serving static files pretty easy.
Passing the http connection to handlers wouldn't be the best idea. Right now I'm working with scgi support, and that doesn't even use http directly. I'm thinking of changing the optional web.Request parameter to something like web.Context, and that will give you access to the Request, Response, and eventually stuff like Session (for per-session storage), and perhaps other info.
from web.
Static files are in a pretty good state
from web.
Related Issues (20)
- web.RunScgi panics if the scgi client header misses a field HOT 1
- Mercurial (hg) is a dependency for developing on Web.go HOT 1
- Direction of the project HOT 1
- Lacking documentation
- Typo on website HOT 2
- change "code.google.com/p/go.net/websocket" to "golang.org/x/net/websocket" HOT 1
- Context is importing interface as an anonymous field
- is there any better way to set favicon ico? HOT 1
- API docs HOT 1
- webgo.io link is broken HOT 6
- How to return json? HOT 1
- ttycolor.go on windows
- THX a lot
- CORS support
- go get github.com/hoisie/web: ttycolors.go error HOT 4
- Web
- Dh
- Web page
- Web
- Development
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 web.