Helen is the static assets handler for golang based web applications. Helen simply handles serving your static files that is javascript, stylesheets and images.
- Fast
- Javascript and Stylesheets minifications
- support
- gorilla mux
- echo
- http.ServeMux
- httrouter[coming soon]
- middlewares. You can chain any alice compatible middlwares.
After using different golang frameworks and libraries for building web applications, I usually came across the need to serve my static files and heck It is a bit complicated.
So helen, is a simple aproach to handle static assets. Helen supports different golang routers, you can use this as a way to remind youself how you can handle static assets for your favorite router.
go get github.com/gernest/helen
package main
import (
"log"
"net/http"
"github.com/gernest/helen"
"github.com/gorilla/mux"
)
func main() {
// Create the instance of your router
server := mux.NewRouter()
// Create a new helen.Static instance. We are passing "static" as the directory
// we want to serve static content from.
static := helen.NewStatic("fixtures")
// We bind anything matching /static/ route to our static handler
static.Bind("/static/", server)
// You can register other handlers to your server or whatever you want to do with it.
log.Fatal(http.ListenAndServe(":8000", server))
}
In this example we will be sriving contents of the fixtures directory as static files.
This example uses gorilla mux
router. Note that you can bind the helen handler at any point of your application. This example also works for all the supported routers.
You can add any alice compatible middlewares to the *Static
instance. If you want gzip compression and you have a wonderful implementation called gzipMe
.
Then,
static:=helen.Static("static")
static.Use(gzipMe)
Will register your middleware. Not that you can pass whatever number of middlewares you want to the Static.Use
method.
- Optimize memory usage
- Write benchmarks
Start with clicking the star button to make the author and his neighbors happy. Then fork the repository and submit a pull request for whatever change you want to be added to this project.
If you have any questions, just open an issue.
Geofrey Ernest geofreyernest@live.com
Twitter : @gernesti
Facebook : Geofrey Ernest
This project is released under the MIT licence. See LICENCE for more details.