mirror of
https://github.com/labstack/echo.git
synced 2025-01-12 01:22:21 +02:00
commit
e2b394e6c9
2
recipes/embed-resources/.gitignore
vendored
Normal file
2
recipes/embed-resources/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
rice
|
||||
app.rice-box.go
|
11
recipes/embed-resources/app/index.html
Normal file
11
recipes/embed-resources/app/index.html
Normal 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/embed-resources/app/main.js
Normal file
1
recipes/embed-resources/app/main.js
Normal file
@ -0,0 +1 @@
|
||||
alert("main.js");
|
26
recipes/embed-resources/rice.go
Normal file
26
recipes/embed-resources/rice.go
Normal 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")
|
||||
}
|
20
website/content/recipes/embed-resources.md
Normal file
20
website/content/recipes/embed-resources.md
Normal 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)
|
Loading…
Reference in New Issue
Block a user