mirror of
https://github.com/labstack/echo.git
synced 2025-04-23 12:18:53 +02:00
Added go.rice recipe
This commit is contained in:
parent
e2928d9155
commit
7a7ceeb9c4
2
recipes/rice/.gitignore
vendored
Normal file
2
recipes/rice/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
rice
|
||||||
|
app.rice-box.go
|
11
recipes/rice/app/index.html
Normal file
11
recipes/rice/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/rice/app/main.js
Normal file
1
recipes/rice/app/main.js
Normal file
@ -0,0 +1 @@
|
|||||||
|
alert("main.js");
|
26
recipes/rice/server.go
Normal file
26
recipes/rice/server.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")
|
||||||
|
}
|
27
website/content/recipes/rice.md
Normal file
27
website/content/recipes/rice.md
Normal 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)
|
Loading…
x
Reference in New Issue
Block a user