1
0
mirror of https://github.com/labstack/echo.git synced 2025-01-12 01:22:21 +02:00

Merge pull request #208 from caarlos0/rice

Added go.rice recipe
This commit is contained in:
Vishal Rana 2015-10-17 20:53:49 -07:00
commit e2b394e6c9
5 changed files with 60 additions and 0 deletions

2
recipes/embed-resources/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
rice
app.rice-box.go

View File

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>go.rice Example</title>
<script src="/static/main.js" charset="utf-8"></script>
</head>
<body>
<h1>go.rice Example</h1>
</body>
</html>

View File

@ -0,0 +1 @@
alert("main.js");

View File

@ -0,0 +1,26 @@
package main
import (
"net/http"
"github.com/GeertJohan/go.rice"
"github.com/labstack/echo"
)
func main() {
e := echo.New()
// the file server for rice. "app" is the folder where the files come from.
assetHandler := http.FileServer(rice.MustFindBox("app").HTTPBox())
// serves the index.html from rice
e.Get("/", func(c *echo.Context) error {
assetHandler.ServeHTTP(c.Response().Writer(), c.Request())
return nil
})
// servers other static files
e.Get("/static/*", func(c *echo.Context) error {
http.StripPrefix("/static/", assetHandler).
ServeHTTP(c.Response().Writer(), c.Request())
return nil
})
e.Run(":3000")
}

View File

@ -0,0 +1,20 @@
---
title: Embed Resources
menu:
side:
identifier: "embed-resources"
parent: recipes
weight: 14
---
### With go.rice
`rice.go`
{{< embed "embed-resources/rice.go" >}}
### Maintainers
- [caarlos0](https://github.com/caarlos0)
### [Source Code](https://github.com/labstack/echo/blob/master/recipes/rice)