-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathmain.go
More file actions
43 lines (33 loc) · 894 Bytes
/
main.go
File metadata and controls
43 lines (33 loc) · 894 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//go:generate fileb0x b0x.yml
package main
import (
"log"
"net/http"
"github.com/labstack/echo"
// your embedded files import here ...
"github.com/UnnoTed/fileb0x/_example/echo/myEmbeddedFiles"
"github.com/UnnoTed/open-golang/open"
)
func main() {
e := echo.New()
e.Debug = true
// enable any filename to be loaded from in-memory file system
e.GET("/*", echo.WrapHandler(myEmbeddedFiles.Handler))
// read ufo.html from in-memory file system
htmlb, err := myEmbeddedFiles.ReadFile("ufo.html")
if err != nil {
log.Fatal(err)
}
// convert to string
html := string(htmlb)
// serve ufo.html through "/"
e.GET("/", func(c echo.Context) error {
// serve it
return c.HTML(http.StatusOK, html)
})
// try it -> http://localhost:1337/
// http://localhost:1337/ufo.html
// http://localhost:1337/public/README.md
open.Run("http://localhost:1337/")
e.Start(":1337")
}