GithubHelp home page GithubHelp logo

Why is static a special case? about web HOT 4 CLOSED

phf avatar phf commented on September 25, 2024
Why is static a special case?

from web.

Comments (4)

hoisie avatar hoisie commented on September 25, 2024

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.

phf avatar phf commented on September 25, 2024

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.

hoisie avatar hoisie commented on September 25, 2024

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.

hoisie avatar hoisie commented on September 25, 2024

Static files are in a pretty good state

from web.

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.