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

Added go.rice recipe

This commit is contained in:
Carlos Alexandro Becker 2015-09-16 21:49:41 -03:00
parent e2928d9155
commit 7a7ceeb9c4
5 changed files with 67 additions and 0 deletions

2
recipes/rice/.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>

1
recipes/rice/app/main.js Normal file
View File

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

26
recipes/rice/server.go Normal file
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,27 @@
---
title: go.rice integration
menu:
side:
identifier: "recipe-rice"
parent: recipes
weight: 14
---
[go.rice](https://github.com/GeertJohan/go.rice) is a library that can be used
to package the assets (js, css, etc) inside the binary file, so your app
can still be a single binary.
This folder contains a simple example serving an `index.html` file and a simple
`.js` file with go.rice.
### Server
`server.go`
{{< embed "rice/server.go" >}}
### Maintainers
- [vishr](https://github.com/caarlos0)
### [Source Code](https://github.com/labstack/echo/blob/master/recipes/rice)